Skip to navigation

Pronunciation Dictionary

View as Markdown

A pronunciation dictionary is a JSON file of "word": "how to say it" pairs. Upload it once, get a dict_id, and pass that ID in any text-to-speech request. Matching words are replaced before synthesis. There is no phoneme markup and no retraining.

It works with both bulbul:v3 and bulbul:v4-flash, on REST, HTTP streaming and WebSocket.

StepCallJump to
1. Write the fileJSON, one block per languageDictionary format
2. Upload itPOST /text-to-speech/pronunciation-dictionaryQuick start
3. Use itdict_id on any TTS requestUsing a dictionary in TTS
4. Maintain itlist, get, update, deleteManaging dictionaries

Test without a dictionary first. Add only the words that are actually misread: acronyms that should be spelled out, brand names, and terms borrowed from another language.


When to use one

Input such as NAIC policy number check karein aur B2B portal pe login karein can be misread: NAIC may be pronounced as a word and B2B read literally. A dictionary fixes exactly those tokens and leaves the rest of the sentence alone.

InputWithout dictionaryWith dictionary entry
NAICread as a word"N A I C" spells it out
B2Bread literally"B to B"

Dictionary format

The top-level key pronunciations maps language codes to word-to-replacement pairs:

{
"pronunciations": {
"hi-IN": {
"B2B": "B to B",
"NAIC": "N A I C",
"CIBIL": "सिबिल"
},
"en-IN": {
"Sarvam": "Saar-vum",
"HDFC": "H D F C"
},
"ta-IN": {
"EMI": "இ எம் ஐ"
}
}
}
RuleDetail
Language keyshi-IN, bn-IN, ta-IN, te-IN, gu-IN, kn-IN, ml-IN, mr-IN, pa-IN, od-IN, en-IN. Case-sensitive: hi-in is rejected.
Matching scopeOnly the block for the request’s language_code is applied. The same word can have different spoken forms in Hindi and English.
ValuesPlain strings. Write the replacement in the script the language uses (for example सिबिल for Hindi).
Content typeThe upload must be sent as application/json.

Matching is per language. A request with language_code="ta-IN" ignores the hi-IN and en-IN blocks of the same dictionary.


Quick start

Set your key once:

export SARVAM_API_KEY="your-key"

Save the example above (or your own) as dict.json.

1. Upload

import os
from sarvamai import SarvamAI
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
with open("dict.json", "rb") as f:
result = client.pronunciation_dictionary.create(file=f)
print(result.dictionary_id) # e.g. "p_5cb7faa6"

The returned ID always matches ^p_[0-9a-f]{8}$.

2. Use it in a TTS request

import os
from sarvamai import SarvamAI
from sarvamai.play import save
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
audio = client.text_to_speech.convert(
text="NAIC policy check karein aur B2B portal pe login karein",
language_code="hi-IN",
model="bulbul:v4-flash",
speaker="simran_en_customer",
dict_id="p_5cb7faa6",
)
save(audio, "output.wav")

For bulbul:v3, change model to bulbul:v3 and use a v3 speaker such as shubh. Speaker names from one model are rejected by the other.


Managing dictionaries

All endpoints live under https://api.sarvam.ai/text-to-speech/pronunciation-dictionary and use the api-subscription-key header.

ActionMethod and pathSuccess response
CreatePOST /pronunciation-dictionary (multipart file){"dictionary_id": "p_..."}
ListGET /pronunciation-dictionary{"dictionary_count": 1, "dictionaries": ["p_..."]}
GetGET /pronunciation-dictionary/{dict_id}{"pronunciations": {...}}
UpdatePUT /pronunciation-dictionary?dict_id=... (multipart file){"dictionary_id": "p_...", "updated_pronunciations": {...}}
DeleteDELETE /pronunciation-dictionary?dict_id=...{"success": true, "message": "Dictionary 'p_...' deleted successfully"}
import os
from sarvamai import SarvamAI
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
result = client.pronunciation_dictionary.list()
print(result.dictionary_count, result.dictionaries)

Limits and errors

LimitValue
Dictionaries per account10
Entries per language block100
File size1 MB
Dictionaries per TTS request1
Modelsbulbul:v3, bulbul:v4-flash
StatusMessageCause
400Invalid content type 'application/octet-stream'. Only application/json is accepted.File part not sent as application/json
400Invalid JSON fileEmpty or malformed JSON
400Invalid pronunciation dictionary dataMissing pronunciations, unknown or lower-case language key, non-string value, or more than 100 entries in a language
400path.dict_id: String should match pattern '^p_[0-9a-f]{8}$'Malformed dict_id in the path
400Dictionary ID (dict_id) is required / query.dict_id: Field requiredDelete or update without dict_id
400Dictionary limit exceededCreating an 11th dictionary
404Dictionary not found.Unknown dict_id on get or update
404Pronunciation dictionary 'p_...' not foundUnknown dict_id in a TTS request
400dict_id: String should match pattern '^p_[0-9a-f]{8}$'Malformed dict_id in a TTS request
413File exceeds maximum allowed size of 1 MBFile too large
429(empty body)Throttled. Retry with backoff.

Using a dictionary on every transport

dict_id is accepted on REST, HTTP streaming and WebSocket. On WebSocket, set it in the config message.

import os
from sarvamai import SarvamAI
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
with open("output.mp3", "wb") as f:
for chunk in client.text_to_speech.convert_stream(
text="NEFT transfer karein aur KYC complete karein",
language_code="hi-IN",
model="bulbul:v4-flash",
speaker="simran_en_customer",
output_audio_codec="mp3",
dict_id="p_5cb7faa6",
):
f.write(chunk)

Patterns

{
"hi-IN": {
"NEFT": "एन ई एफ टी",
"RTGS": "आर टी जी एस",
"KYC": "के वाई सी",
"EMI": "ई एम आई",
"CIBIL": "सिबिल"
}
}
{
"hi-IN": {
"OPD": "ओ पी डी",
"ICU": "आई सी यू",
"MRI": "एम आर आई",
"BP": "बी पी"
}
}
{
"hi-IN": {
"Sarvam": "सर्वम",
"PhonePe": "फ़ोन पे",
"Zerodha": "ज़ीरोधा"
},
"en-IN": {
"Sarvam": "Saar-vum"
}
}
{
"hi-IN": { "EMI": "ई एम आई" },
"en-IN": { "EMI": "E M I" },
"ta-IN": { "EMI": "இ எம் ஐ" },
"te-IN": { "EMI": "ఇ ఎం ఐ" }
}

Tips

  • Keep one dictionary per request. To combine sets, merge them into one file (up to 100 entries per language).
  • Update instead of recreating. The dict_id stays the same, so deployed code keeps working.
  • Audition with your production speaker. Different voices can read the same replacement slightly differently.

Full request and response schemas are in the API reference. Questions? Ask on Discord.