Transliteration API

View as Markdown

Transliteration Types

Romanization

Convert Indic scripts to Roman script (English alphabet). Example: मैं ऑफिस → main office

Indic Script Conversion

Convert code-mixed, romanized, or English text to Indic scripts. Example: main office → मैं ऑफिस

Spoken Form

Convert written text to natural spoken form. Example: 9:30am → सुबह साढ़े नौ बजे

Code Examples

from sarvamai import SarvamAI
client = SarvamAI(
api_subscription_key="YOUR_SARVAM_API_KEY"
)
try:
response = client.text.transliterate(
input="मैं ऑफिस जा रहा हूँ",
source_language_code="hi-IN",
target_language_code="en-IN",
spoken_form=True
)
print(response)
except Exception as e:
print(f"Error: {e}")

API Features

Input Options
  • Multiple Indic languages
  • Code-mixed text support
  • Romanized text input
  • English text input
Output Formats
  • Roman script (English)
  • Native script conversion
  • Spoken form output
  • Natural number formats
Number Handling
  • International numerals (0-9)
  • Native numerals (१-९)
  • English number words
  • Native number words

API Response Format

FieldTypeDescription
request_idstringUnique identifier for the request
transliterated_textstringText converted to target script
source_language_codestringDetected or provided source language (BCP-47 format)

Supported languages: bn-IN, en-IN, gu-IN, hi-IN, kn-IN, ml-IN, mr-IN, od-IN, pa-IN, ta-IN, te-IN

{
"request_id": "20241115_12345678-1234-5678-1234-567812345678",
"transliterated_text": "main office ja raha hun",
"source_language_code": "hi-IN"
}

Indic Script Conversion (English to Indic):

{
"request_id": "20241115_12345678-1234-5678-1234-567812345678",
"transliterated_text": "मैं ऑफिस जा रहा हूँ",
"source_language_code": "en-IN"
}

With Spoken Form Numerals:

{
"request_id": "20241115_12345678-1234-5678-1234-567812345678",
"transliterated_text": "मुझे कल सुबह साढ़े नौ बजे को अपॉइंटमेंट है",
"source_language_code": "hi-IN"
}

With Native Numerals:

{
"request_id": "20241115_12345678-1234-5678-1234-567812345678",
"transliterated_text": "मेरा फोन नंबर है: ९८४०९५०९५०",
"source_language_code": "hi-IN"
}

Error Responses

All errors return a JSON object with an error field (message, code, request_id). The full error-code table, retry guidance, and SDK exception reference live on the central Errors & Troubleshooting page.

Errors specific to this endpoint:

HTTP StatusError CodeWhen This HappensWhat To Do
400invalid_request_errorMissing required parameters or malformed requestCheck input, source_language_code, target_language_code
422unprocessable_entity_errorText too long or unsupported languageKeep text under 1000 characters
from sarvamai import SarvamAI
from sarvamai.core.api_error import ApiError
client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
try:
response = client.text.transliterate(
input="मैं ऑफिस जा रहा हूँ",
source_language_code="hi-IN",
target_language_code="en-IN"
)
print(response.transliterated_text)
except ApiError as e:
if e.status_code == 400:
print(f"Bad request: {e.body}")
elif e.status_code == 403:
print("Invalid API key. Check your credentials.")
elif e.status_code == 422:
print(f"Invalid parameters: {e.body}")
elif e.status_code == 429:
print("Rate limit exceeded. Wait and retry.")
else:
print(f"Error {e.status_code}: {e.body}")

Check out our detailed API Reference to explore Transliteration and all available options.

Need help with transliteration? Contact us on discord for guidance.