Streaming
Murf Speech to Text uses a single WebSocket connection. You send audio as binary frames and control messages as JSON; the server sends back partial transcripts while the caller is speaking, and a final transcript when the turn ends. To transcribe a recorded file in one request, use File transcription.
Endpoint
model is required. Connect Finch-Indic (finch_indic_1.0) to wss://in.api.murf.ai/v1/transcription/stream-input, and Finch-Global (finch_global_1.0) to wss://us-east.api.murf.ai/v1/transcription/stream-input. The overview lists the languages each model transcribes.
Pass your API key as the api_key query parameter or api-key header. See Authentication.
Quickstart
Install the packages
The examples use the websockets package (version 14 or later). The microphone example also needs pyaudio, which depends on PortAudio (brew install portaudio on macOS, sudo apt-get install portaudio19-dev on Debian/Ubuntu).
Stream audio and print transcripts
From a WAV file
From your microphone
Streams a 16-bit PCM WAV file at real-time pace and prints each transcript. The WAV sample rate must be one of 8000, 12000, 16000, 24000, 32000, 44100 or 48000 Hz.
Captures 16 kHz mono audio from your default microphone. Because this is the default input format, no AudioConfig message is needed. Press Ctrl+C to stop.
Session lifecycle
A connection is a session. A session can contain many turns, for example one per caller utterance in a voice agent.
Partial and final transcripts
Each message carries the transcript of the current turn in transcript. The same text is also in rawEvent.transcript.
partial: the transcript of the turn so far. Eachpartialcontains the whole turn up to that point, so replace the text you are showing instead of appending to it.final: the completed transcript of the turn. Use this text as the caller’s utterance, and readrawEvent.wordsif you need word timestamps.
Ending a turn
commit_mode sets how a turn ends. It accepts vad (default) or manual. Any other value closes the connection with code 4002 and the message commit_mode must be vad or manual.
-
vad(default)The server ends each turn when the caller pauses. While the caller speaks, it sends
partialmessages. When the caller stops speaking, the server waits briefly and then sendsfinalwithrawEvent.triggerset tovad. If the caller resumes speaking during that wait, the turn continues andfinalis held until the next pause.Sending
{"type": "Finalize"}ends the current turn immediately, with trigger set to manual. -
manualUse this mode when your agent or a turn-taking model decides when the caller has finished. The server still sends partial updates, but a pause does not end the turn. Send
{"type": "Finalize"}to end it. If there was no pending speech, final is still sent with an empty transcript.
After a turn ends
Keep sending audio on the same connection. The next speech starts a new turn. rawEvent.turn_index goes up by one, rawEvent.sequence_id keeps counting, and audio_window_start / audio_window_end remain relative to the start of the session, so all turns share one timeline.
- If your agent or a turn-taking model should decide when the caller has finished, connect with
commit_mode=manual. The server still sendspartialupdates, but a pause does not end the turn. Send{"type": "Finalize"}to end it. If there was no pending speech,finalis still sent with an emptytranscript. - Any other
commit_modevalue closes the connection with code4002and the messagecommit_mode must be vad or manual.
Keeping the connection open
While you are not sending audio, for example while your agent is speaking, send a KeepAlive message so the connection is not closed for inactivity:
Prefer KeepAlive over streaming silence. Silence still counts as audio on the wire.
If the server receives no audio and no KeepAlive for too long, it sends an Error message and closes the connection with code 4008. See Errors.
Reading results
Session started
SessionStarted is the first JSON message after the socket is accepted.
A partial message:
A final message has the same shape. rawEvent.event is EndOfTurn, and rawEvent also includes trigger and words:
These examples show a session with language detection on. With a single language value, responses carry that language and no language_confidence. See Detected language.
Response fields
Fields in partial and final messages. Sent in shows which message types carry each field. You don’t send any of these; to change what the server does, use the query parameters.
Word times are already on the session timeline, so you don’t need to convert them. Quote rawEvent.request_id when you contact support.
Speaker diarization
Add diarize=true to the connect URL. Each turn and word then carries a speaker_id (speaker_0 to speaker_7), and the labels stay the same for the session. SessionStarted.diarize is true only when speakers will be labelled. If diarization is temporarily unavailable, the session still runs, without speakers, and SessionStarted.diarize is false.
rawEvent.speaker_id is the speaker with the most words in the turn. It is sent on partial and final, and is null when not known yet. rawEvent.words[].speaker_id is sent on final, and is null when not known in time. Streaming word items use word. File transcription word items use text.
A final waits at most 0.6 seconds for its speakers, then is sent without them. partial messages never wait. In Murf’s tests, diarization added about 0.1 seconds to the median time to a final.
For recorded files with more than 8 speakers, use file transcription, which labels up to 32.
Detected language
Four things carry the name “language”. Only the first is something you send.
Two scores, which are not interchangeable:
rawEvent.language_confidenceis the model’s confidence forrawEvent.languageonly, from0to1, and usually close to1.0. It is a confidence score. It is sent only when the language was detected.words[].confidenceis the recognition confidence for each word, from0to1. It is not a language score.
How the fields behave:
- The request controls detection. Omitted or
autodetects among all languages of the model. A comma-separated list, such ashi,ta, detects only among the listed languages. With a single value there is no detection:rawEvent.languageandrawEvent.languagesreport that language andrawEvent.language_confidenceis left out. English is reported asen. rawEvent.languageandrawEvent.languagesare decided per turn. They can change between turns in one session. For example, a Hindi sentence, a pause, then a Tamil sentence giveshifor turn0andtafor turn1.- Very short speech keeps the previous
rawEvent.language. Speech shorter than about one second keeps the previous language when the model still ranks it near the top, so a short “ok” does not flip the turn’s language. - Hindi is reported as
hiinrawEvent.language,rawEvent.languagesandwords[].language, whether output is code-mixed (default),mode=native, ormode=romanized. English words in code-mixed Hindi are still labelledhi. See Script mode.
The languages that can be reported are listed in Languages.
Authentication
Speech to Text does not accept tokens from GET /v1/auth/token.
Query parameters
Zero data retention
zero_retention is available on Enterprise plans. Pass zero_retention=true on the WebSocket connect URL.
Streaming audio and transcripts are not stored. On file transcription, zero_retention means the audio file is kept only while it is processed and is deleted within 24 hours; the transcript is kept for 24 hours so you can download it.
Concurrency
Each open Speech to Text connection uses one slot until it closes, whether or not you’re sending audio. Speech to Text limits are separate from Text to Speech concurrency. If you hit the limit, new connections close with code 4004. See Rate Limits & Concurrency for plan details.
Best practices
- Replace
partialtranscripts, don’t append them. Eachpartialcontains the whole turn so far. Use thefinaltranscript as the completed turn. - Send audio in small frames. Send 20 to 100 ms of audio per frame. Larger frames delay transcription.
- Stream at real-time pace when sending pre-recorded audio.
- Send your telephony codec as-is. If your provider sends 8 kHz µ-law, declare
mulawat8000instead of converting the audio yourself. See Audio formats. - Wait for
finalafter a pause. You do not need to sendFinalizeon each turn. - Keep one connection per call. Keep sending audio between turns rather than reconnecting.
- Handle errors by close code, not by message text. See Errors.
- Quote
rawEvent.request_idwhen you contact support.
FAQs
Do I get partial (interim) transcripts?
Yes. partial messages show the transcript of the current turn while the caller is speaking. Each one replaces the previous one. When the turn ends, you receive a final message.
When does a turn end?
When the caller pauses, or as soon as you send Finalize. With commit_mode=manual, only when you send Finalize or CloseStream. See Ending a turn.
Can I transcribe a recorded file?
Yes. Stream it over the WebSocket, as in the WAV example above, or upload it with File transcription. An uploaded file’s transcript is kept for 24 hours.
What happens to stereo audio?
Stereo input is mixed down to mono before transcription. Each channel is not transcribed separately.
Can it tell different speakers apart?
Yes. Add diarize=true to the connect URL. Each turn and word then carries a speaker_id (speaker_0 to speaker_7), stable for the session. For recorded files with more speakers, use file transcription, which labels up to 32.
Can I change the language mid-session?
No. Model, language, keywords and the audio format are set when you connect. Open a new connection to change them. When the language parameter lets the model detect the language, the detected language can still differ from turn to turn. See Detected language.
Is my audio stored?
Streaming audio and transcripts are not stored when zero_retention is true.
How am I billed?
$0.12 per hour of audio, billed per second. Enterprise customers can get custom pricing. When your balance runs low, the server sends one QuotaWarning message per session. If credits run out, the connection closes with code 4005.