Google Text To Speech
Generate speech with a Gemini TTS model and write the audio to a WAV file.
"""
Google Text To Speech
=====================
Cookbook example for `google/gemini/text_to_speech.py`.
"""
from agno.agent import Agent
from agno.models.google import Gemini
from agno.utils.audio import write_wav_audio_to_file
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=Gemini(
id="gemini-2.5-flash-preview-tts",
response_modalities=["AUDIO"],
speech_config={
"voice_config": {"prebuilt_voice_config": {"voice_name": "Kore"}}
},
)
)
run_output = agent.run("Say cheerfully: Have a wonderful day!")
if run_output.response_audio is not None:
audio_data = run_output.response_audio.content
output_file = "tmp/cheerful_greeting.wav"
write_wav_audio_to_file(output_file, audio_data)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passRun the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno google-genaiExport your Google API key
export GOOGLE_API_KEY="your_google_api_key_here"Run the example
Save the code above as text_to_speech.py, then run:
python text_to_speech.pyFull source: cookbook/90_models/google/gemini/text_to_speech.py