Skip to content

Speak with Language Code

This example assumes using Google.Gemini; is in scope and apiKey contains your Google.Gemini 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 GeminiClient(apiKey);

try
{
    // Gemini 3.1 Flash TTS supports 70+ languages. Pass a BCP-47
    // languageCode to bias the model toward a specific locale's
    // pronunciation and prosody.
    var result = await client.SpeakAsync(
        text: "Hola, ¿cómo estás hoy? Espero que tengas un día maravilloso.",
        voiceName: GeminiVoices.Kore,
        modelId: "gemini-3.1-flash-tts-preview",
        languageCode: "es-ES");

}
catch (ApiException ex) when (IsTransientAvailabilityIssue(ex))
{
    AssertTransientAvailability(ex);
}
catch (ApiException ex) when (ex.StatusCode is System.Net.HttpStatusCode.BadRequest &&
                              ex.Message.Contains("only be used for TTS"))
{
}