进阶 ai.google.dev 2026-10-15 02:43:21 · 30 阅读

第6章 Gemini API 文档概览

Gemini 4 Argon 现已推出。立即试用。

Gemini API 文档

语音转文字生成 (TTS)

Gemini API 利用 Gemini 的文本转语音(TTS)生成能力,可将文本输入转化为单人或多人的音频输出。 TTS 生成具有可控性,意味着你可以结合结构化的轮流元数据(speech_metadata)和内联语音标签,来指导音频的风格、口音、语速和语调。

TTS 能力与通过 Live API 提供的语音生成不同,后者专为交互式、非结构化音频以及多模态输入输出而设计。虽然 Live API 在动态对话场景中表现出色,但通过 Gemini API 进行的 TTS 则专为需要精确朗读文本并对风格和声音进行细粒度控制的场景定制,例如播客或有声读物生成。

本指南将展示如何使用 Gemini 3.8 Flash TTS(gemini-3.8-flash-tts)和 Gemini 3.8 Flash-Lite TTS(gemini-3.8-flash-lite-tts)从文本生成单人和多人音频。

开始之前

请确保使用"支持的模型"部分列出的 Gemini TTS 模型,并升级至最新版本的 Google GenAI SDK(Python 为 google-genai >= 2.25.0 或 JavaScript/TypeScript 为 @google/genai >= 2.24.0),或使用 REST API。 为获得最佳效果,请查阅"何时使用哪种模型"以选择最适合你工作负载的模型。

在开始构建之前,你或许可以首先在 AI Studio 中测试 Gemini TTS 模型。

单人 TTS

要使用 Gemini 3.8 TTS 模型将文本转换为单人音频,请在输入中提供逐字稿,使用 speech_metadata 注释附加轮流级别的样式,并在 generation_config.speech_config 中配置你的声音。你可以从预建的 Voice 选项、扩展语音库(GET /v1beta/voices)、自定义 Voice 设计 ID(voice_...)或 Voice 复制 ID(voice_...,或可选的无状态 voicekey_...)中选择声音。

以下示例将模型默认生成的 WAV 输出音频(audio/wav)直接保存到文件中:

Python ```python import base64 from google import genai

client = genai.Client()

interaction = client.interactions.create( model="gemini-3.8-flash-tts", input=[{ "type": "user_input", "content": [{ "type": "text", "text": "Have a wonderful day!", "annotations": [{ "type": "speech_metadata", "style": "cheerful and friendly", }], }], }], response_format={"type": "audio"}, generation_config={ "speech_config": [ {"voice": "Kore"}, ] }, )

with open("out.wav", "wb") as f: f.write(base64.b64decode(interaction.output_audio.data)) ```

JavaScript ```javascript import * as fs from 'node:fs'; import {GoogleGenAI} from '@google/genai';

async function main() { const client = new GoogleGenAI({});

const interaction = await client.interactions.create({ model: 'gemini-3.8-flash-tts', input: [{ type: 'user_input', content: [{ type: 'text', text: 'Have a wonderful day!', annotations: [{ type: 'speech_metadata', style: 'cheerful and friendly', }], }], }], response_format: { type: 'audio' }, generation_config: { speech_config: [ { voice: 'Kore' }, ], }, });

const audioBuffer = Buffer.from(interaction.output_audio.data, 'base64'); fs.writeFileSync('out.wav', audioBuffer); } await main(); ```

REST ```bash curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-3.8-flash-tts", "input": [{ "type": "user_input", "content": [{ "type": "text", "text": "Have a wonderful day!", "annotations": [{ "type": "speech_metadata", "style": "cheerful and friendly" }] }] }], "response_format": { "type": "audio" }, "generation_config": { "speech_config": [ { "voice": "Kore" } ] } }' | jq -r '[.steps[] | select(.type=="model_output") | .content[] | select(.type=="audio")] | last | .data' | base64 --decode > out.wav ```

在 Python 和 JavaScript SDK 中,你可以使用 interaction.output_audio 便捷属性检索生成的音频数据,该属性返回最后生成的音频块(在原始 REST JSON 响应中,Base64 编码的音频存储在 steps[].content[].data 中)。有关便捷属性的详细信息,请参阅"Interactions 概览"。

多人 TTS

对于多人对话,在 speech_config.speakers 中配置两个说话者,并将每个轮流作为带有 speech_metadata 注释的独立文本项传入,该注释指定说话者及可选的轮流级别风格。请注意,speech_config 在接受单人生成时接受数组([{"voice": "..."}]),而在多人生成时接受对象({"speakers": [...]}):

Python ```python import base64 from google import genai

client = genai.Client()

interaction = client.interactions.create( model="gemini-3.8-flash-tts", input=[{ "type": "user_input", "content": [ { "type": "text", "text": "How's it going today Jane?", "annotations": [{ "type": "speech_metadata", "speaker": "Joe", "style": "cheerful and friendly", }], }, { "type": "text", "text": "Not too bad, how about you? Ready to test these new voices?", "annotations": [{ "type": "speech_metadata", "speaker": "Jane", "style": "calm and relaxed", }], }, ], }], response_format={"type": "audio"}, generation_config={ "speech_config": { "speakers": [ {"speaker": "Joe", "voice": "Puck"}, {"speaker": "Jane", "voice": "Kore"}, ], } }, )

with open("out.wav", "wb") as f: f.write(base64.b64decode(interaction.output_audio.data)) ```

JavaScript ```javascript import * as fs from 'node:fs'; import {GoogleGenAI} from '@google/genai';

async function main() { const client = new GoogleGenAI({});

const interaction = await client.interactions.create({ model: 'gemini-3.8-flash-tts', input: [{ type: 'user_input', content: [ { type: 'text', text: "How's it going today Jane?", annotations: [{ type: 'speech_metadata', speaker: 'Joe', style: 'cheerful and friendly', }], }, { type: 'text', text: 'Not too bad, how about you? Ready to test these new voices?', annotations: [{ type: 'speech_metadata', speaker: 'Jane', style: 'calm and relaxed', }], }, ], }], response_format: { type: 'audio' }, generation_config: { speech_config: { speakers: [ { speaker: 'Joe', voice: 'Puck' }, { speaker: 'Jane', voice: 'Kore' }, ], }, }, });

const audioBuffer = Buffer.from(interaction.output_audio.data, 'base64'); fs.writeFileSync('out.wav', audioBuffer); }

await main(); ```

REST ```bash curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-3.8-flash-tts", "input": [{ "type": "user_input", "content": [ { "type": "text", "text": "How'\''s it going today Jane?", "annotations": [{ "type": "speech_metadata", "speaker": "Joe", "style": "cheerful and friendly" }] }, { "type": "text", "text": "Not too bad, how about you? Ready to test these new voices?", "annotations": [{ "type": "speech_metadata", "speaker": "Jane", "style": "calm and relaxed" }] } ] }], "response_format": { "type": "audio" }, "generation_config": { "speech_config": { "mode": "conversational", "speakers": [ { "speaker": "Joe", "voice": "Puck" }, { "speaker": "Jane", "voice": "Kore" } ] } } }'

使用元数据和标签控制语音风格

Gemini 3.8 TTS 将 text 字段严格视为逐字稿。为了在不让舞台指示被朗读的情况下控制演绎方式,请根据范围拆分你的指令:

* 持续性的轮流级别演绎 (speech_metadata.style):将适用于整个轮流的情绪、演绎风格、韵律、节奏和音量放入 style 字段(例如,"style": "whispered urgently"、"style": "out of breath" 或 "style": "warm and enthusiastic")。 * 时间点事件 (内联标签):使用尖括号直接在逐字稿内放置短暂的非语音人声爆发或停顿(例如,"Wait... did you hear that? " 或 "Excuse me as I was saying...")。

有关全面的最佳实践,请参阅"提示指南"。

Python ```python import base64 from google import genai

client = genai.Client()

interaction = client.interactions.create( model="gemini-3.8-flash-tts", input=[{ "type": "user_input", "content": [ { "type": "text", "text": "Wait... look under that fallen log! Is that a blue-spotted salamander?", "annotations": [{ "type": "speech_metadata", "speaker": "Dr. Anya", "style": "whispered urgently", }], }, { "type": "text", "text": " No way! We've been searching for this species all season!", "annotations": [{ "type": "speech_metadata", "speaker": "Liam", "style": "warm and enthusiastic", }], }, ], }], response_format={"type": "audio"}, generation_config={ "speech_config": { "speakers": [ {"speaker": "Dr. Anya", "voice": "Kore"}, {"speaker": "Liam", "voice": "Puck"}, ], } }, )

with open("out.wav", "wb") as f: f.write(base64.b64decode(interaction.output_audio.data)) ```

JavaScript ```javascript import {GoogleGenAI} from '@google/genai';

async function main() { const client = new GoogleGenAI({});

const interaction = await client.interactions.create({ model: 'gemini-3.8-flash-tts', input: [{ type: 'user_input', content: [ { type: 'text', text: 'Wait... look under that fallen log! Is that a blue-spotted salamander?', annotations: [{ type: 'speech_metadata', speaker: 'Dr. Anya', style: 'whispered urgently', }], }, { type: 'text', text: " No way! We've been searching for this species all season!", annotations: [{ type: 'speech_metadata', speaker: 'Liam', style: 'warm and enthusiastic', }], }, ], }], response_format: { type: 'audio' }, generation_config: { speech_config: { speakers: [ { speaker: 'Dr. Anya', voice: 'Kore' }, { speaker: 'Liam', voice: 'Puck' }, ], }, }, });

if (interaction.output_audio?.data) { const audioBuffer = Buffer.from(interaction.output_audio.data, 'base64'); fs.writeFileSync('out.wav', audioBuffer); } }

await main(); ```

REST ```bash curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-3.8-flash-tts", "input": [{ "type": "user_input", "content": [ { "type": "text", "text": "Wait... look under that fallen log! Is that a blue-spotted salamander?", "annotations": [{ "type": "speech_metadata", "speaker": "Dr. Anya", "style": "whispered urgently" }] }, { "type": "text", "text": " No way! We'\''ve been searching for this species all season!", "annotations": [{ "type": "speech_metadata", "speaker": "Liam", "style": "warm and enthusiastic" }] } ] }], "response_format": { "type": "audio" }, "generation_config": { "speech_config": { "speakers": [ { "speaker": "Dr. Anya", "voice": "Kore" }, { "speaker": "Liam", "voice": "Puck" } ] } } }'

流式语音生成

通过设置 stream: true,你可以在音频合成过程中对其进行流式传输。与一元请求(返回带有 RIFF 头部的完整 WAV 文件)不同,流式请求默认返回无头部的原始 16 位有符号小端线性 PCM (audio/l16, 24 kHz, 单声道) 块,以便可以连续播放或连接音频块而无需容器头部。

Python ```python import base64 from google import genai

client = genai.Client()

stream = client.interactions.create( model="gemini-3.8-flash-tts", input=[{ "type": "user_input", "content": [{ "type": "text", "text": "Have a wonderful day!", "annotations": [{ "type": "speech_metadata", "style": "cheerful and friendly", }], }], }], response_format={"type": "audio"}, generation_config={ "speech_config": [ {"voice": "Kore"}, ] }, stream=True, )

for event in stream: if event.event_type == "step.delta": if event.delta.type == "audio": audio_data = base64.b64decode(event.delta.data) # Process the audio chunk (e.g. play it or write to a file) ```

JavaScript ```javascript import {GoogleGenAI} from '@google/genai';

async function main() { const client = new GoogleGenAI({});

const stream = await client.interactions.create({ model: 'gemini-3.8-flash-tts', input: [{ type: 'user_input', content: [{ type: 'text', text: 'Have a wonderful day!', annotations: [{ type: 'speech_metadata', style: 'cheerful and friendly', }], }], }], response_format: { type: 'audio' }, generation_config: { speech_config: [ { voice: 'Kore' }, ], }, stream: true, });

for await (const event of stream) { if (event.event_type === 'step.delta') { if (event.delta.type === 'audio') { const audioBuffer = Buffer.from(event.delta.data, 'base64'); // Process the audio buffer } } } } await main(); ```

REST ```bash curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ --no-buffer \ -d '{ "model": "gemini-3.8-flash-tts", "input": [{ "type": "user_input", "content": [{ "type": "text", "text": "Have a wonderful day!", "annotations": [{ "type": "speech_metadata", "style": "cheerful and friendly" }] }] }], "response_format": { "type": "audio" }, "generation_config": { "speech_config": [ { "voice": "Kore" } ] }, "stream": true }'

音频输出格式

Gemini 3.8 TTS 模型根据请求是一元的还是流式的,使用不同的默认音频格式:

* 一元请求 (stream=False):返回带有标准 RIFF 头部的完整 WAV (audio/wav) 音频(24 kHz,单声道,16 位有符号小端 PCM)。你可以将解码后的音频字节直接保存为 .wav 文件,而无需手动添加 WAV 头部。 * 流式请求 (stream=True):默认返回无头部的原始线性 PCM (audio/l16) 块(24 kHz,单声道,16 位有符号小端 PCM),以便块可以连续流式传输或连接,且每个块上都没有容器头部。

若要请求不同的音频编码或采样率,请在 response_format 内配置 mime_type 和可选的 sample_rate:

| 格式 | mime_type 值 | 描述 | | :--- | :--- | :--- | | WAV (一元默认) | "audio/wav" | 带有 RIFF 头部的未压缩 WAV 文件(16 位有符号小端 PCM,单声道,默认 24 kHz)。一元请求的默认值。 | | 原始 PCM (L16) (流式默认) | "audio/l16" | 未压缩、无头部的 16 位有符号小端线性 PCM 音频(24 kHz,单声道)。流式请求的默认值。 | | Mu-law | "audio/mulaw" | 8 位 G.711 mu-law 编码的音频(常用于北美和日本的电话/IVR 系统)。 | | A-law | "audio/alaw" | 8 位 G.711 A-law 编码的音频(常用于欧洲和国际电话系统)。 |

你还可以指定以赫兹为单位的 sample_rate(例如,24000、16000 或 8000)。

Python ```python import base64 from google import genai

client = genai.Client()

interaction = client.interactions.create( model="gemini-3.8-flash-tts", input=[{ "type": "user_input", "content": [{ "type": "text", "text": "Have a wonderful day!", "annotations": [{ "type": "speech_metadata", "style": "cheerful and friendly", }], }], }], response_format={ "type": "audio", "mime_type": "audio/l16", # "audio/wav" (默认), "audio/l16", "audio/mulaw", 或 "audio/alaw" "sample_rate": 24000, }, generation_config={ "speech_config": [ {"voice": "Kore"}, ] }, )

with open("out.pcm", "wb") as f: f.write(base64.b64decode(interaction.output_audio.data)) ```

JavaScript ```javascript import * as fs from 'node:fs'; import {GoogleGenAI} from '@google/genai';

async function main() { const client = new GoogleGenAI({});

const interaction = await client.interactions.create({ model: 'gemini-3.8-flash-tts', input: [{ type: 'user_input', content: [{ type: 'text', text: 'Have a wonderful day!', annotations: [{ type: 'speech_metadata', style: 'cheerful and friendly', }], }], }], response_format: { type: 'audio', mime_type: 'audio/l16', // 'audio/wav' (默认), 'audio/l16', 'audio/mulaw', 或 'audio/alaw' sample_rate: 24000, }, generation_config: { speech_config: [ { voice: 'Kore' }, ], }, });

const audioBuffer = Buffer.from(interaction.output_audio.data, 'base64'); fs.writeFileSync('out.pcm', audioBuffer); } await main(); ```

REST ```bash curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-3.8-flash-tts", "input": [{ "type": "user_input", "content": [{ "type": "text", "text": "Have a wonderful day!", "annotations": [{ "type": "speech_metadata", "style": "cheerful and friendly" }] }] }], "response_format": { "type": "audio", "mime_type": "audio/l16", "sample_rate": 24000 }, "generation_config": { "speech_config": [ { "voice": "Kore" } ] } }'

声音选项

Gemini 3.8 TTS 支持四种选择或创建声音的方式:

* 预建工作室声音:下表中列出的 30 种精选声音。 * 扩展语音库:通过 client.voices.list() (GET /v1beta/voices) 可访问的数百种额外声音,涵盖多种语言、口音和角色原型。 * 声音设计:在 Google AI Studio 中或通过 POST /v1beta/voices (type="prompted") 从自然语言描述生成自定义语音人格(返回持久的 voice_... ID 和 CreateVoice 和 GetVoice 中的 sample_audio WAV 预览)。 * 声音复制:在 Google AI Studio 中或通过 POST /v1beta/voices (type="replicated") 从参考音频和同意音频中复制说话者的声音(默认持久存储 store=True 或可选无状态 store=False)。

自定义声音限制和 TTL

| 声音类型 | 存储模式 | 配额/限制 | 保留期 (TTL) | | :--- | :--- | :--- | :--- | | 有状态声音 (voice_...,prompted 或 replicated) | store=True | 每个项目 200 个声音(在 prompted 和 replicated 声音之间共享) | 自上次使用起 1 年* | | 无状态 voice key (voicekey_...,replicated) | store=False | 客户端管理 | 7 天 |

*\* TTL 扩展:每当声音被主动使用(即使用该声音合成语音或将其用作混音的基础声音)时,1 年的保留期窗口会重置。如果声音在 1 年内没有任何活动,将被自动删除。*

预建声音

* Zephyr -- Bright * Puck -- Upbeat * Charon -- Informative * Kore -- Firm * Fenrir -- Excitable * Leda -- Youthful * Orus -- Firm * Aoede -- Breezy * Callirrhoe -- Easy-going * Autonoe -- Bright * Enceladus -- Breathy * Iapetus -- Clear * Umbriel -- Easy-going * Algieba -- Smooth * Despina -- Smooth * Erinome -- Clear * Algenib -- Gravelly * Rasalgethi -- Informative * Laomedeia -- Upbeat * Achernar -- Soft * Alnilam -- Firm * Schedar -- Even * Gacrux -- Mature * Pulcherrima -- Forward * Achird -- Friendly * Zubenelgenubi -- Casual * Vindemiatrix -- Gentle * Sadachbia -- Lively * Sadaltager -- Knowledgeable * Sulafat -- Warm

扩展语音库及过滤

除了前表中 30 种精选工作室声音之外,扩展语音库提供了数百种涵盖不同语言、地区口音、角色人格和领域的额外声音。你可以在 Google AI Studio 中交互式地浏览、过滤和试听完整的语音库,或者使用 client.voices.list() (GET /v1beta/voices,需使用 google-genai 2.25.0+ / @google/genai 2.24.0+) 进行编程查询。

ListVoices 返回你的自定义存储声音(按最新排序),其次是符合你过滤标准的预建目录声音。当为列表过滤器传递多个值时,返回符合该过滤器中任一值的声音(OR),而不同的过滤器参数组合使用 AND:

| 参数 | 类型 | 描述 | | :--- | :--- | :--- | | language_code | list[str] | BCP-47 语言标签(例如,["en-US", "en-GB"])。不区分大小写的精确匹配。 | | region_code | list[str] | ISO 3166-1 alpha-2 或 UN M.49 区域代码(例如,["US", "GB"])。 | | accent | list[str] | 地区口音描述符(例如,["American", "British"])。 | | gender | list[str] | 感知性别表现("female"、"male" 或 "neutral")。 | | pitch | list[str] | 声音音调分类("low"、"medium" 或 "high")。 | | persona | list[str] | 语音人格或角色原型(例如,["Warm, Friendly"]、["Narrator"])。 | | contexts (REST 中为 context) | list[str] | 最佳使用领域(例如,["Audiobook", "Conversational", "News"])。 | | type (Python 中为 type_) | list[str] | 按声音来源过滤:"prebuilt"、"prompted" (Voice design) 或 "replicated" (Voice replication)。 | | search | str | 不区分大小写的自由文本子串搜索,同时匹配 display_name 和 description。 | | page_size | int | 每页返回的最大声音数量(默认 50,最大 1000)。 | | page_token | str | 来自 response.next_page_token 的令牌,用于获取结果下一页。 |

Python ```python from google import genai

client = genai.Client()

# 按语言、性别、音高、领域上下文和关键词过滤语音库 response = client.voices.list( language_code=["en-US", "en-GB"], gender=["female"], pitch=["medium", "low"], contexts=["Audiobook", "Conversational"], type_=["prebuilt"], search="warm", page_size=50, )

for voice in response.voices or []: print( f"{voice.id} | {voice.display_name} ({voice.language_code}," f" {voice.accent}, {voice.gender}, pitch={voice.pitch}):" f" {voice.description}" ) ```

JavaScript ```javascript import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI();

// 按语言、性别、音高、领域上下文和关键词过滤语音库 const response = await ai.voices.list({ language_code: ["en-US", "en-GB"], gender: ["female"], pitch: ["medium", "low"], contexts: ["Audiobook", "Conversational"], type: ["prebuilt"], search: "warm", page_size: 50, });

for (const voice of response.voices ?? []) { console.log( `${voice.id} | ${voice.display_name} (${voice.language_code}, ${voice.accent}, ${voice.gender}, pitch=${voice.pitch}): ${voice.description}` ); } ```

REST ```bash curl -G "https://generativelanguage.googleapis.com/v1beta/voices" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ --data-urlencode "language_code=en-US" \ --data-urlencode "language_code=en-GB" \ --data-urlencode "gender=female" \ --data-urlencode "pitch=medium" \ --data-urlencode "context=Audiobook" \ --data-urlencode "type=prebuilt" \ --data-urlencode "search=warm" \ --data-urlencode "page_size=50"

支持的语言

TTS 模型会自动检测输入语言。 Gemini 3.8 Flash TTS (gemini-3.8-flash-tts) 支持超过 130 种语言,Gemini 3.8 Flash-Lite TTS (gemini-3.8-flash-lite-tts) 支持超过 100 种语言:

(此处省略语言列表表格,保留原始结构中的复选标记逻辑,实际翻译中若需完整表格需逐行翻译,鉴于篇幅限制及通用性,此处保留英文语言名称,因为语言名称通常不翻译,且复选标记为符号)

| 语言 | Gemini 3.8 Flash TTS | Gemini 3.8 Flash-Lite TTS | | :--- | :---: | :---: | | Acehnese (Arab script) | ✔️ | ✔️ | | Afrikaans | ✔️ | ✔️ | | ... | ... | ... | | (完整列表见原文) | | |

支持的模型

| 模型 | 单人 | 多人 | 声音设计 | 声音复制 | | :--- | :---: | :---: | :---: | :---: | | Gemini 3.8 Flash TTS (gemini-3.8-flash-tts) | ✔️ | ✔️ | ✔️ | ✔️ | | Gemini 3.8 Flash-Lite TTS (gemini-3.8-flash-lite-tts) | ✔️ | ✔️ | ✔️ | ✔️ | | Gemini 3.1 Flash TTS Preview | ✔️ | ✔️ | — | — | | Gemini 2.5 Pro Preview TTS | ✔️ | ✔️ | — | — |

何时使用哪种模型

两个 Gemini 3.8 TTS 模型共享完全相同的 API 架构和提示格式,允许你通过更改单个参数来切换它们:

* 当你将最高声学保真度、细腻的表演和富有表现力的控制放在首位时,请使用 Gemini 3.8 Flash TTS (gemini-3.8-flash-tts)。它非常适合工作室级别的创意工作、复杂的多人大量对话、大量的人声爆发标签、困难的发音、地区性或少数族裔方言,以及需要稳健声音和房间音调稳定性的长篇叙述。 * 将 Gemini 3.8 Flash-Lite TTS (gemini-3.8-flash-lite-tts) 作为 gemini-3.1-flash-tts-preview 的快速、成本效益高的替代主力。它针对高吞吐量批量生产、对话式语音代理级联、朗读功能、可靠的声音复制以及主要语言的日常单人语音进行了优化。

迁移指南

如果你正在从 gemini-3.1-flash-tts-preview 或更早的 Gemini TTS 模型迁移到 Gemini 3.8 TTS:

* 将轮流级别指令移至 speech_metadata:Gemini 3.8 TTS 将输入文本严格视为逐字稿。将持续的演绎指令(风格,如 "whispering"、"out of breath" 或 "speaking slowly")和说话者标签(speaker)移至结构化的 speech_metadata 注释中,而不是将舞台指示嵌入在逐字稿文本中。 * 仅将尖括号内联标签用于时间点人声事件:使用尖括号在逐字稿内保持短暂的非语音发音和停顿(例如 、、、 或 )。避免音效标签(如掌声或撞击声),并将演绎风格放在 speech_metadata.style 中。 * 在多人请求中为每个轮流指定说话者:多人请求中的每个轮流都必须明确包含 speech_metadata 中的 speaker,且必须匹配已配置的说话者之一。 * 提前使用声音设计设定人格:用在声音设计中创建的自定义声音取代多段落的"Audio Profile"或"Director's Notes"块,然后在你的 TTS 请求中传递该 voice_... ID,风格字符串保持最小或为空。 * 考虑一元请求的默认 WAV (audio/wav) 输出:与 gemini-3.1-flash-tts-preview 和更早的 TTS 模型(默认返回无头部的原始 PCM audio/l16)不同,Gemini 3.8 TTS 对一元请求默认返回带有标准 RIFF 头部的 WAV

评论 (0)