Skip to content
,

Gemini TTS API Tutorial in Python: Voices, Multi-Speaker, Streaming and Prices (2026)

14–22 minutes
Woman at a whiteboard holding a tablet with a GEMINI TTS card, hook 30 voices two-speaker TTS

Google’s Gemini API can read any text aloud in a natural voice, with one speaker or two. The current models, Gemini 3.8 Flash TTS and Gemini 3.8 Flash-Lite TTS, went GA on 22 September 2026 and use a new request format.

This guide gives you working Python code with the google-genai SDK. It covers voices, style control, streaming, saving WAV files, prices, limits, and how Gemini compares with OpenAI’s text-to-speech models, which shut down on 6 January 2027.

TLDR

  • Models: gemini-3.8-flash-tts (best quality) and gemini-3.8-flash-lite-tts (cheaper, faster). Both are GA.
  • SDK: pip install -U google-genai (I checked 3.7.0, released 2 Dec 2026). Set api_version to v1beta and call client.interactions.create().
  • Voices: 30 prebuilt voices such as Kore and Puck, plus an Extended Voice Library you can search with client.voices.list().
  • Style: put tone in speech_metadata.style and sounds like <laugh> inline in the text.
  • Output: normal requests return a ready WAV file. Streaming returns raw 24 kHz, 16-bit mono PCM.
  • Price: free on the free tier. Paid Flash TTS costs $0.50 per 1M text tokens in and $9 per 1M audio tokens out until 31 Dec 2026, then doubles.

What the Gemini TTS API Is (and When to Use It)

Gemini TTS takes text and returns spoken audio. Google built it for jobs where the model must say exactly the words you give it, with fine control over how they sound.

That makes it different from the Live API, which holds a two-way voice conversation. If your app needs to listen and reply in real time, read my Gemini Live API tutorial instead.

Good fits for Gemini TTS

  • Podcasts and dialogues: two speakers with different voices in one request.
  • Audiobooks and narration: long, stable reads of articles, lessons or chapters.
  • Read-aloud buttons: turn a blog post or help page into audio on demand.
  • Voice agent pipelines: an LLM writes the reply, then Flash-Lite TTS speaks it turn by turn.
  • Phone systems: the API can output mu-law or A-law audio at 8 kHz for telephony.

Note: TTS models accept text only and return audio only. You cannot send an image or audio clip, and the model will not answer questions. It just reads.

Current Gemini TTS Models (December 2026)

Google’s docs list four TTS models as of 4 December 2026. The two 3.8 models share the same API schema, so switching between them is a one-word change.

Model ID Status Best for Voice design / replication
gemini-3.8-flash-tts GA (22 Sep 2026) Audiobooks, studio narration, complex dialogue, regional accents. 130 languages Yes
gemini-3.8-flash-lite-tts GA (22 Sep 2026) High volume, low latency, voice agents, read-aloud. 101 languages Yes
gemini-3.1-flash-tts-preview Preview (older) Old projects. Flash-Lite TTS is its official replacement No
gemini-2.5-pro-preview-tts Preview (older) Old projects only. Not on the free tier No
Google AI Studio docs table listing gemini-3.8-flash-tts and gemini-3.8-flash-lite-tts with single speaker, multi-speaker, voice design and voice replication support
Official Gemini API text-to-speech docs, Supported models table (checked 4 Dec 2026).

The latest TTS change landed on 4 November 2026, when Google added Voice remixing to the 3.8 models. Nothing new for TTS shipped in the last two weeks. The 2 December release was for Gemini 4 Live, not TTS.

Quick answer: start with gemini-3.8-flash-lite-tts for apps and agents. Switch to gemini-3.8-flash-tts when quality matters most, such as an audiobook or a two-person podcast.

Prerequisites and Setup

You need very little to start. TTS is part of the normal Gemini Developer API, so the same API key works.

  • Python 3.11 or newer: google-genai 3.7.0 requires it. The TTS docs ask for at least version 2.25.0.
  • A Gemini API key: free from Google AI Studio. Both 3.8 TTS models work on the free tier.
  • A media player: any player that opens WAV files.
  1. Create an API key. Open Google AI Studio, click Get API key, and create a key in a new or existing project.
  2. Store the key in an environment variable. On macOS or Linux run export GEMINI_API_KEY="your-key". On Windows PowerShell run $env:GEMINI_API_KEY="your-key".
  3. Create a virtual environment. Run python -m venv .venv, then activate it.
  4. Install the SDK. Run pip install -U google-genai. This guide was checked against version 3.7.0.
  5. Test a voice in the browser. Try the TTS models in Google AI Studio first. This confirms your account works before you write code.
  6. Run Example 1 below. If out.wav plays a cheerful “Have a wonderful day!”, your setup is done.

Warning: the TTS features only exist in the v1beta API. New SDKs default to v1, so always create the client with http_options={"api_version": "v1beta"}. Forgetting this is the most common setup mistake.

Example 1: Single-Speaker Speech to a WAV File

This is Google’s own basic example. You pass the exact words in text, describe the delivery in a speech_metadata annotation, and pick a voice in speech_config.

import base64
from google import genai

# Reads GEMINI_API_KEY from your environment
client = genai.Client(http_options={"api_version": "v1beta"})

interaction = client.interactions.create(
    model="gemini-3.8-flash-tts",
    input=[{
        "type": "user_input",
        "content": [{
            "type": "text",
            "text": "Have a wonderful day!",
            "annotations": [{
                "type": "speech_metadata",
                "style": "cheerful and friendly",
            }],
        }],
    }],
    response_format={"type": "audio"},
    generation_config={
        "speech_config": [
            {"voice": "Kore"},
        ]
    },
)

with open("out.wav", "wb") as f:
    f.write(base64.b64decode(interaction.output_audio.data))

The output_audio property returns the last audio block as base64. On the 3.8 models a normal request returns a complete WAV file (24 kHz, mono, 16-bit), so you can write the bytes straight to disk.

Already have older code that uses client.models.generate_content()? It still works with the 3.8 models. Put "speech_metadata" on each part, set "response_modalities": ["AUDIO"], and pass the voice as "speech_config": {"voice_config": {"voice": "Kore"}}.

Google now calls generateContent the legacy path, so new code should use Interactions. My Gemini Interactions API tutorial explains the new format.

Example 2: Two-Speaker Dialogue With Vocal Tags

For a dialogue, send each turn as its own text item. Each turn names its speaker, and speech_config becomes an object with a speakers list that maps names to voices.

import base64
from google import genai

client = genai.Client(http_options={"api_version": "v1beta"})

def turn(speaker, text, style=""):
    meta = {"type": "speech_metadata", "speaker": speaker}
    if style:
        meta["style"] = style
    return {"type": "text", "text": text, "annotations": [meta]}

interaction = client.interactions.create(
    model="gemini-3.8-flash-tts",
    input=[{
        "type": "user_input",
        "content": [
            turn("Dr. Anya",
                 "Wait... <short pause> look under that fallen log! Is that a blue-spotted salamander?",
                 "whispered urgently"),
            turn("Liam",
                 "<gasp> No way! <laugh> We've been searching for this species all season!",
                 "warm and enthusiastic"),
        ],
    }],
    response_format={"type": "audio"},
    generation_config={
        "speech_config": {
            "speakers": [
                {"speaker": "Dr. Anya", "voice": "Kore"},
                {"speaker": "Liam", "voice": "Puck"},
            ],
        }
    },
)

with open("dialogue.wav", "wb") as f:
    f.write(base64.b64decode(interaction.output_audio.data))
print("Saved dialogue.wav")

Notice the shape change. For one speaker, speech_config is a list ([{"voice": "Kore"}]). For two speakers it is an object ({"speakers": [...]}). Mixing these up makes the request fail.

Tip: one request supports up to 2 speakers, and only with prebuilt voices. For three or more characters, or for custom voices, make one request per turn and join the audio afterwards (Example 4 shows how).

Controlling Style, Pace and Emotion

The 3.8 models treat text as a word-for-word transcript. If you write “Say cheerfully: Hello!”, the model may read “Say cheerfully” out loud. So Google splits directions into two places.

What you want Where it goes Examples
Tone for a whole turn speech_metadata.style “whispered urgently”, “sarcastic”, “out of breath”
Speed for a whole turn speech_metadata.style “speaking rapidly”, “speaking slowly”
Pitch and prosody speech_metadata.style “high pitch, cheerful and excited inflection”, “monotone and flat”
A sound at one exact moment Inline tag in text <laugh>, <sigh>, <cough>, <gasp>
A pause at one exact moment Inline tag in text <short pause>, <long pause>
Stress on a word Capital letters in text “This is a VERY important point!”

Rules from Google’s prompting guide

  • Start with no style: most requests sound good with an empty style field. Add a short style only for turns that need it.
  • Keep style short: long “director’s notes” paragraphs cause voice drift. Reuse one short string, such as “casual, friendly”, across turns.
  • Use human sounds only: tags like <breath> or <chuckle> work well. Sound effects like applause do not.
  • Keep tags in English: even when your transcript is in another language.
  • Don’t change who the speaker is: age, gender or a permanent accent belong in the voice choice, not in style.
  • Backchannels: in a dialogue, wrap a listener’s short reaction in pipes, like |oh really?|, inside the other speaker’s turn.

Voices and the Voice Library

You can pick a voice in five ways. Most people start with the 30 prebuilt voices, then move to the library or a custom voice later.

  • Prebuilt voices: 30 curated voices (listed below).
  • Extended Voice Library: hundreds of extra voices across languages, accents and personas, searchable by API.
  • Voice design: describe a voice in words and get a reusable voice_... ID.
  • Voice replication: copy a real speaker’s voice from reference audio plus a consent recording.
  • Voice remixing: adjust an existing voice with plain-language instructions (added 4 Nov 2026).

The 30 prebuilt voices

Voice Character Voice Character Voice Character
Zephyr Bright Puck Upbeat Charon Informative
Kore Firm Fenrir Excitable Leda Youthful
Orus Firm Aoede Breezy Callirrhoe Easy-going
Autonoe Bright Enceladus Breathy Iapetus Clear
Umbriel Easy-going Algieba Smooth Despina Smooth
Erinome Clear Algenib Gravelly Rasalgethi Informative
Laomedeia Upbeat Achernar Soft Alnilam Firm
Schedar Even Gacrux Mature Pulcherrima Forward
Achird Friendly Zubenelgenubi Casual Vindemiatrix Gentle
Sadachbia Lively Sadaltager Knowledgeable Sulafat Warm

Search the voice library from Python

This snippet lists warm, female, English voices that suit audiobooks. Filters of the same kind are joined with OR, and different filters are joined with AND.

from google import genai

client = genai.Client(http_options={"api_version": "v1beta"})

response = client.voices.list(
    language_code=["en-US", "en-GB"],
    gender=["female"],
    pitch=["medium", "low"],
    contexts=["Audiobook", "Conversational"],
    type_=["prebuilt"],
    search="warm",
    page_size=50,
)

for voice in response.voices or []:
    print(f"{voice.id} | {voice.display_name} ({voice.language_code}, "
          f"{voice.accent}, {voice.gender}, pitch={voice.pitch}): {voice.description}")

Note the trailing underscore in type_, because type is a Python built-in. Page size defaults to 50 and goes up to 1,000.

Supported Languages

You do not set a language code. The model detects the language from your text, so just write the transcript in the language you want to hear.

  • gemini-3.8-flash-tts: about 130 languages, including Hindi, Bangla, Tamil, Japanese, Arabic, Spanish and many regional languages.
  • gemini-3.8-flash-lite-tts: 101 languages.
  • Flash only (not Lite): Finnish, Swedish, Thai, Swahili, Lithuanian, Slovenian, Burmese, Somali and about 20 more.

If you need Swedish or Thai, pick Flash TTS, not Flash-Lite. The full table is on Google’s speech generation page.

Example 3: Streaming and Saving PCM as WAV

Streaming lets playback start before the whole clip is ready. Set stream=True and read the step.delta events that carry audio.

Streamed chunks are raw PCM with no WAV header (24 kHz, mono, 16-bit little-endian). If you save them straight to a .wav file, most players will refuse it or play noise. Python’s built-in wave module adds the header for you.

import base64
import wave
from google import genai

client = genai.Client(http_options={"api_version": "v1beta"})

def save_wav(path, pcm_bytes, rate=24000, channels=1, sample_width=2):
    """Wrap raw 16-bit PCM in a WAV header."""
    with wave.open(path, "wb") as wf:
        wf.setnchannels(channels)
        wf.setsampwidth(sample_width)
        wf.setframerate(rate)
        wf.writeframes(pcm_bytes)

stream = client.interactions.create(
    model="gemini-3.8-flash-lite-tts",
    input=[{
        "type": "user_input",
        "content": [{
            "type": "text",
            "text": "Welcome back! Today we will learn how streaming speech works.",
            "annotations": [{"type": "speech_metadata", "style": "warm and clear"}],
        }],
    }],
    response_format={"type": "audio"},
    generation_config={"speech_config": [{"voice": "Sulafat"}]},
    stream=True,
)

pcm = bytearray()
for event in stream:
    if event.event_type == "step.delta" and event.delta.type == "audio":
        chunk = base64.b64decode(event.delta.data)
        pcm.extend(chunk)          # or send chunk to a player here
        print(f"got {len(chunk)} bytes")

save_wav("streamed.wav", bytes(pcm))
print("Saved streamed.wav")

Google added streaming for TTS in June 2026, and it works on both 3.8 models. Each second of audio is 48,000 bytes of PCM (24,000 samples times 2 bytes), which helps if you want to show progress.

Example 4: Long Text in Chunks

One request accepts at most 8,192 input tokens and returns at most 16,384 output tokens. At 25 audio tokens per second, that caps one reply at about 655 seconds, or roughly 10.9 minutes.

For a long article, split the text, request headerless PCM with "mime_type": "audio/l16", and join everything into one WAV file. Joining normal WAV replies would leave a 44-byte header inside the audio, which causes clicks.

import base64
import wave
from google import genai

client = genai.Client(http_options={"api_version": "v1beta"})
MODEL = "gemini-3.8-flash-tts"
VOICE = "Charon"
MAX_WORDS = 1000   # about 6-7 minutes of speech, well under the output cap

def split_text(text, max_words=MAX_WORDS):
    chunks, current = [], []
    for para in text.split("\n\n"):
        words = para.split()
        if current and len(current) + len(words) > max_words:
            chunks.append(" ".join(current))
            current = []
        current.extend(words)
    if current:
        chunks.append(" ".join(current))
    return chunks

def speak_pcm(text):
    interaction = client.interactions.create(
        model=MODEL,
        input=[{"type": "user_input",
                "content": [{"type": "text", "text": text}]}],
        response_format={"type": "audio", "mime_type": "audio/l16", "sample_rate": 24000},
        generation_config={"speech_config": [{"voice": VOICE}]},
    )
    return base64.b64decode(interaction.output_audio.data)

with open("article.txt", encoding="utf-8") as f:
    article = f.read()

with wave.open("article.wav", "wb") as wf:
    wf.setnchannels(1)
    wf.setsampwidth(2)
    wf.setframerate(24000)
    for i, chunk in enumerate(split_text(article), start=1):
        print(f"Chunk {i}: {len(chunk.split())} words")
        wf.writeframes(speak_pcm(chunk))

print("Saved article.wav")

This script sends no style string at all, as Google suggests for long narration. The voice reference keeps the tone steady across chunks.

The Same Request With curl

The REST endpoint is POST /v1beta/interactions. This copy of Google’s sample needs jq and base64 installed.

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.8-flash-tts",
    "input": [{
      "type": "user_input",
      "content": [{
        "type": "text",
        "text": "Have a wonderful day!",
        "annotations": [{"type": "speech_metadata", "style": "cheerful and friendly"}]
      }]
    }],
    "response_format": {"type": "audio"},
    "generation_config": {"speech_config": [{"voice": "Kore"}]}
  }' | jq -r '[.steps[] | select(.type=="model_output") | .content[] | select(.type=="audio")] | last | .data' | base64 --decode > out.wav

In raw JSON the audio sits in steps[].content[].data. The SDK’s output_audio property is just a shortcut to it.

Pricing With a Worked Example

Gemini TTS bills text input and audio output per million tokens. Audio is counted at 25 tokens per second, so one minute of speech is 1,500 output tokens. Both 3.8 models are free on the free tier.

Model Text input (per 1M) Audio output (per 1M) About per minute of audio Free tier
gemini-3.8-flash-tts until 31 Dec 2026 $0.50 $9.00 $0.0135 Free
gemini-3.8-flash-tts from 1 Jan 2027 $1.00 $18.00 $0.027 Free
gemini-3.8-flash-lite-tts until 31 Dec 2026 $0.50 $6.00 $0.009 Free
gemini-3.8-flash-lite-tts from 1 Jan 2027 $1.00 $12.00 $0.018 Free
gemini-3.1-flash-tts-preview $1.00 $20.00 $0.03 Free
gemini-2.5-pro-preview-tts $1.00 $20.00 $0.03 Not available
Gemini API pricing table for gemini-3.8-flash-tts: free tier free of charge, paid tier $0.50 per 1M text input tokens and $9.00 per 1M audio output tokens through December 31, 2026, doubling on January 1, 2027
Official Gemini Developer API pricing page, Gemini 3.8 Flash TTS standard prices (checked 4 Dec 2026).

The Batch API halves the price. Batch Flash TTS costs $0.25 per 1M text tokens and $4.50 per 1M audio tokens until the end of 2026. Flex and Priority options also exist on both 3.8 models.

Worked example: narrating a 5,000-word article

  1. Audio length: at a typical pace of about 150 words per minute, 5,000 words is about 33 minutes, or 2,000 seconds.
  2. Output tokens: 2,000 seconds times 25 = 50,000 audio tokens.
  3. Input tokens: roughly 6,500 text tokens (an estimate; check the usage data in the response for real counts).
  4. Flash TTS today: 50,000 x $9 / 1M = $0.45, plus about $0.003 for input. Total: about $0.45.
  5. Flash-Lite TTS today: 50,000 x $6 / 1M = about $0.30.
  6. From 1 January 2027: about $0.91 on Flash and $0.61 on Flash-Lite. With Batch, Flash drops back to about $0.45.

Tip: prices double on 1 January 2027. If you plan a big one-off job, such as a full audiobook back catalogue, running it in December saves half. For general Gemini costs, see my Gemini API pricing and free tier guide.

Limits and Rate Limits

Limit Value
Input token limit 8,192 tokens per request
Output token limit 16,384 tokens (about 10.9 minutes of audio)
Speakers per request Up to 2, prebuilt voices only
Input and output types Text in, audio out. No tools, thinking, caching or structured output
Default audio WAV (normal) or raw L16 PCM (streaming), 24 kHz, mono, 16-bit
Other formats audio/mulaw, audio/alaw, sample rates such as 24,000, 16,000 or 8,000 Hz
Stored custom voices 200 per project, deleted after 1 year with no use
Stateless voice keys Expire after 7 days
Rate limits Per project (not per key), set by your usage tier. See them in AI Studio
Daily quota reset Midnight Pacific time
Spend limit per 10 minutes Tier 1: $10. Tiers 2 and 3: $200

Google does not publish fixed RPM numbers for each TTS model on its docs page. Your live limits show in Google AI Studio, and they rise automatically as your tier goes up.

Gemini TTS vs OpenAI TTS

OpenAI’s deprecations page shows that tts-1, tts-1-hd and gpt-4o-mini-tts all shut down on 6 January 2027. OpenAI’s suggested replacement is gpt-realtime-2.1-mini, which runs on the Realtime API instead of the simple speech endpoint.

Feature Gemini 3.8 Flash / Flash-Lite TTS OpenAI Speech API (tts-1, gpt-4o-mini-tts) OpenAI gpt-realtime-2.1-mini
Status GA, current Shuts down 6 Jan 2027 Current
Call style One HTTP request (or stream) One HTTP request WebSocket session
Voices 30 prebuilt plus a large library and custom voices 13 built-in Realtime voices
Two speakers in one request Yes No No
Style control speech_metadata.style plus inline tags instructions (gpt-4o-mini-tts only) Session instructions
Free tier Yes No No
Audio output price $9 (Flash) or $6 (Lite) per 1M tokens until 31 Dec 2026 Being retired $20 per 1M audio tokens

Token counts differ between vendors, so compare cost on a real sample of your own text. Still, if you want a simple “send text, get a file” API after January, Gemini TTS is the closest swap. My OpenAI text-to-speech API guide covers the OpenAI side and its migration path.

Moving an OpenAI TTS script to Gemini

  1. Swap the client. Replace the OpenAI client with genai.Client(http_options={"api_version": "v1beta"}).
  2. Map the call. input text becomes a text item, and voice="alloy" becomes speech_config=[{"voice": "Kore"}] or another prebuilt voice.
  3. Move instructions. Text you passed in instructions goes into speech_metadata.style, kept short.
  4. Change the output handling. Decode output_audio.data from base64 and save it as WAV. Convert to MP3 with a tool like ffmpeg if you need it.
  5. Re-split long text. OpenAI capped input at 4,096 characters. Gemini’s cap is token-based (8,192 in, about 10.9 minutes out), so you can use bigger chunks.

Troubleshooting: Common Errors and Fixes

Problem or error Likely cause Fix
404 NOT_FOUND for the model Client is on v1, or the model ID has a typo Create the client with api_version v1beta and copy the ID exactly
AttributeError for interactions or voices Old google-genai version Run pip install -U google-genai (2.25.0 or newer)
pip says no matching version Python 3.10 or older Use Python 3.11+ for google-genai 3.7.0
400 INVALID_ARGUMENT More than 2 speakers, a turn with no speaker, custom voices in a multi-speaker call, or a list vs object mix-up in speech_config Check the request shape against Examples 1 and 2
The model reads your directions aloud Style text is inside text Move it to speech_metadata.style
WAV file plays noise or will not open Raw PCM saved without a header Wrap streamed PCM with the wave module (Example 3)
Clicks between joined clips 44-byte WAV headers inside the audio Request audio/l16 and join raw PCM (Example 4)
Audio stops early Hit the 16,384-token output cap Split text into chunks of about 1,000 words
Voice drifts across turns Long or changing style prompts Use a short, fixed style or none, and pick a voice that fits
429 RESOURCE_EXHAUSTED Rate limit or spend limit reached Retry with backoff, check limits in AI Studio, or use Batch
403 PERMISSION_DENIED Bad key or a project without access Create a new key and check the project
500, 503 or 504 Temporary server issue Retry with exponential backoff. The SDK already retries some errors

For a longer list of Gemini error codes and what they mean, see my Gemini API errors fix guide.

Frequently Asked Questions

What is the best Gemini TTS model right now?

For quality, gemini-3.8-flash-tts is Google’s flagship TTS model. For speed and lower cost, gemini-3.8-flash-lite-tts is the official replacement for the older 3.1 Flash TTS preview.

Is the Gemini TTS API free?

Yes, both 3.8 TTS models are free of charge on the free tier, with lower rate limits. On the free tier Google may use your content to improve its products, which does not happen on the paid tier.

Can Gemini TTS do more than two speakers?

Not in one request. The limit is two prebuilt voices per request, so for three or more characters you generate each turn separately and join the PCM audio.

Does Gemini TTS support streaming?

Yes. Pass stream=True and read audio from step.delta events. Streamed audio is raw 24 kHz, 16-bit mono PCM with no header.

How do I get an MP3 instead of WAV?

The API returns WAV, raw PCM, mu-law or A-law, not MP3. Convert the WAV file with a tool like ffmpeg or a Python audio library if you need MP3.

Do I need to set a language?

No. The model detects the language from your text. Write the transcript in the target language and keep inline tags like <laugh> in English.

Can I clone my own voice?

Voice replication can copy a speaker’s voice from reference audio plus a consent recording, in AI Studio or through the voices API. Use it only with clear permission from the person whose voice it is.

Is Gemini TTS a good replacement for OpenAI tts-1?

For simple “text in, audio file out” jobs, yes. It keeps a one-request workflow, while OpenAI’s suggested replacement moves you to a WebSocket-based Realtime API.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman at a whiteboard holding a tablet with a GEMINI TTS card, hook 30 voices two-speaker TTS