Skip to content

Text to Speech

Synthesize natural-sounding speech from text using an Inworld voice.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Create an Inworld client using your API key.
using var client = new InworldClient(apiKey);

// TTS-2 supports BCP-47 languages, natural-language direction, conversation context, and enhanced denoising.
// Use InworldTtsModels.RealtimeTts2Flash instead when minimum latency and cost matter most.
var response = await client.TextToSpeech.SynthesizeSpeechAsync(
    text: "Your booking reference is <verbatim>AHAA7771Z</verbatim>.",
    voiceId: "Dennis",
    modelId: InworldTtsModels.RealtimeTts2,
    deliveryMode: DeliveryMode.Balanced,
    language: "en-US",
    instruction: "Speak warmly and clearly, emphasizing the booking reference.",
    enhanceGeneration: true,
    synthesisContext: new SynthesisContext
    {
        PreviousRequests =
        [
            new PreviousSynthesisRequest { Text = "I found your reservation." },
        ],
    });

// The response contains Base64-encoded audio bytes ready to decode into a playable file.