A Python library for transliterating English text to Hindi using AI4Bharat's model. This library provides a simple interface for converting English words to their Hindi (Devanagari) equivalents.
- Returns multiple transliteration candidates, default is 3
- Interactive command-line interface
pip install hindi-xlitfrom hindi_xlit import HindiTransliterator
# Initialize the transliterator
transliterator = HindiTransliterator()
# Transliterate a single word
word = "namaste"
candidates = transliterator.transliterate(word)
print(f"Transliteration candidates for '{word}':")
for i, candidate in enumerate(candidates, 1):
print(f"{i}. {candidate}")
# Transliterate multiple words
words = ["hello", "world"]
results = transliterator.transliterate_batch(words)
for word, candidates in zip(words, results):
print(f"\nTransliteration candidates for '{word}':")
for i, candidate in enumerate(candidates, 1):
print(f"{i}. {candidate}")After installing the package (e.g., via pip from PyPI), you can use the command line interface:
hindi-xlit <word> [topk]<word>: The word in Roman script to transliterate (required)[topk]: (Optional) Number of transliteration candidates to return (default: 3)
Examples:
hindi-xlit namaste
# Output:
# Transliteration candidates for 'namaste':
# 1. नमस्ते
# 2. नमसते
# 3. नामसते
hindi-xlit hello 5
# Output:
# Transliteration candidates for 'hello':
# 1. हेलो
# 2. हैलो
# 3. हेलों
# 4. हिलो
# 5. हीलोIf you run the command without arguments, it will show usage instructions.
This project is licensed under the MIT License - see the LICENSE file for details.
This library uses the transliteration model from AI4Bharat.
See CHANGELOG.md for release notes.