event.data in the browser’s onmessage callback, or use the equivalent message handler in your WebSocket library.
For complete examples, see Stream audio to Dictation session. To learn how to establish the WebSocket connection and stream audio, see Stream Dictation audio.
Partial and final transcripts
Useis_final to decide whether the text should be shown as draft text or committed to the transcript.
Example partial frame:
End of results
After the upstream stream ends, the server sends one terminal frame:transcript.transcript equal to EOF as the canonical end-of-results signal for that speech session. The WebSocket closes shortly after.
Handle transcript updates in your UI
The Dictation WebSocket sends transcript updates as speech is processed. Each message contains the current transcript and anis_final flag that tells you whether the text is still changing or has been finalized.
Partial and final updates
A single spoken sentence can generate multiple partial transcript frames before a single final transcript is produced. Interim frames are drafts that the recognizer can revise. The final frame is the committed text for that segment. Your application is responsible for deciding how transcript text is displayed and stored in the editor.Recommended client state
A common approach is to maintain two pieces of state:committedText: transcript that has been finalized and stored.interimText: the current in-progress transcript that is replaced by newer interim updates or cleared when a final transcript arrives.
Insert transcript text
Cursor and insertion point
The WebSocket returns only transcript text. It does not know your cursor position, selected text, or the surrounding content in your editor. Your application is responsible for inserting each transcript at the correct location.Spacing
Before inserting a transcript, determine whether a space is needed between the existing text and the incoming transcript. Insert a leading space only when the existing text does not already end with whitespace or an opening bracket or quote ((, [, {, "), the insertion point is not at the beginning of the field, and the incoming transcript does not begin with punctuation that should attach to the previous text (for example ,, ., :, ;, !, ?).
Capitalization
Your application is responsible for capitalization when starting a new sentence or paragraph. Do not recapitalize on every interim update.Examples
Understand transcript ordering
The transcript_id field
Every transcript frame includes a transcript_id, but the value identifies a single emitted message, not a spoken utterance. Multiple interim and final updates for the same spoken phrase can each have a different transcript_id.
- Do not use
transcript_idto detect duplicate transcripts. - Use transcript arrival order to display updates.
The words array
Final transcript frames include the words array, which provides word-level metadata such as the individual word and speaker information (when available). Use it when your application shows word-level detail or distinguishes speakers. Interim frames typically contain an empty words array.
End-of-stream (EOF) lifecycle
To finish a Dictation session cleanly:- Send
AUDIO_END. - Continue reading transcript frames.
- Wait for the terminal
EOFtranscript (transcript.transcript: "EOF"). - Close the WebSocket.
- Complete the Dictation session using the End Dictation session REST API.
Related topics and resources
Stream Dictation Audio
Open
/ws/transcribe, send audio, and end with AUDIO_END.Wire Format
Outbound Dictation messages and audio format and chunking.
Complete the Session
End the Dictation session with REST after you finish reading frames.
Dictation Streaming API
API reference and code samples for transcript frames.