mistralM

Docs

sideBar

Quickstart: generate speech

Convert text into natural speech and play it back with one API call.

This tutorial will show you how to generate speech, save the bytes as a file, then play that file through your computer's speakers. To play audio continually as it's generated, see Stream speech.

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

To use Python or TypeScript, install the Mistral SDK, plus a library to play audio. The curl example uses jqarrowUpRight to decode base64-encoded bytes.

pip install mistralai sounddevice soundfile

Generate your audio

Use this code to turn text into speech. The API returns the audio in base64 encoding, so this example decodes it into bytes. The curl example saves the audio as hello.wav, the Python example plays it right away, and the TypeScript example saves it, then plays it.

curl -s https://api.mistral.ai/v1/audio/speech \
  -H "Authorization: Bearer $MISTRAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "voxtral-mini-tts-3-0",
    "input": "Hi there! You are listening to Voxtral.",
    "voice_id": "gb_jane_neutral",
    "response_format": "wav"
  }' | jq -r '.audio_data' | base64 --decode > hello.wav

You should hear

The Python and TypeScript examples play the audio through your speakers.

The curl example saves hello.wav in the current directory. Open it in any audio player, or play it from the terminal:

afplay hello.wav   # macOS
aplay hello.wav    # Linux

You'll hear the gb_jane_neutral voice say "Hello! This is Voxtral, Mistral's text-to-speech model."

Going further

Browse all voices
illustrationSpeech

Browse all voices

Browse the preset voices and manage the voices saved in your workspace through the API.

Control the delivery
illustrationSound

Control the delivery

Steer the delivery of the whole speech output with a short free-form instruction.

Stream speech
illustrationGear

Stream speech

Stream the audio of a speech request as it's generated, play it before the whole file is ready, and measure the time to first audio.