Speech synthesis (Interactions)
Synthesize single- or two-speaker speech with Interactions, including style control and streaming.
Convert the specified text to speech and return Base64 audio in complete JSON or SSE streaming. For model IDs, see the Gemini TTS model guide.
/v1beta/interactionsConvert text to audio with single-speaker narration, two-speaker dialogue and SSE streaming.
Authorization
bearerAuth Use Bearer your-api-key in the Authorization Header.
In: header
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
Text, voices and dialogue
| Field | Usage |
|---|---|
input | Pass a string for simple narration; use text blocks in a user_input step for style or speaker control |
annotations | Use a type: "speech_metadata" annotation on each text block to set style and speaker; keep style instructions out of the text to be spoken |
generation_config.speech_config | Use [{"voice":"Kore"}] for one speaker; use a speakers object to assign voices for dialogue |
speaker | Required on each dialogue text block; must exactly match speakers[].speaker; configure up to 2 speakers |
| Vocal effects and pauses | Use tags such as <laugh>, <sigh> and <short pause> in the text; put sustained delivery instructions in style |
Output and playback
| Mode or setting | Handling |
|---|---|
| Non-streaming response | Traverse steps, read the type: "audio" items in content of type: "model_output" steps and decode data; do not assume the first step contains audio |
| Default format | Non-streaming WAV, 24 kHz, mono, 16-bit; save or play directly without adding another WAV header |
response_format | mime_type accepts audio/wav, audio/l16, audio/mulaw or audio/alaw; sample_rate is in Hz, defaults to 24000, and also accepts 16000 or 8000 |
stream: true | SSE defaults to raw PCM16 little-endian audio. Decode each step.delta → delta.data separately, then concatenate the bytes in order; do not concatenate Base64 strings |
| Usage and completion | Read final usage from interaction.usage in interaction.completed; treat an error event as failure, not partial audio as a complete result |
Try It provides audio playback and download after the response completes, with the original JSON or SSE on the right. Raw PCM and G.711 audio are converted to WAV for playback; the original response is preserved.
Usage notes
| Item | Details |
|---|---|
| Input and capabilities | Text input and audio output; no tool calls or web search |
| Background settings | Requests return generation results directly; background and webhook_config are ignored, while agent returns a parameter error |
| Audio duration | Control duration through text length; max_output_tokens does not truncate audio. Split long text into paragraphs and allow a client timeout of at least 300 seconds |