mistralM

Docs

sideBar

Realtime transcription

Transcribe live audio over a WebSocket session: the session lifecycle, its settings, the events to read, and how to trade speed for accuracy.

Realtime transcription turns live audio into text while the person is still speaking. Use it in agentic applications: transcribe a user's microphone or phone stream, then pass the transcript to a model that generates the assistant's response.

This page explains how a session runs from start to finish, how to configure it, how to read its events, and how to trade speed for accuracy.

flag

If the audio is already recorded, use File transcription instead. To choose between the two, see Offline and realtime audio. For a first live transcript in a few minutes, follow the realtime quickstart.

Understand the lifecycle

A session is one WebSocket connection that goes through four stages, always in the same order. Your application sends the audio, and the API sends the text back while the audio still flows.

Session lifecycle

Read from top to bottom: each arrow is one message, from your application on the left or from the API on the right.

Realtime session lifecycle: connect, then session.created; session.update, then session.updated; input_audio.append and transcription.text.delta, repeated while audio flows; then input_audio.end and transcription.done with the full transcript.

At each stage, your application does the following:

Stage

You send

You receive

What your application does

OpenA connection with the model and your API keysession.created, with the default settingsWait for it before you send anything else.
Configuresession.update, with your settingssession.updated, with the settings the session appliesCheck the values. They're fixed from the first audio chunk.
Streaminput_audio.append, one chunk of audio at a timetranscription.text.delta, with each piece of new textAdd each piece of text to the end of the transcript you show.
Finishinput_audio.end, when the audio stopstranscription.done, with the full transcriptSave the full transcript, then close the connection.

If the API rejects a message, it sends an error event at that stage instead. See Common issues.

Connect to a session

A session is a WebSocket connection to the realtime endpoint, with the model in the query string:

wss://api.mistral.ai/v1/audio/transcriptions/realtime?model=voxtral-mini-transcribe-realtime-3

The connection authenticates with your Mistral API key, sent as Authorization: Bearer <your API key>. To create a key, open API keysarrowUpRight.

With the Python or TypeScript SDK, connect() opens the connection and returns once the session is created:

import asyncio
import os

from mistralai.client import Mistral

async def main():
    client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
    async with await client.audio.realtime.connect(
        model="voxtral-mini-transcribe-realtime-3",
    ) as connection:
        print(connection.session.model_dump_json(indent=2))

asyncio.run(main())

Configure the session

Send your settings in a session.update message, before the first audio chunk. The session answers with session.updated, which echoes every setting it applies:

{
  "type": "session.update",
  "session": {
    "audio_format": { "encoding": "pcm_s16le", "sample_rate": 24000 },
    "target_streaming_delay_ms": 480,
    "language": "en",
    "context_bias": ["Northwind", "Quillara", "Alder Creek Design", "Rotterdam"]
  }
}

The following script sends these settings, streams a WAV file in chunks of 100 ms, and prints the transcript as it arrives.

pen

The Voice Agents SDK sends language, context_bias, and turn_detection through the stt config. For raw WebSocket sessions without the SDK, send session.update with websockets in Python and ws in TypeScript.

import asyncio
import base64
import json
import os
import wave

import websockets

MODEL = "voxtral-mini-transcribe-realtime-3"
URL = f"wss://api.mistral.ai/v1/audio/transcriptions/realtime?model={MODEL}"
HEADERS = {"Authorization": f"Bearer {os.environ['MISTRAL_API_KEY']}"}
AUDIO_FILE = "customer_call.wav"  # 16-bit mono PCM WAV

async def send_audio(ws, path):
    with wave.open(path, "rb") as wav:
        while chunk := wav.readframes(wav.getframerate() // 10):
            await ws.send(json.dumps({"type": "input_audio.append", "audio": base64.b64encode(chunk).decode()}))
    await ws.send(json.dumps({"type": "input_audio.end"}))

async def main():
    with wave.open(AUDIO_FILE, "rb") as wav:
        sample_rate = wav.getframerate()

    async with websockets.connect(URL, additional_headers=HEADERS) as ws:
        print(json.loads(await ws.recv())["type"])  # session.created

        await ws.send(json.dumps({
            "type": "session.update",
            "session": {
                "audio_format": {"encoding": "pcm_s16le", "sample_rate": sample_rate},
                "target_streaming_delay_ms": 480,
                "language": "en",
                "context_bias": ["Northwind", "Quillara", "Alder Creek Design", "Rotterdam"],
            },
        }))
        sender = asyncio.create_task(send_audio(ws, AUDIO_FILE))

        async for message in ws:
            event = json.loads(message)
            if event["type"] == "session.updated":
                print("session.updated:", json.dumps(event["session"]))
            elif event["type"] == "transcription.text.delta":
                print(event["text"], end="", flush=True)
            elif event["type"] == "transcription.done":
                print("\ntranscription.done")
                break
            elif event["type"] == "error":
                print("error:", event["error"]["message"])
                break
        sender.cancel()

asyncio.run(main())
exclamationMark

The settings are fixed once audio has started. A session.update sent after the first input_audio.append returns the error Session fields cannot be changed after audio has started. To change a setting, open a new session.

Session fields

session.update takes the following fields. Send only the ones you want to change: the others keep the default that session.created reports.

Field

Type

Default

Use it to

audio_formatObject: encoding, sample_ratepcm_s16le at 16000 HzDescribe the audio you send: 16-bit signed little-endian PCM, mono, at the sample rate of your source. The format is inferred automatically from the PCM payload if you don't set it.
target_streaming_delay_msInteger480 ms (recommended starting point)Trade speed for accuracy: a multiple of 80 from 80 to 1200, or 2400. See Control latency.
languageString, a two-letter ISO 639-1 code such as "en"Not setPin the language of the audio. Leave it out and the model detects the language. See Languages.
context_biasArray of strings[]Help the model spell names and terms. See Context bias.
diarizeBooleanfalseLabel each piece of text with its speaker. See Diarize speakers.
speaker_referencesObject: a name for each base64 audio clipNot setName known speakers, up to 8 clips of 3 to 15 seconds. Requires diarize. See Diarize speakers.
turn_detectionObjectNot setKnow when the user starts and finishes speaking. See Turn detection.
exclamationMark

diarize and turn_detection can't be used in the same session: the session returns the error Diarization is not compatible with turn detection.

Events: receive updates and finish

Everything the API sends arrives as a JSON message with a type. Read the type first, then the fields of that event:

Event

Fields

Sent when

session.createdsessionThe connection opens, with the default settings.
session.updatedsessionAfter each session.update, with the settings the session applies.
transcription.text.deltatextNew text is ready, as the audio flows.
transcription.segmenttext, speaker_id, start, endWith diarize on, instead of transcription.text.delta. See Diarize speakers.
turn.start, turn.eager_end, turn.resume, turn.endtime_s, and end_reason on turn.endWith turn_detection on, at the moments of each turn. See Turn detection.
transcription.donetext, segments, language, model, usageAfter input_audio.end, once all the audio is transcribed.
errorerror.message, error.codeThe API rejects a message or a setting.

Show the text as it arrives

Each transcription.text.delta adds new text after the text already sent. A delta never corrects earlier text, so your application only appends: there's nothing to replace.

  • Show each delta as soon as it arrives. It's final when you receive it.
  • Append it as is. Deltas carry their own spaces and punctuation, such as " for" or ".", so don't add separators.
  • Save the text of transcription.done as the transcript of record.
lightbulb

To show fast text first and replace it with more accurate text later, you need two sessions on the same audio. See Variable transcription rate.

Finish the session

When the audio stops, send input_audio.end. The API sends the last deltas, then transcription.done with the full transcript. Close the connection once you've received it.

Control latency

The model uses a configurable delay to control how long it waits between the moment a word is spoken and the moment it's transcribed:

  • A shorter delay transcribes the speech sooner, but less accurately.
  • A longer delay gives the model more context: the text is more accurate, but arrives later.

target_streaming_delay_ms sets this delay for the session. Use a multiple of 80 from 80 to 1200 (80, 160, 240, and so on), or 2400. A value outside this range returns an error. Start with 480 ms, which balances latency and accuracy. The Python SDK can set it with update_session(), along with the audio format.

flag

For where the delay fits in the wait your users notice, see Latency. Turn events don't wait for the delay: see Turn detection.

Variable transcription rate

Readers see words at once, and the text they keep is the accurate one. Live captions and note-taking benefit most.

Common issues

Most issues come back as an error event with a message. These are the ones specific to live sessions:

Error or symptom

Cause

Fix

Session fields cannot be changed after audio has started.A session.update sent after the first audio chunkSend every setting before the first input_audio.append. To change one, open a new session.
target_streaming_delay_ms must be one of the trained valuesA delay outside 80 to 1200, other than 2400Pick a multiple of 80 from 80 to 1200, or 2400. See Control latency.
Diarization is not compatible with turn detection.diarize and turn_detection in the same sessionKeep one of them. See Turn detection.
Speaker references require diarization, set diarize=true.speaker_references without diarizeSet diarize to true.
An error that mentions Invalid language alpha2 codeA language that isn't a two-letter ISO 639-1 codeUse a code such as "en" or "fr".
Latency measured on a file doesn't match live useThe file is sent faster than real timeTo measure latency, send each chunk at the pace of the audio, for example 100 ms of audio every 100 ms.

For other errors, see Troubleshooting.

Going further

Turn detection
illustrationHeadphones

Turn detection

Enable end-of-turn detection in realtime transcription, read the turn events and their timing against the text, and tune the thresholds.

Label speakers live
illustrationSound

Label speakers live

Label who speaks in a recorded file or a live session, read the speaker labels, and name known speakers with reference clips.

Latency
illustrationTimer

Latency

What latency means in each Mistral audio mode, the delays it adds up, and how to measure it and weigh speed against quality.

Troubleshooting
illustrationWarning

Troubleshooting

The errors that transcription requests and realtime sessions return, the usual causes of a poor or missing transcript, and the setting that fixes each one.