Repository navigation
Speech Generation
Gemini's text-to-speech (TTS) models turn text into spoken audio through the normal generateContent call. You ask for audio output with ResponseModalities, choose a voice with SpeechConfig, and read the audio from the response's inline data. Both single-speaker and multi-speaker (dialogue) output are supported.
For real-time, two-way voice conversations use the Multimodal Live API instead.
NuGet package
dotnet add package Google_GenerativeAIConstant (GoogleAIModels) |
Model ID | Notes |
|---|---|---|
Gemini38FlashTts |
models/gemini-3.8-flash-tts |
GA |
Gemini38FlashLiteTts |
models/gemini-3.8-flash-lite-tts |
GA |
Gemini31FlashTtsPreview |
models/gemini-3.1-flash-tts-preview |
Scheduled for shutdown on December 18, 2026 |
Gemini25FlashPreviewTts, Gemini25ProPreviewTts
|
[Obsolete], scheduled for shutdown on December 18, 2026 |
On Vertex AI use VertexAIModels.Gemini.Gemini38FlashTts.
using GenerativeAI;
using GenerativeAI.Types;
var model = new GenerativeModel(apiKey, GoogleAIModels.Gemini38FlashTts);
var request = new GenerateContentRequest
{
GenerationConfig = new GenerationConfig
{
ResponseModalities = new List<Modality> { Modality.AUDIO },
SpeechConfig = new SpeechConfig
{
VoiceConfig = new VoiceConfig
{
PrebuiltVoiceConfig = new PrebuiltVoiceConfig { VoiceName = "Kore" }
},
LanguageCode = "en-US" // optional, BCP 47
}
}
};
request.AddText("Say cheerfully: Have a wonderful day!");
var response = await model.GenerateContentAsync(request);
var audio = response.Candidates?[0].Content?.Parts.FirstOrDefault(p => p.InlineData != null)?.InlineData;
if (audio?.Data != null)
{
byte[] pcm = Convert.FromBase64String(audio.Data);
Console.WriteLine($"Received {pcm.Length} bytes of {audio.MimeType}");
}Style instructions in the prompt ("Say cheerfully", "Whisper", "Read slowly") control tone and pace.
Use MultiSpeakerVoiceConfig instead of VoiceConfig (they are mutually exclusive). Each Speaker name must match the speaker labels in your text.
var config = new GenerationConfig
{
ResponseModalities = new List<Modality> { Modality.AUDIO },
SpeechConfig = new SpeechConfig
{
MultiSpeakerVoiceConfig = new MultiSpeakerVoiceConfig
{
SpeakerVoiceConfigs = new List<SpeakerVoiceConfig>
{
new() { Speaker = "Joe", VoiceConfig = new VoiceConfig { PrebuiltVoiceConfig = new PrebuiltVoiceConfig { VoiceName = "Kore" } } },
new() { Speaker = "Jane", VoiceConfig = new VoiceConfig { PrebuiltVoiceConfig = new PrebuiltVoiceConfig { VoiceName = "Puck" } } }
}
}
}
};
var model = new GenerativeModel(apiKey, GoogleAIModels.Gemini38FlashTts, config: config);
var response = await model.GenerateContentAsync(
"TTS the following conversation between Joe and Jane:\nJoe: How's it going today, Jane?\nJane: Not too bad, how about you?");Gemini TTS returns raw 16-bit PCM audio (mono, 24 kHz); check InlineData.MimeType for the exact format. Add a WAV header to play it in ordinary players. The Google_GenerativeAI.Live package includes a helper:
using GenerativeAI.Live.Helper; // Google_GenerativeAI.Live package
byte[] wav = AudioHelper.AddWaveHeader(pcm, numberOfChannels: 1, sampleRate: 24000, bitsPerSample2: 16);
await File.WriteAllBytesAsync("speech.wav", wav);VoiceConfig selects one voice in one of three ways:
| Property | Use |
|---|---|
PrebuiltVoiceConfig.VoiceName |
A prebuilt voice, for example "Kore" or "Puck" (see the Gemini TTS voice list) |
Voice |
The name of a custom voice resource, for example one designed or replicated with VoicesClient (see Agent APIs) |
ReplicatedVoiceConfig |
Speak with a voice replicated from an audio sample (MimeType, VoiceSampleAudio, ConsentAudio) |
SpeechConfig.LanguageCode sets the output language (BCP 47, for example "en-US").
- Multimodal Live API
- Agent APIs (custom voices)
- Generate Content
- Supported Models
Getting Started
- Initialization
- Authentication
- Configuration & Error Handling
- Supported Models
- Migration Guide (v4)
- Release Notes (v4)
Core Features
- Generate Content
- Chat Session
- Streaming
- Multimodal Features
- JSON Mode
- Function Calling
- Embeddings
- Context Caching
Gemini APIs
- Interactions API
- Multimodal Live API
- File Search
- Batch API
- Model Tuning
- Webhooks
- Agent APIs
- Image Generation
- Video Generation
- Speech Generation
- Files Client
- Model Client
Vertex AI
Integrations
Guides
Legacy