> ## 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 語音合成

> 將要朗讀的文字放在 `contents[].parts[].text`，把 `generationConfig.responseModalities` 設為 `["AUDIO"]`。在 `generationConfig.speechConfig.voiceConfig.prebuiltVoiceConfig.voiceName` 選擇預設音色。

使用 MixRoute API Key 驗證，並在請求路徑填入完整模型 ID。本節說明 MixRoute 的 GenerateContent 請求格式。

`POST /v1/models/{model}:generateContent`

部分模型文件也列出了 `POST /v1beta/models/{model}:generateContent`。請使用對應模型頁指定的版本；以下範例使用 `/v1`。

## 模型 ID

* `gemini-2.5-flash-preview-tts`
* `gemini-2.5-pro-preview-tts`
* `gemini-3.1-flash-tts-preview`
* `gemini-3.8-flash-lite-tts`
* `gemini-3.8-flash-tts`

## 請求與回應

將要朗讀的文字放在 `contents[].parts[].text`，把 `generationConfig.responseModalities` 設為 `["AUDIO"]`。在 `generationConfig.speechConfig.voiceConfig.prebuiltVoiceConfig.voiceName` 選擇預設音色。

Gemini 3.8 TTS 等支援該欄位的路由可用 `speechMetadata.style` 指定說話方式。可選音色、單／多說話者模式與輸出編碼因型號而異。

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

成功後，從 `candidates[].content.parts[].inlineData` 取得音訊。對 `data` 做 Base64 解碼，再根據 `mimeType` 判斷編碼；已是 WAV 的資料不需再加檔頭。

可用性與欄位支援依 MixRoute 路由而定。請先查看獨立模型頁，不要預設支援串流或其他請求格式。


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