> ## 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 TTS

> Gemini 3.8 Flash TTS: 構造化した話し方の指定と WAV 出力に対応する、Gemini ネイティブ API のテキスト音声合成。

Gemini 3.8 Flash TTS は表現力の高い音声、対話、長いナレーション向けです。Google は 130 言語への対応を公表しています。

Gemini 3.8 Flash TTS はテキスト入力から音声を出力します。プロバイダー上限は入力 8,192 トークン、出力 16,384 トークンです。実際の制限と利用可否は MixRoute のルートに依存します。例は既存の Gemini generateContent パスを使い、Interactions や OpenAI 音声 API の対応を仮定しません。

## リクエストパラメーター

parts\[].text には読み上げる原文のみを入れ、話し方の指示は parts\[].speechMetadata.style に入れます。Say cheerfully などを先頭に付けると、そのまま読まれる場合があります。SDK や資料では speech\_metadata という名称の場合がありますが、REST JSON では speechMetadata です。3.8 の非ストリーミング出力は旧モデルの生 PCM と異なり、既定で WAV です。

| フィールド | 説明 |
| - | - |
| `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-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 を確認します。WAV を Base64 デコードして直接保存し、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-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.