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

# Gemini 2.5 Flash TTS 文本转语音

基于 Google Vertex AI generateContent 接口的 Gemini 2.5 Flash TTS。支持同步和流式单人/多人语音合成，通过自然语言提示词精确控制风格、口音、节奏、语调和情感表达。contents 字段最大 8000 字节，输出音频最长约 655 秒。Vertex AI 输出为 LINEAR16 PCM 格式（24kHz, 单声道），不包含 WAV 头。如需其他音频格式需客户端自行转换。

## 请求头

<ParamField header="Content-Type" type="string" required={true}>
  枚举值: `application/json`
</ParamField>

<ParamField header="Authorization" type="string" required={true}>
  Bearer 身份验证格式: Bearer \{\{API 密钥}}。
</ParamField>

## 请求体

<ParamField body="contents" type="object" required={true}>
  <Expandable title="properties" defaultOpen={true}>
    <ParamField body="role" type="string" required={true} default="user">
      角色，固定为 user

      可选值：`user`
    </ParamField>

    <ParamField body="parts" type="object" required={true}>
      <Expandable title="properties" defaultOpen={true}>
        <ParamField body="text" type="string" required={true}>
          要合成为语音的文本内容。Vertex AI API 将提示词和文本合并在一个字段中，格式为 '{prompt}: {text}'，例如 'Say the following in a curious way: OK, so... tell me about this AI thing.'。总大小最多 8000 字节，超出 655 秒的音频将被截断。支持内联标记标签：\[sigh]、\[laughing]、\[uhm]、\[sarcasm]、\[robotic]、\[shouting]、\[whispering]、\[extremely fast]、\[short pause]、\[medium pause]、\[long pause]

          长度限制：0 - 8000
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="generation_config" type="object" required={true}>
  <Expandable title="properties" defaultOpen={true}>
    <ParamField body="temperature" type="number" default={2}>
      温度参数，控制语音生成的随机性和创造性。值越高越有创意和多样性，值越低越可预测和集中。有效范围 (0.0, 2.0]，推荐值为 2.0

      取值范围：\[0, 2]
    </ParamField>

    <ParamField body="speech_config" type="object" required={true}>
      <Expandable title="properties" defaultOpen={true}>
        <ParamField body="voice_config" type="object">
          单人语音配置。与 multi\_speaker\_voice\_config 二选一

          <Expandable title="properties" defaultOpen={true}>
            <ParamField body="prebuilt_voice_config" type="object">
              <Expandable title="properties" defaultOpen={true}>
                <ParamField body="voice_name" type="string">
                  预置语音名称（大小写不敏感）。可选的 30 个语音（男女声均有）

                  可选值：`Achernar`, `Achird`, `Algenib`, `Algieba`, `Alnilam`, `Aoede`, `Autonoe`, `Callirrhoe`, `Charon`, `Despina`, `Enceladus`, `Erinome`, `Fenrir`, `Gacrux`, `Iapetus`, `Kore`, `Laomedeia`, `Leda`, `Orus`, `Pulcherrima`, `Puck`, `Rasalgethi`, `Sadachbia`, `Sadaltager`, `Schedar`, `Sulafat`, `Umbriel`, `Vindemiatrix`, `Zephyr`, `Zubenelgenubi`
                </ParamField>
              </Expandable>
            </ParamField>
          </Expandable>
        </ParamField>

        <ParamField body="language_code" type="string">
          语言代码（BCP-47 格式，大小写不敏感）。可选字段；不传时将根据输入文本自动识别语言。GA 语言：ar-EG, bn-BD, nl-NL, en-IN, en-US, fr-FR, de-DE, hi-IN, id-ID, it-IT, ja-JP, ko-KR, mr-IN, pl-PL, pt-BR, ro-RO, ru-RU, es-ES, ta-IN, te-IN, th-TH, tr-TR, uk-UA, vi-VN。Preview 语言包括 cmn-CN（中文普通话）等 63 种

          可选值：`af-ZA`, `am-ET`, `ar-001`, `ar-EG`, `az-AZ`, `be-BY`, `bg-BG`, `bn-BD`, `ca-ES`, `ceb-PH`, `cmn-CN`, `cmn-TW`, `cs-CZ`, `da-DK`, `de-DE`, `el-GR`, `en-AU`, `en-GB`, `en-IN`, `en-US`, `es-419`, `es-ES`, `es-MX`, `et-EE`, `eu-ES`, `fa-IR`, `fi-FI`, `fil-PH`, `fr-CA`, `fr-FR`, `gl-ES`, `gu-IN`, `he-IL`, `hi-IN`, `hr-HR`, `ht-HT`, `hu-HU`, `hy-AM`, `id-ID`, `is-IS`, `it-IT`, `ja-JP`, `jv-JV`, `ka-GE`, `kn-IN`, `ko-KR`, `kok-IN`, `la-VA`, `lb-LU`, `lo-LA`, `lt-LT`, `lv-LV`, `mai-IN`, `mg-MG`, `mk-MK`, `ml-IN`, `mn-MN`, `mr-IN`, `ms-MY`, `my-MM`, `nb-NO`, `ne-NP`, `nl-NL`, `nn-NO`, `or-IN`, `pa-IN`, `pl-PL`, `ps-AF`, `pt-BR`, `pt-PT`, `ro-RO`, `ru-RU`, `sd-IN`, `si-LK`, `sk-SK`, `sl-SI`, `sq-AL`, `sr-RS`, `sv-SE`, `sw-KE`, `ta-IN`, `te-IN`, `th-TH`, `tr-TR`, `uk-UA`, `ur-PK`, `vi-VN`
        </ParamField>

        <ParamField body="multi_speaker_voice_config" type="object">
          多人语音配置。与 voice\_config 二选一。注意：gemini-2.5-flash-lite-preview-tts 不支持多人合成

          <Expandable title="properties" defaultOpen={true}>
            <ParamField body="speaker_voice_configs" type="object[]">
              说话人语音配置列表

              <Expandable title="properties" defaultOpen={true}>
                <ParamField body="speaker" type="string" required={true}>
                  说话人别名，必须仅由字母数字字符组成，不含空格。需与 contents.parts.text 中的说话人标识一致
                </ParamField>

                <ParamField body="voice_config" type="object" required={true}>
                  <Expandable title="properties" defaultOpen={true}>
                    <ParamField body="prebuilt_voice_config" type="object">
                      <Expandable title="properties" defaultOpen={true}>
                        <ParamField body="voice_name" type="string">
                          预置语音名称（大小写不敏感）。可选的 30 个语音（男女声均有）

                          可选值：`Achernar`, `Achird`, `Algenib`, `Algieba`, `Alnilam`, `Aoede`, `Autonoe`, `Callirrhoe`, `Charon`, `Despina`, `Enceladus`, `Erinome`, `Fenrir`, `Gacrux`, `Iapetus`, `Kore`, `Laomedeia`, `Leda`, `Orus`, `Pulcherrima`, `Puck`, `Rasalgethi`, `Sadachbia`, `Sadaltager`, `Schedar`, `Sulafat`, `Umbriel`, `Vindemiatrix`, `Zephyr`, `Zubenelgenubi`
                        </ParamField>
                      </Expandable>
                    </ParamField>
                  </Expandable>
                </ParamField>
              </Expandable>
            </ParamField>
          </Expandable>
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

## 响应信息

<ResponseField name="audioContent" type="string" required={false}>
  Base64 编码的音频内容。格式为 LINEAR16 PCM（24kHz, 单声道, 16-bit signed little-endian），不包含 WAV 头。客户端可使用 ffmpeg 转换：ffmpeg -f s16le -ar 24k -ac 1 -i input.raw output.wav
</ResponseField>

<ResponseField name="usageMetadata" type="object" required={false}>
  <Expandable title="properties" defaultOpen={true}>
    <ResponseField name="totalTokenCount" type="integer" required={false}>
      总 token 数量（promptTokenCount + candidatesTokenCount）
    </ResponseField>

    <ResponseField name="promptTokenCount" type="integer" required={false}>
      输入文本消耗的 token 数量
    </ResponseField>

    <ResponseField name="candidatesTokenCount" type="integer" required={false}>
      输出音频消耗的 token 数量（每秒音频约 25 个 token）
    </ResponseField>
  </Expandable>
</ResponseField>
