Skip to navigation

Streaming

Stream audio over a WebSocket and receive transcripts in real time.

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.

wss://in.api.murf.ai/v1/transcription/stream-input
wss://us-east.api.murf.ai/v1/transcription/stream-input

Pass your API key as the api_key query parameter or api-key header. See Authentication.

Quickstart

1

Get an API key

Create a key in the Murf API dashboard and export it:

export MURF_API_KEY="your_api_key_here"
2

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).

pip install websockets pyaudio
3

Stream audio and print transcripts

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.

import asyncio
import json
import os
import wave
import websockets
API_KEY = os.environ["MURF_API_KEY"]
URL = f"wss://in.api.murf.ai/v1/transcription/stream-input?api_key={API_KEY}&model=finch_indic_1.0&language=hi"
CHUNK_MS = 100 # send 100 ms of audio per frame
async def send_audio(ws, path):
with wave.open(path, "rb") as wav:
# Declare the WAV's format. Sample rate must be one of:
# 8000, 12000, 16000, 24000, 32000, 44100, 48000.
await ws.send(json.dumps({
"type": "AudioConfig",
"codec": "pcm_s16le",
"sample_rate": wav.getframerate(),
"channels": wav.getnchannels(),
}))
frames_per_chunk = wav.getframerate() * CHUNK_MS // 1000
while chunk := wav.readframes(frames_per_chunk):
await ws.send(chunk)
await asyncio.sleep(CHUNK_MS / 1000) # pace the file like live audio
# Flush the remaining speech and close the connection with code 1000.
await ws.send(json.dumps({"type": "CloseStream"}))
async def receive_results(ws):
try:
async for raw in ws:
msg = json.loads(raw)
if msg["type"] in ("partial", "final"):
if msg["transcript"]:
print(f'[{msg["type"]}] {msg["transcript"]}')
if msg["type"] == "final":
print("-- end of turn --")
elif msg["type"] == "QuotaWarning":
print(f'Low balance: ${msg["remaining_funds"]}')
elif msg["type"] == "Error":
print(f'Error: {msg["message"]}')
except websockets.ConnectionClosedError:
pass # closed with an error code; printed below
print(f"Connection closed with code {ws.close_code}")
async def main(path):
async with websockets.connect(URL) as ws:
sender = asyncio.create_task(send_audio(ws, path))
await receive_results(ws)
sender.cancel()
if __name__ == "__main__":
asyncio.run(main("sample.wav"))

Session lifecycle

A connection is a session. A session can contain many turns, for example one per caller utterance in a voice agent.

StepYou sendThe server sends
ConnectWebSocket upgrade with your API keySessionStarted, the first JSON message after the socket is accepted. An invalid key closes the connection with code 4001.
Declare format (optional)One AudioConfig message, before any audioNothing. An invalid config closes with 4002.
StreamBinary audio framespartial messages as the turn grows: StartOfTurn first, then Update. A final message when the caller pauses.
End a turn (optional){"type": "Finalize"}The turn’s transcript as a final message (EndOfTurn, trigger: "manual"). Send only if you want to end before the next pause. The connection stays open.
End the session{"type": "CloseStream"}A final message if a turn is still open, then close code 1000

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. Each partial contains 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 read rawEvent.words if 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 partial messages. When the caller stops speaking, the server waits briefly and then sends final with rawEvent.trigger set to vad. If the caller resumes speaking during that wait, the turn continues and final is held until the next pause.

    Sending {"type": "Finalize"} ends the current turn immediately, with trigger set to manual.

  • manual

    Use 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 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.
  • Any other commit_mode value closes the connection with code 4002 and the message commit_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:

{ "type": "KeepAlive" }

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.

{
"type": "SessionStarted",
"session_id": "20261201T063354Z_b03747c9909645528da8f3591335ea17",
"request_id": "20261201T063354Z_b03747c9909645528da8f3591335ea17",
"language": "en_US",
"bvc": false,
"diarize": true,
"text_formatting": false,
"mode": null,
"commit_mode": "vad",
"commit_strategy": "vad",
"vad_silence_threshold_secs": 0.55,
"vad_threshold": 0.6,
"min_speech_duration_ms": 150,
"min_silence_duration_ms": 500
}
FieldDescription
session_id, request_idThe same value. Quote it when you contact support.
languageThe accepted language query, or null for auto.
bvc, text_formattingWhat you requested.
modenative, romanized, or null when omitted. See Script mode.
diarizetrue when speakers will be labelled. false if you did not request it, or if diarization is temporarily unavailable. The session still runs, without speakers.
commit_mode, commit_strategyvad or manual. The same value, under two names.
vad_silence_threshold_secs, vad_threshold, min_speech_duration_ms, min_silence_duration_msThe voice-activity settings in effect for this session.

A partial message:

{
"type": "partial",
"transcript": "मेरा नाम मर्फ़ है",
"rawEvent": {
"type": "TurnInfo",
"request_id": "a1b2c3d4-...",
"event": "Update",
"turn_index": 0,
"sequence_id": 4,
"audio_window_start": 4.20,
"audio_window_end": 5.25,
"transcript": "मेरा नाम मर्फ़ है",
"language": "hi",
"languages": ["hi"],
"language_confidence": 1.0
}
}

A final message has the same shape. rawEvent.event is EndOfTurn, and rawEvent also includes trigger and words:

{
"type": "final",
"transcript": "मेरा नाम मर्फ़ है",
"rawEvent": {
"type": "TurnInfo",
"request_id": "a1b2c3d4-...",
"event": "EndOfTurn",
"turn_index": 0,
"sequence_id": 5,
"audio_window_start": 4.20,
"audio_window_end": 5.25,
"transcript": "मेरा नाम मर्फ़ है",
"trigger": "vad",
"language": "hi",
"languages": ["hi"],
"language_confidence": 1.0,
"words": [
{ "word": "मेरा", "start": 4.30, "end": 4.52, "language": "hi", "confidence": 0.9999 },
{ "word": "नाम", "start": 4.54, "end": 4.71, "language": "hi", "confidence": 0.9998 },
{ "word": "मर्फ़", "start": 4.75, "end": 5.12, "language": "hi", "confidence": 0.9991 },
{ "word": "है", "start": 5.15, "end": 5.25, "language": "hi", "confidence": 0.9999 }
]
}
}

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.

FieldSent inDescription
typeEvery messagepartial while the turn is in progress, final when it ends.
transcriptEvery messageThe transcript of the current turn so far. Same as rawEvent.transcript.
rawEvent.eventEvery messageStartOfTurn, Update or EndOfTurn.
rawEvent.turn_indexEvery messageTurn number, starting at 0. Goes up by one after each EndOfTurn.
rawEvent.sequence_idEvery messageMessage counter that keeps increasing for the whole session.
rawEvent.audio_window_start / audio_window_endEvery messageStart and end of the turn, in seconds from the start of the session.
rawEvent.triggerfinal onlyvad when the server ended the turn after a pause. manual when the turn was ended by Finalize or CloseStream.
rawEvent.languagepartial (Update) and finalLanguage of the turn: the language with the most words so far, for example de. One code. Sent once the turn has text; absent on StartOfTurn.
rawEvent.languagespartial (Update) and finalEvery language detected in the turn, most words first. Usually one item. Can contain more than one code when the turn has speech in several languages.
rawEvent.language_confidencepartial (Update) and finalModel confidence for rawEvent.language, from 0 to 1. Only sent when the language was detected (the language parameter was omitted, auto, or a list).
rawEvent.speaker_idpartial and finalWith diarize: the turn’s speaker, speaker_0 to speaker_7, numbered in the order people first speak. The speaker with the most words in the turn. null when not known yet.
rawEvent.wordsfinal onlyStart and end of each word, in seconds from the start of the session, with the word’s language and confidence (words[].language, words[].confidence). Items use word. File transcription word items use text.
rawEvent.words[].speaker_idfinal onlyWith diarize: speaker of each word. null when not known in time.

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.

{
"type": "final",
"transcript": "I have a question about my bill",
"rawEvent": {
"type": "TurnInfo",
"event": "EndOfTurn",
"turn_index": 3,
"audio_window_start": 12.40,
"audio_window_end": 14.10,
"transcript": "I have a question about my bill",
"speaker_id": "speaker_1",
"words": [
{ "word": "I", "start": 12.40, "end": 12.52, "language": "en", "confidence": 0.98, "speaker_id": "speaker_1" }
]
}
}

Detected language

Four things carry the name “language”. Only the first is something you send.

NameWhereWhat it is
languageQuery parameter you sendWhich languages the model may choose from. Controls detection.
rawEvent.languagepartial (Update) and finalThe turn’s language: the one with the most words so far. One code.
rawEvent.languagespartial (Update) and finalEvery language heard in the turn, most words first. Usually one item.
words[].languageEach word in a final messageThe language of the stretch of speech containing that word. It can differ from rawEvent.language.

Two scores, which are not interchangeable:

  • rawEvent.language_confidence is the model’s confidence for rawEvent.language only, from 0 to 1, and usually close to 1.0. It is a confidence score. It is sent only when the language was detected.
  • words[].confidence is the recognition confidence for each word, from 0 to 1. It is not a language score.

How the fields behave:

  • The request controls detection. Omitted or auto detects among all languages of the model. A comma-separated list, such as hi,ta, detects only among the listed languages. With a single value there is no detection: rawEvent.language and rawEvent.languages report that language and rawEvent.language_confidence is left out. English is reported as en.
  • rawEvent.language and rawEvent.languages are decided per turn. They can change between turns in one session. For example, a Hindi sentence, a pause, then a Tamil sentence gives hi for turn 0 and ta for turn 1.
  • 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 hi in rawEvent.language, rawEvent.languages and words[].language, whether output is code-mixed (default), mode=native, or mode=romanized. English words in code-mixed Hindi are still labelled hi. See Script mode.

The languages that can be reported are listed in Languages.

Authentication

MethodExample
Querywss://in.api.murf.ai/v1/transcription/stream-input?api_key=YOUR_API_KEY&model=finch_indic_1.0&language=hi
Headerapi-key: YOUR_API_KEY on the WebSocket handshake

Speech to Text does not accept tokens from GET /v1/auth/token.

Query parameters

ParameterRequiredDefaultDescription
api_keyYes, unless you send the api-key header-Your Murf API key.
modelYes-finch_indic_1.0 on in.api.murf.ai, or finch_global_1.0 on us-east.api.murf.ai.
languageNoautoOne language value for the connected model, auto, or a comma-separated list of languages to detect from. See Languages. The detected language is reported in rawEvent.language.
keywordsNo-Comma-separated words or phrases to boost. See Keyword boosting.
alphaNo0.5How strongly to favour keywords, from 0.0 to 1.0.
text_formattingNofalseSet to true to format numbers and similar terms in Hindi and English (India) transcripts. See Text formatting.
modeNo-native writes Hindi entirely in Devanagari. romanized writes Indic-language words in Latin letters. Omitted, Hindi is code-mixed with English words in Latin script, and other Indic languages stay in their own script. See Script mode.
bvcNofalseSet to true to remove background voices before transcription. Included with Finch, at no extra cost. Cannot be combined with diarize (the socket closes with 4002).
diarizeNofalsetrue labels the speaker of every turn and word. Up to 8 speakers per session; labels stay the same for the whole session. Cannot be combined with bvc (the socket closes with 4002). See Speaker diarization.
commit_modeNovadLeave unset. The server ends turns on a pause. Set manual only if you decide end of turn yourself. See Ending a turn.
zero_retentionNofalseEnterprise only. Set to true so the streaming session is not stored. See Zero data retention.

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

PlanStreaming concurrency
Free tier5
Pay as you go20 by default; up to 150 on request
EnterpriseCustom (150+)

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 partial transcripts, don’t append them. Each partial contains the whole turn so far. Use the final transcript 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 mulaw at 8000 instead of converting the audio yourself. See Audio formats.
  • Wait for final after a pause. You do not need to send Finalize on 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_id when you contact support.

FAQs

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 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.

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.

Stereo input is mixed down to mono before transcription. Each channel is not transcribed separately.

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.

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.

Streaming audio and transcripts are not stored when zero_retention is true.

$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.

Next steps