Custom vocabulary
The problem. Speech models write what is most likely in general. Your product, your customers’ names and your jargon are rare words: “Gladia” comes out as “Gladya”, “Kubernetes” as “Cuban et ease”, “Dr Okafor” as “doctor oak a four”. Custom vocabulary tells the model which words to expect, so they come out right the first time.
Where it works. Every model.
At a glance
Section titled “At a glance”| Live API | realtime_processing.custom_vocabulary |
|---|---|
| Pre-recorded (batch) | custom_vocabulary (how) |
| Live models | solaria-3 (every live model) |
| Languages | Every language of the model (supported languages) |
Step by step
Section titled “Step by step”1. List your words
Section titled “1. List your words”The option goes in realtime_processing of the session’s configuration. Both fields are required:
{ "realtime_processing": { "custom_vocabulary": true, "custom_vocabulary_config": { "vocabulary": ["Gladia", "Kubernetes", "Dr Okafor"] } }}2. Start a session with it
Section titled “2. Start a session with it”Each program streams a 16-bit WAV file and prints the final transcripts. Put your API key in the GLADIA_API_KEY environment variable, then run python custom_vocabulary.py meeting.wav.
# pip install "gladiaio-sdk>=2.2"import osimport sysimport threadingimport wave
from gladiaio_sdk import GladiaClient, LiveV2InitRequest
with wave.open(sys.argv[1]) as wav: # a 16-bit PCM WAV file rate, channels = wav.getframerate(), wav.getnchannels() audio = wav.readframes(wav.getnframes())
config = { "encoding": "wav/pcm", "sample_rate": rate, "bit_depth": 16, "channels": channels, "model": "solaria-3", "language_config": {"languages": ["en"]}, "realtime_processing": { "custom_vocabulary": True, "custom_vocabulary_config": { "vocabulary": [ "Gladia", {"value": "Kubernetes", "pronunciations": ["cuban et ease", "kubernetis"]}, {"value": "Dr Okafor", "intensity": 0.8}, ], "default_intensity": 0.5, }, },}
client = GladiaClient( api_key=os.environ["GLADIA_API_KEY"], api_url=os.environ.get("GLADIA_API_URL", "https://eu1.api.gladia.io"),)session = client.live_v2().start_session(LiveV2InitRequest.from_dict(config))ended, errors = threading.Event(), []
@session.on("message")def on_message(message): if message.type == "transcript" and message.data.is_final: print(message.data.utterance.text)
session.on("error", errors.append)session.once("ended", lambda _: ended.set())
# Stream once the socket is open: a stop sent while it opens can pass the audio queued until then.connected = threading.Event()session.once("connected", lambda _: connected.set())session.once("ended", lambda _: connected.set()) # a session that never connects endssession.on("error", lambda _: connected.set())if session.status == "connected": # it opened before the listener above connected.set()if not connected.wait(timeout=30) or errors or ended.is_set(): sys.exit(1) # no open session to stream to
step = rate * channels * 2 // 10 # 100 ms of audio per chunkfor start in range(0, len(audio), step): session.send_audio(audio[start : start + step]) # live audio: send each chunk as it is capturedsession.stop_recording()
ended.wait(timeout=60)sys.exit(1 if errors or not ended.is_set() else 0)// npm install @gladiaio/sdkimport { readFileSync } from "node:fs";import { GladiaClient } from "@gladiaio/sdk";
const { sampleRate, channels, pcm } = readWav(process.argv[2]); // a 16-bit PCM WAV file
const config = { encoding: "wav/pcm", sample_rate: sampleRate, bit_depth: 16, channels, model: "solaria-3", language_config: { languages: ["en"] }, realtime_processing: { custom_vocabulary: true, custom_vocabulary_config: { vocabulary: [ "Gladia", { value: "Kubernetes", pronunciations: ["cuban et ease", "kubernetis"] }, { value: "Dr Okafor", intensity: 0.8 }, ], default_intensity: 0.5, }, },};
const client = new GladiaClient({ apiKey: process.env.GLADIA_API_KEY, apiUrl: process.env.GLADIA_API_URL ?? "https://eu1.api.gladia.io",});const session = client.liveV2().startSession(config);
session.on("message", (message) => { if (message.type === "transcript" && message.data.is_final) console.log(message.data.utterance.text);});session.on("error", (error) => { console.error(error); process.exitCode = 1;});session.once("ended", () => process.exit());
const step = (sampleRate * channels * 2) / 10; // 100 ms of audio per chunkfor (let start = 0; start < pcm.length; start += step) { session.sendAudio(pcm.subarray(start, start + step)); // live audio: send each chunk as it is captured}session.stopRecording();
function readWav(path) { const file = readFileSync(path); let fmt, pcm; for (let pos = 12; pos < file.length; ) { const id = file.toString("ascii", pos, pos + 4); const size = file.readUInt32LE(pos + 4); if (id === "fmt ") fmt = { channels: file.readUInt16LE(pos + 10), sampleRate: file.readUInt32LE(pos + 12) }; if (id === "data") pcm = file.subarray(pos + 8, pos + 8 + size); pos += 8 + size + (size % 2); } return { ...fmt, pcm };}Create the session, then stream its audio to the returned url (Live WebSocket):
curl -X POST https://eu1.api.gladia.io/v2/live \ -H "x-gladia-key: $GLADIA_API_KEY" \ -H "content-type: application/json" \ -d '{ "encoding": "wav/pcm", "sample_rate": 16000, "bit_depth": 16, "channels": 1, "model": "solaria-3", "language_config": { "languages": ["en"] }, "realtime_processing": { "custom_vocabulary": true, "custom_vocabulary_config": { "vocabulary": [ "Gladia", { "value": "Kubernetes", "pronunciations": ["cuban et ease", "kubernetis"] }, { "value": "Dr Okafor", "intensity": 0.8 } ], "default_intensity": 0.5 } } }'3. Check the result
Section titled “3. Check the result”Nothing new arrives: the words simply come out spelled as you listed them, in partial and final transcripts.
{ "type": "transcript", "data": { "is_final": true, "utterance": { "text": "Dr Okafor deployed Gladia on Kubernetes." } } }Key terms: the words still missed
Section titled “Key terms: the words still missed”Custom vocabulary corrects a word the transcript gets almost right: “Gladya” becomes “Gladia”. A name the
transcript hears as something else entirely (an Irish first name such as “Siobhan” or “Aoife”) stays missed, and
on solaria-3 a higher intensity does not change that. For these words, list them in
realtime_processing.keyterms_prompt (live sessions): the transcript then expects them and writes them as you
spelled them.
{ "realtime_processing": { "keyterms_prompt": ["Siobhan Nguyen", "Aoife Ruairc", "Tipalti"], "custom_vocabulary": true, "custom_vocabulary_config": { "vocabulary": ["Gladia", "Tipalti"] } }}- Alone or together.
keyterms_promptworks withoutcustom_vocabulary; with both, the transcript gets the most terms right. Start with the terms your transcripts miss, not your whole vocabulary. - Each term once, spelled right. A misspelt variant listed as a term of its own (“Topalty” next to “Tipalti”)
can come out in the transcript instead of the right spelling. Remove the variants: to turn a variant into the
right spelling, give it as a
pronunciationsof the vocabulary entry, or use custom spelling. - Size limit. At most 100 terms, each of at most 6 words. Beyond,
POST /v2/liveanswers400with “keyterms_prompt: at most 100 terms per streaming session” or “keyterms_prompt: at most 6 words per term”. - Changing it mid-session. As for the vocabulary: allow it at the init and send a
session_configmessage.
Options
Section titled “Options”| field | what it does |
|---|---|
vocabulary |
The words or phrases: strings, or objects with their own options. |
value |
The word or phrase, written exactly as it must appear. |
pronunciations |
How it may be heard, written as it sounds. Whatever the model writes for one of them is rewritten to value. |
intensity |
How strongly the entry is favoured, from 0 to 1. On solaria-3, only a value under 0.5 changes anything: it makes the entry stricter (see below). |
default_intensity |
The intensity of entries that set none. |
keyterms_prompt |
Live, beside custom_vocabulary: the names and terms the transcript must get right, even those the vocabulary misses (Key terms). |
language |
Deprecated. An entry’s language, from Gladia Classic (Gladia’s cloud API, api.gladia.io): accepted, not applied. Kept only for clients migrated from Gladia Classic. Do not use it in new integrations: it may be removed (decommissioned) in a future release. Remove it (Deprecated Gladia Classic compatibility). |
Limits and gotchas
Section titled “Limits and gotchas”- Fewer, precise entries work better. List what is specific to your audio. Hundreds of common words, or a whole dictionary, make the model see your words where they were not said.
- On
solaria-3,intensityonly makes the vocabulary stricter. Any value from 0.5 to 1, per entry or asdefault_intensity, gives the same transcript as leaving it out: a higher value neither finds more of your words nor corrects words that sound further from them. A value under 0.5 corrects fewer words: only those heard very close to the entry. For a word still missed, addpronunciationsor list it inkeyterms_prompt. - Common words are never rewritten on
solaria-3. An entry that is also an everyday word (“Plain”, heard as “plane”) is left as the transcript wrote it, so a vocabulary never turns ordinary speech into your product names. To always write it your way, use custom spelling. - No misspelt variants. List each word once, spelled as it must appear: a wrong spelling added as an entry of
its own can be written as is. Put the ways it is heard in
pronunciations. - Size limit. At most 1,000 entries. The whole session configuration (vocabulary, custom spelling and
custom_metadatatogether) must also fit in its WebSocket URL: a few hundred average entries. Beyond,POST /v2/liveanswers400with “the session configuration is too large for its WebSocket URL”. - Numbers stay as listed. With numbers as digits, a vocabulary phrase made of number words (“Seven Eleven”) is kept as you wrote it.
- Not a spelling rule. Vocabulary helps the model hear a word. To change how a word is written (casing, an abbreviation), use custom spelling.
- Changing it mid-session. The vocabulary is set at
POST /v2/live; to change it while the session runs, allow it at the init and send asession_configmessage. languageof an entry is not applied: it is accepted for compatibility with Gladia’s cloud API.
Troubleshooting
Section titled “Troubleshooting”| symptom | cause | fix |
|---|---|---|
400 “custom_vocabulary_config is required when custom_vocabulary is true” |
the flag without the list | send both fields |
400 “the session configuration is too large…” |
the list, the spelling and the metadata do not fit in the URL | shorten the list, keep the words that are actually missed |
| your word now appears where it was not said | the list is too long or the intensity too high | remove generic entries, lower intensity |
a word is still missed on solaria-3 |
the model hears it differently | add pronunciations as it is heard, list it in keyterms_prompt, or fix it with custom spelling |
raising intensity changes nothing on solaria-3 |
on solaria-3, a value above 0.5 does no more than 0.5 |
list the missed words in keyterms_prompt |
fewer of your words corrected on solaria-3 than without intensity |
an intensity under 0.5 makes the entry stricter |
remove intensity, or set it to 0.5 |
| a misspelling of your word appears in the transcript | a misspelt variant is listed as an entry or a key term | remove the variant; put it in pronunciations |