Skip to content

Text to speech

Synthesize a short WAV clip and save it to disk using one of the ready voices.

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
20
21
22
using var client = new ResembleAIClient(apiKey);
var selectedVoice = await GetReadyVoiceAsync(client);

try
{
    // Synthesize a short clip to WAV audio.
    var response = await client.SubpackageTextToSpeech.SynthesizeAsync(
        voiceUuid: selectedVoice.Uuid,
        data: "Hello from the Resemble AI SDK integration tests.",
        title: "resembleai-sync-sample",
        outputFormat: SynthesizePostRequestBodyContentApplicationJsonSchemaOutputFormat.Wav,
        sampleRate: SynthesizePostRequestBodyContentApplicationJsonSchemaSampleRate.x22050);

    // Persist the decoded audio payload to disk.
    await File.WriteAllBytesAsync("resembleai-sync.wav", response.AudioContent!);
    Console.WriteLine($"Saved {response.AudioContent?.Length ?? 0} bytes using {selectedVoice.Name}.");

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