AI / Google Antigravity Gemini Fundamentals Interview Questions
What is the Gemini API's text-to-speech capability and how do you use it?
The Gemini API provides text-to-speech (TTS) generation through the Speech API and the Live API. The Speech API generates audio from text using Gemini's native speech synthesis with dozens of available voices.
from google import genai from google.genai import types import wave client = genai.Client() # Single-speaker TTS: response = client.models.generate_content( model="gemini-3.1-flash-tts-preview", contents="Welcome to the Gemini API tutorial. Today we explore text-to-speech.", config=types.GenerateContentConfig( response_modalities=["AUDIO"], speech_config=types.SpeechConfig( voice_config=types.VoiceConfig( prebuilt_voice_config=types.PrebuiltVoiceConfig( voice_name="Aoede" # one of 30 available voices ) ) ) ) ) # Extract and save audio: audio_data = response.candidates[0].content.parts[0].inline_data.data with open("output.wav", "wb") as f: f.write(audio_data) # Multi-speaker TTS (new in 2026): response = client.models.generate_content( model="gemini-3.1-flash-tts-preview", contents="""TTS the following conversation: <speaker name="Narrator">The story begins on a dark night.</speaker> <speaker name="Alice">Who goes there?</speaker> <speaker name="Bob">It is I, your long-lost friend!</speaker> """, config=types.GenerateContentConfig( response_modalities=["AUDIO"], speech_config=types.SpeechConfig( multi_speaker_voice_config=types.MultiSpeakerVoiceConfig( speaker_voice_configs=[ types.SpeakerVoiceConfig(speaker="Alice", voice_config=types.VoiceConfig( prebuilt_voice_config=types.PrebuiltVoiceConfig(voice_name="Aoede") )), types.SpeakerVoiceConfig(speaker="Bob", voice_config=types.VoiceConfig( prebuilt_voice_config=types.PrebuiltVoiceConfig(voice_name="Charon") )), ] ) ) ) )
The TTS model supports 30 built-in voices with different tones and accents. Multi-speaker TTS allows different voices for different speakers within a single audio generation request, enabling podcast production, audiobook generation, and conversational AI audio without post-production mixing.
More Related questions...