Skip to content

Voxtral round-trip (TTS → Voxtral STT)

Exercises the Voxtral batch transcription endpoint end-to-end by: 1. Using Mistral TTS (/v1/audio/speech) to synthesize a short utterance. 2. Feeding the resulting audio bytes into Meai.ISpeechToTextClient.GetTextAsync (default model: voxtral-mini-2507). 3. Asserting the returned text is non-empty.

Skips when MISTRAL_API_KEY is unset or the account has no voices available.

This example assumes using Mistral; is in scope and apiKey contains your Mistral API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using var client = new MistralClient(apiKey);

VoiceListResponse voices;
try
{
    voices = await client.AudioVoices.ListAllVoicesAsync();
}
catch (ApiException ex)
{
    throw new AssertInconclusiveException(
        $"Mistral voice listing unavailable (HTTP {(int?)ex.StatusCode}); skipping live STT round-trip.",
        ex);
}

if (voices.Items is not { Count: > 0 } items)
{
    throw new AssertInconclusiveException(
        "No voices available on this Mistral account; skipping live STT round-trip.");
}

var voice = items[0];

SpeechResponse speech;
try
{
    speech = await client.AudioSpeech.SpeechAsync(new SpeechRequest
    {
        Input = "Hello from Voxtral.",
        VoiceId = voice.Id.ToString(),
        ResponseFormat = SpeechOutputFormat.Wav,
    });
}
catch (ApiException ex)
{
    throw new AssertInconclusiveException(
        $"Mistral TTS unavailable for this account (HTTP {(int?)ex.StatusCode}); skipping live STT round-trip.",
        ex);
}

var audioBytes = Convert.FromBase64String(speech.AudioData);

Meai.ISpeechToTextClient speechClient = client;
using var audioStream = new MemoryStream(audioBytes);
var response = await speechClient.GetTextAsync(audioStream);