Skip to main content

Overview

You stream audio in and receive word tokens back as they are recognized. Each word arrives first as provisional, then as final. The box uses the public free trial key. Press Record and speak Hebrew or English. The browser streams your microphone to the socket and words appear while you talk. You can also choose an audio file. One WebSocket is one audio stream, one conversation. Open a new socket for each new stream.

Connection

Keys use the same dd-... format as the rest of the API. See Authentication for how to get one. The Try it box is filled with the public free trial key. Keep your own key in a secrets manager or in DEEPDUB_API_KEY.

Start message

The first frame is a text frame of JSON. Send it before any audio.
string
required
Speech-to-text model. Use stt-egf.
string
required
Raw formats pcm_s16le, pcm_f32le, pcm_mulaw, and pcm_alaw also require sample_rate and num_channels. Container formats are auto, wav, ogg, flac, mp3, webm, aac, m4a, amr, and mp4. Raw 16 kHz mono pcm_s16le is the lowest-latency choice.
integer
Sample rate in Hz for a raw format. The example uses 16000.
integer
Channel count for a raw format. Use 1 for mono.
string[]
["he"] or ["en"] locks that language. Both, or omitting the field, turns on automatic detection per utterance. Hebrew and English can switch within one session in automatic mode.
boolean
Restrict automatic detection to the languages in language_hints.
boolean
default:"false"
When true, the server sends a final <end> token when the speaker finishes a turn.
integer
How long a pause must last before a turn ends, from 500 to 3000. Used with endpoint detection.
string[]
Words to boost: names, products, rare words. Up to 200 words.
string
Earlier conversation as plain text. Used as history for recognition.
string
Earlier conversation as plain text, same role as context.text.
boolean
default:"false"
Set true when you will send what your voice agent is saying. See Agent text.
string
Your own id. It is echoed in Deepdub logs.
translation and enable_speaker_diarization are rejected.

Audio

Send audio as binary frames, at real-time pace, in chunks of about 100 ms. That is 3,200 bytes of 16 kHz pcm_s16le mono. An empty binary frame is a valid empty chunk. End the audio with an empty text frame, "". The server flushes the last words, sends a final message with "finished": true, and closes the socket with code 1000.

Control messages

After the start message, further text frames are JSON.
string
keepalive keeps the stream open while you have no audio to send. finalize finalizes everything recognized so far and leaves the stream open. agent_text sends what your agent is saying.

Agent text

Requires enable_agent_text_input: true. Send the agent’s speech in small pieces, each just before it is played to the user, and end each agent turn with end_of_segment:
Send the text exactly as spoken, spaces included. Each message can be at most 2,000 characters. The text becomes history for the user’s next reply. Vocabulary boosting stays on context.terms. Agent text is omitted from the transcript. If the user interrupts the agent, send end_of_segment: true immediately and stop sending the rest of that reply.

Tokens

Each server message is JSON:
object[]
Words or word pieces recognized so far in this message.
string
The word, with its leading space when the server sends one. Build the transcript by concatenating text exactly as sent. Do not add or remove spaces.
integer
Start time of the token in the audio, in milliseconds.
integer
End time of the token in the audio, in milliseconds.
number
Recognition confidence for this token.
boolean
false tokens are provisional and are replaced by later messages. true tokens never change. Keep the finals, and redraw the provisional tokens from the latest message.
string
Language of this token, he or en.
integer
Milliseconds of audio included in the latest final tokens.
integer
Milliseconds of audio processed so far.
boolean
true on the last message, which has an empty tokens array. The socket then closes.
<end> is sent only when endpoint detection is on. It marks the end of a speaker turn. Skip it when building text.

Errors

An error is a JSON message, and then the socket closes.

Code example

The file is 16 kHz mono 16-bit WAV. Audio is sent in 100 ms chunks at real-time pace. The returned string is the concatenation of final tokens.

Limits

Final words arrive about 0.1 s after the speaker stops (median). Provisional words stream while they talk. A session can run for up to 5 hours. Send {"type": "keepalive"} during a long silence in which you send no audio. Each message, in either direction, is limited to 1 MiB.
bearerAuth
type:http

Deepdub API key. Send it as Authorization: Bearer on the WebSocket handshake.

Word tokens
type:object
Start message
type:object