Back to KB
Difficulty
Intermediate
Read Time
4 min

Voice assistant with cloned voice & Mistral AI Voxtral

By Codcompass TeamΒ·Β·4 min read

Here's what you get at the end: a browser app where you click a button, ask a question aloud, and hear the answer back in a cloned voice. Speech recognition, LLM response, and text-to-speech β€” all Mistral, all on the free plan.

This article walks through how the pipeline fits together, shows the code for the part most tutorials skip (the STT relay), and covers the cost and compliance angles that are worth knowing before you pick a stack.

How the pipeline fits together

Browser mic β†’ [WebSocket] β†’ Voxtral STT β†’ Mistral LLM β†’ Voxtral TTS β†’ Browser audio

Enter fullscreen mode Exit fullscreen mode

The browser never talks to Mistral directly. It relays audio over WebSocket to a FastAPI backend, which handles all three API calls. There are two reasons for this: you can't expose your API key in browser JavaScript, and Voxtral's realtime speech recognition requires a persistent connection that has to stay open for the full duration of the audio stream.

The relay β€” the part most tutorials skip

Setting up the WebSocket relay is the piece that trips people up. Here's the core:

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

async def do_stt(ws, client):
    connection = await client.audio.realtime.connect(
        model="voxtral-mini-transcribe-realtime-2602",
        audio_format=AudioFormat(encoding="pcm_s16le", sample_rate=16000),
        target_streaming_delay_ms=480,
    )

    async def receive_audio():
        while True:
            data = await ws.receive()
            if "bytes" in data:
                await connection.send_audio(data["bytes"])
            elif "text" in data:
                msg =

πŸŽ‰ Mid-Year Sale β€” Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register β€” Start Free Trial

7-day free trial Β· Cancel anytime Β· 30-day money-back