Get started with Gemini-TTS voices using Text-to-Speech
Source notebook
Repo path:
audio/speech/getting-started/get_started_with_gemini_tts_voices.ipynb· Open on GitHub · intro
Synthesizes Gemini-TTS speech with Cloud Text-to-Speech and Agent Platform APIs.
Summary
This notebook teaches how to use Gemini-TTS voices for single-speaker, multi-speaker, and streamed text-to-speech synthesis. It demonstrates setup, authentication, voice and locale selection, prompt-driven style control, expressive tags, dialogue synthesis, safety filter relaxation, and Agent Platform generation. The workflow compares Cloud Text-to-Speech API and Agent Platform API paths and plays or writes generated audio.
Key code patterns
Initialize Text-to-Speech client
API_ENDPOINT = "texttospeech.googleapis.com"
client = texttospeech.TextToSpeechClient(
client_options=ClientOptions(api_endpoint=API_ENDPOINT)
)Creates a Cloud Text-to-Speech client, optionally using a regional endpoint.
Prompted single-speaker synthesis
voice = texttospeech.VoiceSelectionParams(
name=VOICE, language_code=LANGUAGE_CODE, model_name=MODEL
)
response = client.synthesize_speech(
input=texttospeech.SynthesisInput(text=TEXT, prompt=PROMPT),
voice=voice,
audio_config=texttospeech.AudioConfig(audio_encoding=texttospeech.AudioEncoding.MP3),
)Shows how prompts steer emotion, tone, pace, and delivery for Gemini-TTS.
Multi-speaker dialogue
multi_speaker_voice_config = texttospeech.MultiSpeakerVoiceConfig(
speaker_voice_configs=[
texttospeech.MultispeakerPrebuiltVoice(speaker_alias="Zizu", speaker_id="Fenrir"),
texttospeech.MultispeakerPrebuiltVoice(speaker_alias="Gary", speaker_id="Orus"),
]
)Maps speaker aliases to prebuilt voices for dialogue synthesis.
Streaming synthesis
def request_generator():
yield config_request
yield texttospeech.StreamingSynthesizeRequest(
input=texttospeech.StreamingSynthesisInput(text=TEXT, prompt=PROMPT)
)
streaming_responses = client.streaming_synthesize(request_generator())Streams audio chunks back as soon as they are ready for real-time use cases.
Agent Platform TTS
client = genai.Client(enterprise=True, project=PROJECT_ID, location=LOCATION)
response = client.models.generate_content(
model="gemini-2.5-flash-tts",
contents=TEXT,
config=types.GenerateContentConfig(speech_config=types.SpeechConfig(...)),
)Uses Google GenAI SDK enterprise mode to synthesize speech through Agent Platform.
Models & APIs used
- Models: gemini-3.1-flash-tts-preview, gemini-2.5-flash-tts
- APIs / services: Cloud Text-to-Speech API, Agent Platform API
- SDKs / libraries:
google-cloud-texttospeech,google-genai
When to use this
Use this pattern when building prompt-steerable speech synthesis with Gemini-TTS voices, including dialogue or low-latency audio streaming.
Gotchas & caveats
- google-cloud-texttospeech version 2.31.0 or newer is required for Gemini-TTS fields.
- A Google Cloud project is required and the Text-to-Speech API must be enabled.
- The notebook sets ADC quota project and runs application-default login.
- Regional availability should be checked in Gemini-TTS documentation.
- Agent Platform API returns PCM 16-bit 24k audio without WAV headers, so client-side conversion may be needed.
- Cloud Text-to-Speech supports bidirectional streaming, while Agent Platform supports single request and multiple responses.
- relax_safety_filters is only enabled for accounts with monthly invoiced billing.
- ffmpeg installation is handled separately for Linux and macOS.
Best practices
- Choose Cloud Text-to-Speech API when specific output encodings or bidirectional streaming are needed.
- Choose Agent Platform API when already using Gemini-TTS from AI Studio or other Agent Platform models.
- Use natural-language prompts to steer style, accent, pace, tone, and emotional expression.
- Use multi_speaker_voice_config to assign speaker aliases to specific voices.
- Stream audio chunks immediately to the frontend in real-time applications.
- Check available voices, locales, and regional availability in the Gemini-TTS documentation.
Related
- Concepts: Getting Started · Audio & Speech · Gemini Capabilities
- Entities: Google GenAI SDK · Chirp · Gemini
- Area: Audio Notebooks
- Best practices: Getting Started - Best Practices · Audio & Speech - Best Practices · Gemini Capabilities - Best Practices