The Gemini API can transform text input into single speaker or multi-speaker audio using Gemini text-to-speech (TTS) generation capabilities. Text-to-speech (TTS) generation is controllable, meaning you can use natural language to structure interactions and guide the style, accent, pace, and tone of the audio.
The TTS capability differs from speech generation provided through the Live API, which is designed for interactive, unstructured audio, and multimodal inputs and outputs. While the Live API excels in dynamic conversational contexts, TTS through the Gemini API is tailored for scenarios that require exact text recitation with fine-grained control over style and sound, such as podcast or audiobook generation.
This guide shows you how to generate single-speaker and multi-speaker audio from text.
Before you begin
Ensure you use a Gemini 2.5 model variant with Gemini text-to-speech (TTS) capabilities, as listed in the Supported models section. For optimal results, consider which model best fits your specific use case.
You may find it useful to test the Gemini TTS models in AI Studio before you start building.
Single-speaker TTS
To convert text to single-speaker audio, set the response modality to "audio",
and pass a speech_config object with a voice name.
You'll need to choose a voice name from the prebuilt output voices.
This example saves the output audio from the model in a wave file:
Python
from google import genai
import wave
import base64
def wave_file(filename, pcm, channels=1, rate=24000, sample_width=2):
with wave.open(filename, "wb") as wf:
wf.setnchannels(channels)
wf.setsampwidth(sample_width)
wf.setframerate(rate)
wf.writeframes(pcm)
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.1-flash-tts-preview",
input="Say cheerfully: Have a wonderful day!",
response_format={"type": "audio"},
generation_config={
"speech_config": [
{"voice": "Kore"}
]
}
)
wave_file('out.wav', base64.b64decode(interaction.output_audio.data))
JavaScript
import {GoogleGenAI} from '@google/genai';
import wav from 'wav';
async function saveWaveFile(
filename,
pcmData,
channels = 1,
rate = 24000,
sampleWidth = 2,
) {
return new Promise((resolve, reject) => {
const writer = new wav.FileWriter(filename, {
channels,
sampleRate: