Skip to content

Streaming text to speech

Stream a short WAV response and save the resulting bytes to disk.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
using var client = new ResembleAIClient(apiKey);
var selectedVoice = await GetReadyVoiceAsync(client);

try
{
    // Stream synthesized audio as a WAV byte buffer.
    var audioBytes = await client.SubpackageTextToSpeech.StreamSynthesizeAsync(
        voiceUuid: selectedVoice.Uuid,
        data: "This is a streaming text to speech check for the Resemble AI SDK.",
        sampleRate: StreamPostRequestBodyContentApplicationJsonSchemaSampleRate.x22050);

    await File.WriteAllBytesAsync("resembleai-stream.wav", audioBytes);
    Console.WriteLine($"Saved {audioBytes.Length} streamed bytes using {selectedVoice.Name}.");

}
catch (ApiException ex)
{
    AssertFeatureAvailable(ex, "streaming text-to-speech");
}