mistralM

Docs

sideBar

Quickstart: transcribe speech in realtime

Stream live audio and get a transcript with low latency.

Stream live audio to the realtime transcription API and get a transcript with low latency. For offline transcription of prerecorded files, see Transcribe an audio file.

Get an API key

First, you'll need a Mistral API key. If you don't have one, then go to StudioarrowUpRight. Navigate to the API keys sectionarrowUpRight and create a new API key.

Store your API key in the MISTRAL_API_KEY environment variable:

export MISTRAL_API_KEY="your-api-key"

Install the SDK

The realtime transcription client requires the realtime extra.

pip install "mistralai[realtime]"

Connect and stream

The realtime API uses a WebSocket connection. The SDK opens the connection, streams audio chunks to the server, and yields transcription events as they arrive. The example below reads a WAV file in 100 ms chunks and streams them at real-time pace, simulating a live microphone. For a real microphone input, replace read_chunks with your audio source.

To follow along without a file of your own, download the sample recording:

curl -O https://docs.mistral.ai/audio/chat.wav
import asyncio
import os
import wave

from mistralai.client import Mistral
from mistralai.client.models import (
    AudioFormat,
    RealtimeTranscriptionError,
    TranscriptionStreamDone,
    TranscriptionStreamTextDelta,
)

AUDIO_FILE = "chat.wav"  # 16-bit mono PCM WAV

async def read_chunks(path):
    with wave.open(path, "rb") as wav:
        while chunk := wav.readframes(wav.getframerate() // 10):
            yield chunk
            await asyncio.sleep(0.1)  # send 100 ms of audio every 100 ms, like a live source

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

    client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
    async for event in client.audio.realtime.transcribe_stream(
        read_chunks(AUDIO_FILE),
        model="voxtral-mini-transcribe-realtime-3",
        audio_format=AudioFormat(encoding="pcm_s16le", sample_rate=sample_rate),
    ):
        if isinstance(event, TranscriptionStreamTextDelta):
            print(event.text, end="", flush=True)
        elif isinstance(event, TranscriptionStreamDone):
            print(f"\n\nFinal transcript: {event.text}")
        elif isinstance(event, RealtimeTranscriptionError):
            print(f"\nError: {event.error.message}")

asyncio.run(main())

You should see

The script prints the transcript as it arrives, then the final transcript:

Transcribe what I'm about to say. Today, on July 15th, 2025, Mistral AI is announcing the new Voxtral models. Okay, and the transcription there and then write code to give the first n digits of the Fibonacci sequence.

Final transcript: Transcribe what I'm about to say. Today, on July 15th, 2025, Mistral AI is announcing the new Voxtral models. Okay, and the transcription there and then write code to give the first n digits of the Fibonacci sequence.

Going further

Understand the session lifecycle
illustrationBolt

Understand the session lifecycle

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

Detect when the user finished speaking
illustrationDeskchair

Detect when the user finished speaking

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
illustrationHeadphones

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.