Speech synthesis (Generate Content)
Synthesize speech with Generate Content, including voice settings, delivery style and two-speaker dialogue.
Convert text to speech in Generate Content format and return complete JSON with Base64 audio. Set the model ID in the request path; see the Gemini TTS model guide. For streaming, use Interactions.
/v1beta/models/{model}:generateContentConvert text to single-speaker narration or two-speaker dialogue and return a complete JSON result.
Authorization
bearerAuth Use Bearer your-api-key in the Authorization Header.
In: header
Path Parameters
Enter an enabled model ID. See the Gemini TTS model guide for available models.
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
application/json
Text, voices and dialogue
| Field | Usage |
|---|---|
contents[].parts[].text | Text to read aloud; put tone, emotion or accent instructions in the segment's speech_metadata.style |
speechConfig.voiceConfig.voice | Choose a voice such as Kore for one speaker; do not combine with multiSpeakerVoiceConfig |
speechConfig.multiSpeakerVoiceConfig | Set each speaker's name and voiceConfig.voice in speakerVoiceConfigs, up to 2 speakers |
speech_metadata.speaker | Required for each dialogue text segment; must match speakerVoiceConfigs[].speaker; segments are read in parts order |
| Vocal effects and pauses | Put tags such as <laugh>, <sigh> and <short pause> in the text; use speech_metadata.style for sustained delivery instructions |
The speechConfig above is inside generationConfig. Switch request examples between single speaker, style control, dialogue and PCM audio.
Output and playback
| Field or format | Handling |
|---|---|
candidates[].content.parts[].inlineData | Traverse the audio segments and decode Base64 data according to mimeType; audio is not returned as a download URL |
| Default format | WAV, 24 kHz, mono, 16-bit; save as .wav without adding another header |
generationConfig.responseFormat.audio | mimeType accepts AUDIO_WAV, AUDIO_L16, AUDIO_MULAW or AUDIO_ALAW; sampleRate sets the output rate in Hz, default 24000 |
| Raw audio | Play PCM16 little-endian using its sample rate and channel count, or wrap it in WAV; Mu-law and A-law require their corresponding decoders |
| Usage and completion | usageMetadata reports token usage; check finishReason to distinguish normal completion from content filtering and other stop reasons |
Try It provides audio playback and download after the response completes, with complete JSON on the right. Raw PCM and G.711 audio are converted to WAV for playback.