Dictate Live
The live socket sends partial text while the person speaks, then one finished text after each pause. Open it from your server, not from a browser: the socket needs your key in a header, and a long-lived key must not go in a browser or app.
Send audio
Base64 audio: 16 kHz (or 8 kHz), mono, 16-bit, at most 1 s per message (0.5 s with stream_type=fast), at about real-time speed.
A live session
Output
JavaScript on Node.js 22 and later: the built-in WebSocket of these versions cannot send the key header, so the
connection is refused with a 403. Run the script with node --no-experimental-websocket live.mjs. Node.js 18 and
20 work without the flag.
The messages you get
Good to know
Connect
- Key in a header. Send
api-subscription-keyas a header. A key in the URL query string is refused with403. - Match
sample_rate. Use16000or8000, the real rate of your audio. Dictate does not check it, and it measures the audio at the rate you declare: 16 kHz audio sent as8000raises no error, but the text is wrong and the billed seconds double. - Send raw samples. Leave out the WAV header. A header is not refused, but it is read as audio.
While you stream
- Push-to-talk. Connect with
endpointing="manual". Sendspeech_startwhen the button goes down andspeech_endwhen it comes up. Each press is one turn, and only the pressed audio is billed. - Add a name in the middle. Send
config.updatewithvocabulary. It applies from the next turn that ends. An update that changes nothing is refused withinvalid_config. - Keep reading. A client that stops reading also stops answering the server’s pings, and Dictate closes it with
1011(keepalive ping timeout) in under a minute. Read messages in their own task, and do not block it on slow work. - Quiet sockets. The socket closes after 60 s with no message from you. Send
pingduring long silences. - Long speech. About 18 to 20 s of speech with no pause ends a turn, even inside a word.
- A repeated key. If a JSON message repeats a key, Dictate uses the last one. A repeated form field on a clip or a job is refused with
400.
Finish
- Always send
endand read untilsession.end, or you lose the last turn and the output. Dictate then closes the socket (1000). Afterend, only read the remaining messages untilsession.end. - Every close code and message is in the WebSocket reference.