Gemini TTS Integration Guide#
Model: gemini-3.1-flash-tts-preview
Status: Verified Available
Calling Method#
Uses the Gemini native endpoint /v1beta/models/{model}:generateContent — this is not the OpenAI-compatible /v1/audio/speech endpoint.Endpoint#
POST https://platform.dataeyes.ai/v1beta/models/gemini-3.1-flash-tts-preview:generateContent
Authentication#
Authorization: Bearer sk-YOUR_API_KEY
cURL Example#
Python Example#
{
"candidates": [
{
"content": {
"parts": [
{
"inlineData": {
"mimeType": "audio/l16; rate=24000; channels=1",
"data": "AAAAAAAAAA...(Base64-encoded PCM audio data)"
}
}
]
}
}
],
"usageMetadata": {
"promptTokenCount": 15,
"candidatesTokenCount": 200,
"totalTokenCount": 215
}
}
Response Field Descriptions#
| Field | Description |
|---|
mimeType | audio/l16; rate=24000; channels=1 — 16-bit PCM, 24kHz sample rate, mono |
data | Base64-encoded raw PCM audio data |
Available Voices#
Specify in speechConfig.voiceConfig.prebuiltVoiceConfig.voiceName:| Voice Name | Description |
|---|
| Kore | Female |
| Charon | Male |
| Fenrir | Male |
| Aoede | Female |
| Puck | Male |
| Leda | Female |
Official Pricing#
| Type | Paid Tier (per 1M tokens) |
|---|
| Input (text) | $1.00 |
| Output (audio) | $20.00 |
Audio token conversion: 25 audio tokens per second
Important Notes#
1.
You must use the Gemini native endpoint format — the OpenAI-compatible /v1/audio/speech endpoint is not supported
2.
The response contains raw PCM audio (not MP3/WAV) — the client must convert the format or play PCM directly
3.
responseModalities must be set to ["AUDIO"]; otherwise, text is returned instead of speech
4.
Supports multilingual input including Chinese and English — the model automatically detects the language
5.
For streaming output, change the endpoint to streamGenerateContent?alt=sse:POST /v1beta/models/gemini-3.1-flash-tts-preview:streamGenerateContent?alt=sse
Verification Record (2026-04-20)#
Request: "Hello, welcome to our service. This is a test of text to speech."
Result: Audio data returned successfully
Response Format: audio/l16; rate=24000; channels=1
Modified at 2026-10-19 10:10:04