Skip to navigation

Audio Formats

Supported codecs, sample rates and channels, with telephony examples.

By default, the server expects 16-bit signed little-endian PCM, 16 kHz, mono. If your audio is in that format, just send it.

For any other format, send one AudioConfig message as the first text message on the connection, before any audio:

{ "type": "AudioConfig", "codec": "mulaw", "sample_rate": 8000, "channels": 1 }

Then send the audio as binary frames. The server converts every supported format before transcription, so you don’t need to convert audio yourself.

Send exactly one AudioConfig per connection, and send it before any audio. To use a different format, open a new connection.

Supported formats

codecAliasContents of each binary frame
pcm_s16le—Raw 16-bit signed little-endian PCM samples
mulawpcmuG.711 µ-law, 1 byte per sample
alawpcmaG.711 A-law, 1 byte per sample
opus—Exactly one Opus packet per frame, with no Ogg or WebM container
FieldRequiredAllowed values
codecYespcm_s16le, mulaw, pcmu, alaw, pcma, opus
sample_rateYes8000, 12000, 16000, 24000, 32000, 44100, 48000 (every codec)
channelsNo1 (default) or 2. Stereo is mixed down to mono before transcription.
typeNoAudioConfig. Can be omitted when codec and sample_rate are present.

Telephony

Most telephony platforms stream call audio as 8 kHz G.711. Declare it as-is:

Common in North America and Japan, and the default on many cloud telephony platforms.

{ "type": "AudioConfig", "codec": "mulaw", "sample_rate": 8000, "channels": 1 }

Many telephony media streams deliver audio as base64 text inside JSON events. Decode the base64 and send the raw bytes as a binary frame. Do not forward the provider’s JSON event.

import base64
# media_payload: the base64 audio string from your telephony provider's event
await ws.send(base64.b64decode(media_payload))

Full telephony session

wss://in.api.murf.ai/v1/transcription/stream-input?api_key=YOUR_API_KEY&language=hi
{ "type": "AudioConfig", "codec": "mulaw", "sample_rate": 8000, "channels": 1 }
<binary frame: 8 kHz µ-law bytes>
<binary frame: 8 kHz µ-law bytes>
...
{ "type": "Finalize" }

The server sends the turn’s final transcript. The connection stays open for the next turn.

{ "type": "CloseStream" }

Web and mobile audio

{ "type": "AudioConfig", "codec": "opus", "sample_rate": 48000, "channels": 2 }

Send each Opus packet as its own binary frame. Do not combine several packets into one frame, and do not send Ogg or WebM container data, such as the output of the browser’s MediaRecorder.

Format errors

If codec, sample_rate or channels is invalid, a binary frame cannot be decoded, or a text frame is not a JSON object, the server sends an Error message and closes the connection with code 4002.

{ "type": "Error", "message": "Invalid sample_rate 22050. Allowed: [8000, 12000, 16000, 24000, 32000, 44100, 48000]" }
{ "type": "Error", "message": "Invalid audio config: missing sample_rate" }
{ "type": "Error", "message": "Opus decode failed" }

If your source audio uses a sample rate that isn’t listed, such as 22.05 kHz, resample it to a supported rate before sending.

See Errors for every close code.