> ## Documentation Index
> Fetch the complete documentation index at: https://mixroute.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini 3.8 Flash-Lite TTS

> Gemini 3.8 Flash-Lite TTS: 透過 Gemini 原生介面進行文字轉語音，支援結構化朗讀風格和 WAV 輸出。

Gemini 3.8 Flash-Lite TTS 側重低延遲和高吞吐語音生成。Google 公布支援 101 種語言。

Gemini 3.8 Flash-Lite TTS 接收文字並輸出音訊。廠商限制為 8,192 輸入 tokens、16,384 輸出 tokens；實際限制與可用性取決於 MixRoute 路由。範例使用既有 Gemini 原生 generateContent 路徑，不假定支援 Interactions 或 OpenAI 音訊介面。

## 請求參數

parts\[].text 只寫需要朗讀的原文，朗讀指令放入 parts\[].speechMetadata.style。不要加 Say cheerfully 之類前綴，它可能被直接讀出。SDK 或說明文件可能使用 speech\_metadata 命名；REST JSON 欄位為 speechMetadata。3.8 的非串流輸出預設 WAV，不再沿用舊版預設的原始 PCM。

| 欄位 | 說明 |
| - | - |
| `contents[].parts[].text` | 必填，僅放需要朗讀的文字。 |
| `contents[].parts[].speechMetadata.style` | 可選的語氣與表達方式指令。 |
| `generationConfig.responseModalities` | \["AUDIO"] |
| `generationConfig.speechConfig` | 使用 generationConfig.responseModalities=\["AUDIO"]，並設定 speechConfig.voiceConfig.prebuiltVoiceConfig.voiceName，例如 Kore。多說話人請求中，每項 speechMetadata.speaker 須對應 speakerVoiceConfigs 設定，不要同時傳單音色與多說話人設定。 |

## 請求範例

設定 MIXROUTE\_API\_KEY 環境變數。Python 示例僅使用標準函式庫。

```bash theme={null}
curl --request POST "https://api.mixroute.ai/v1/models/gemini-3.8-flash-lite-tts:generateContent" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "contents": [
    {
      "parts": [
        {
          "text": "Welcome to MixRoute.",
          "speechMetadata": {
            "style": "Warm, clear and unhurried."
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "AUDIO"
    ],
    "speechConfig": {
      "voiceConfig": {
        "prebuiltVoiceConfig": {
          "voiceName": "Kore"
        }
      }
    }
  }
}'
```

## 讀取音訊結果

讀取 candidates\[].content.parts\[].inlineData.data 和 mimeType。Base64 解碼後直接寫入 WAV 檔案，不要再次加入 WAV 標頭。Python 範例會拒絕缺少音訊或非 WAV 資料，避免靜默產生損壞檔案。自訂音色、串流等廠商能力仍須路由單獨支援。

```python theme={null}
import base64
import json
import os
from pathlib import Path
from urllib.request import Request, urlopen

payload = {
    "contents": [
        {
            "parts": [
                {
                    "text": "Welcome to MixRoute.",
                    "speechMetadata": {
                        "style": "Warm, clear and unhurried."
                    }
                }
            ]
        }
    ],
    "generationConfig": {
        "responseModalities": [
            "AUDIO"
        ],
        "speechConfig": {
            "voiceConfig": {
                "prebuiltVoiceConfig": {
                    "voiceName": "Kore"
                }
            }
        }
    }
}
request = Request(
    "https://api.mixroute.ai/v1/models/gemini-3.8-flash-lite-tts:generateContent",
    data=json.dumps(payload).encode("utf-8"),
    headers={
        "Authorization": "Bearer " + os.environ["MIXROUTE_API_KEY"],
        "Content-Type": "application/json",
    },
    method="POST",
)
with urlopen(request, timeout=120) as response:
    result = json.load(response)

audio = next((
    part["inlineData"]
    for candidate in result.get("candidates", [])
    for part in candidate.get("content", {}).get("parts", [])
    if part.get("inlineData", {}).get("mimeType", "").startswith("audio/")
), None)
if not audio:
    reasons = [c.get("finishReason") for c in result.get("candidates", [])]
    raise RuntimeError(f"No audio: finishReason={reasons}; promptFeedback={result.get('promptFeedback')}")
mime_type = audio["mimeType"].split(";", 1)[0].strip().lower()
if mime_type not in ("audio/wav", "audio/x-wav"):
    raise RuntimeError(f"Expected WAV, received {mime_type}")
wav = base64.b64decode(audio["data"], validate=True)
if wav[:4] != b"RIFF" or wav[8:12] != b"WAVE":
    raise RuntimeError("The audio data is not a WAV file")
Path("speech.wav").write_bytes(wav)
print("speech.wav")
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.