中文博物馆导览 — 中文导览词,语言根据文本自动识别。
Gemini 3.8 Flash TTS Text to Speech API
google/gemini-3.8-flash/text-to-speechGemini 3.8 Flash TTS Text to Speech 将文稿和双人对话转为 WAV 语音,覆盖130种语言并提供30种预设音色。整段请求和每句台词都可设置风格指令,让演绎遵循你的指导,同时按原文朗读文稿。
输入
示例
Gemini 3.8 Flash TTS Text to Speech API
通过 API 生成语音
提交文稿并保存返回的 task_id,通过任务状态接口获取完成后的音频。
设置请求认证
在 Authorization 请求头中使用 Bearer 方式传入 Vidgo API 密钥。
- 接口地址
- POST
https://api.vidgo.ai/api/generate/submit - 认证方式
- Authorization: Bearer YOUR_API_KEY
提交文稿或对话
以 JSON 提交 model 与 input。下方示例与本页第一条音频示例一致。
REQUEST_BODY=$(cat <<'JSON'
{
"model": "google/gemini-3.8-flash/text-to-speech",
"input": {
"text": "The snow had been falling for three days when the letter arrived. It carried no stamp, no return address, only my name, written in my grandmother's careful hand.",
"voice": "Charon",
"style_instructions": "Read like a seasoned audiobook narrator: unhurried, low and warm, with a short pause after each sentence.",
"enable_safety_checker": true
}
}
JSON
)
RESPONSE=$(curl --silent --show-error --fail-with-body \
--request POST \
--url "https://api.vidgo.ai/api/generate/submit" \
--header "Authorization: Bearer $VIDGO_API_KEY" \
--header "Content-Type: application/json" \
--data "$REQUEST_BODY")
CODE=$(printf '%s' "$RESPONSE" | jq -r '.code // empty')
if [ "$CODE" != "0" ] && [ "$CODE" != "200" ]; then
printf 'API error: %s
' "$RESPONSE" >&2
exit 1
fi
printf '%s
' "$RESPONSE"查询任务
使用返回的 task_id 查询,直至 status 为 finished 或 failed。
状态接口
GET https://api.vidgo.ai/api/generate/status/{task_id}保存提交时返回的 task_id,查询其状态,并在完成后读取生成文件。
not_startedrunningfinishedfailed{
"code": 200,
"data": {
"task_id": "3LCLZTC34PBO54EP",
"status": "not_started",
"created_time": "2026-11-05T07:14:43"
}
}{
"code": 200,
"data": {
"task_id": "3LCLZTC34PBO54EP",
"status": "finished",
"files": [
{
"file_url": "https://cdn.vidgo.ai/apis/models/google/gemini-3.8-flash/text-to-speech/v2/02/speech-01.wav",
"file_type": "audio",
"file_name": "speech-01.wav"
}
],
"created_time": "2026-11-05T07:14:43",
"error_message": null,
"progress": 100
}
}获取音频文件
使用音频 file_url 播放或下载 WAV 文件。
set -euo pipefail
: "${VIDGO_API_KEY:?Set VIDGO_API_KEY in your environment}"
REQUEST_BODY=$(cat <<'JSON'
{
"model": "google/gemini-3.8-flash/text-to-speech",
"input": {
"text": "The snow had been falling for three days when the letter arrived. It carried no stamp, no return address, only my name, written in my grandmother's careful hand.",
"voice": "Charon",
"style_instructions": "Read like a seasoned audiobook narrator: unhurried, low and warm, with a short pause after each sentence.",
"enable_safety_checker": true
}
}
JSON
)
SUBMIT_RESPONSE=$(curl --silent --show-error --fail-with-body \
--request POST \
--url "https://api.vidgo.ai/api/generate/submit" \
--header "Authorization: Bearer $VIDGO_API_KEY" \
--header "Content-Type: application/json" \
--data "$REQUEST_BODY")
TASK_ID=$(printf '%s' "$SUBMIT_RESPONSE" | jq -r '.data.task_id // .task_id // empty')
BUSINESS_CODE=$(printf '%s' "$SUBMIT_RESPONSE" | jq -r '.code // empty')
if [ "$BUSINESS_CODE" != "0" ] && [ "$BUSINESS_CODE" != "200" ]; then
printf 'Submit failed:
%s
' "$SUBMIT_RESPONSE" >&2
exit 1
fi
if [ -z "$TASK_ID" ]; then
printf 'Submit response did not include task_id:
%s
' "$SUBMIT_RESPONSE" >&2
exit 1
fi
START_TIME=$(date +%s)
POLL_DELAY=2
while true; do
if [ $(( $(date +%s) - START_TIME )) -ge 600 ]; then
printf 'Timed out after 600 seconds
' >&2
exit 1
fi
STATUS_RESPONSE=$(curl --silent --show-error --fail-with-body \
--url "https://api.vidgo.ai/api/generate/status/$TASK_ID" \
--header "Authorization: Bearer $VIDGO_API_KEY")
STATUS=$(printf '%s' "$STATUS_RESPONSE" | jq -r '.data.status // .status // empty')
BUSINESS_CODE=$(printf '%s' "$STATUS_RESPONSE" | jq -r '.code // empty')
if [ "$BUSINESS_CODE" != "0" ] && [ "$BUSINESS_CODE" != "200" ]; then
printf 'Status request failed:
%s
' "$STATUS_RESPONSE" >&2
exit 1
fi
case "$STATUS" in
finished)
printf '%s' "$STATUS_RESPONSE" | jq -r '(.data.files // .files // [])[]?.file_url'
break
;;
failed)
printf '%s' "$STATUS_RESPONSE" | jq -r '.data.error_message // .error_message // "Generation failed"' >&2
exit 1
;;
not_started|running)
sleep "$POLL_DELAY"
if [ "$POLL_DELAY" -lt 10 ]; then POLL_DELAY=$((POLL_DELAY + 1)); fi
;;
*)
printf 'Unexpected task status: %s
' "$STATUS" >&2
exit 1
;;
esac
done请求参数
语音控制参数填写在 input 内,model 与 callback_url 位于请求顶层。
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| model | string | 是 | — | 使用 google/gemini-3.8-flash/text-to-speech 选择该语音模型。 |
| input | object | 是 | — | 单人模式使用 text 和 voice,对话模式使用 speakers 和 turns,并可加上下列可选字段。 |
| input.text | string | 单人模式必填 | — | 单人模式:要朗读的文稿。请按实际要听到的内容书写,演绎指令放在 Style Instructions 中。 |
| input.voice | string | 可选 | Kore | 单人模式:30种预设音色之一,默认 Kore。 音色: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. |
| input.speakers | array | 对话模式必填 | — | 对话模式:恰好两位说话人,每位需要唯一的 speaker_id 和30种预设音色之一。 |
| input.speakers[].speaker_id | string | 每项必填 | — | 说话人唯一且非空的名称,例如 Host。 |
| input.speakers[].voice | string | 每项必填 | — | 该说话人的预设音色。 音色: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. |
| input.turns | array | 对话模式必填 | — | 对话模式:按顺序排列的台词。每条需指定 Speakers 中的 speaker_id 和 text,并可为该句单独填写 style_instructions。 |
| input.turns[].speaker_id | string | 每项必填 | — | 说出该句台词的说话人 speaker_id。 |
| input.turns[].text | string | 每项必填 | — | 该句台词内容,不能为空。 |
| input.turns[].style_instructions | string | 可选 | — | 仅作用于该句的可选指令。 |
| input.style_instructions | string | 可选 | — | 可选,整段请求的演绎指令,例如语气、语速或场景。其字符计入费用。 |
| input.enable_safety_checker | boolean | 可选 | true | 对请求启用上游安全检查,默认 true。 |
| callback_url | string | 否 | — | 可选的 HTTP 或 HTTPS 任务通知地址,填写在请求顶层。 |
响应字段
提交响应提供任务标识,状态响应用于跟踪语音生成直至完成。
| 字段 | 类型 | 说明 |
|---|---|---|
| code | integer | 响应代码,成功响应使用200或0。 |
| data.task_id | string | 用于查询状态的任务标识。 |
| data.status | string | 任务状态:not_started、running、finished 或 failed。 |
| data.created_time | string | 服务返回的任务创建时间。 |
| data.files | array | 生成的文件;audio 条目为 WAV 语音。 |
| data.files[].file_url | string | 用于播放或下载生成文件的地址。 |
| data.files[].file_type | string | audio 表示生成的语音。 |
| data.files[].file_name | string | 返回的文件名,如有。 |
| data.error_message | string | null | 任务失败时的错误详情。 |
任务生命周期
根据任务状态决定继续查询或读取结果。
not_started任务已接收,等待开始。
running正在生成语音,继续查询当前任务。
finished生成完成,从 files 读取 WAV 音频。
failed生成失败,查看 error_message 后决定是否重新提交。
处理结果与中断
- 保留当前任务标识状态查询中断时,使用同一 task_id 再次查询,获取最新状态。
- 按用途读取文件读取 files 中的 audio 条目,使用其 file_url 与 file_name 下载。
- 检查失败任务status 为 failed 时,查看 error_message,检查文稿与设置后再提交生成。
语音规格
| 项目 | 规格 | 说明 |
|---|---|---|
| 任务 | Text to Speech | 单人语音或双人对话。 |
| 音色 | 30种预设 | 默认 Kore;对话中每位说话人一种音色。 |
| 说话人 | 1或2 | 对话模式需恰好两位说话人和至少一条台词。 |
| 语言 | 130 | 根据文稿自动识别。 |
| 输出 | WAV | 每个任务返回一个音频文件。 |
| 价格 | $0.045 / 1K 字符 | 每1,000计费字符9 credits。 |
Gemini 3.8 Flash TTS Text to Speech API 常见问题
Gemini 3.8 Flash TTS Text to Speech API 是什么?
Gemini 3.8 Flash TTS Text to Speech 是 Google 用于从文本生成自然语音的模型。它能以130种语言生成单人旁白或双人对话,提供30种预设音色,并用风格指令控制语气和语速。Google 将 3.8 Flash 档位定位于音色保真和表演细节,模型在遵循你的指导的同时按原文朗读文稿。你可以通过 API 进行程序化调用,也可以在上方体验区直接在线试用。
Gemini 3.8 Flash TTS 如何生成双人对话?
选择 Dialogue,提交恰好两位 speakers(各含 speaker_id 和预设音色)以及 turns 列表。每条台词指定一个 speaker_id、text,并可选填 style_instructions。此形式下不提交顶层 text 和 voice。
Gemini 3.8 Flash TTS 的演绎指令应写在哪里?
写在 style_instructions 中,可作用于整段请求或单条台词。Google 说明 Gemini 3.8 TTS 会按字面朗读文稿,写在文本里的指令可能会被读出来。
Gemini 3.8 Flash TTS 提供哪些音色?
共有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。单人模式默认 Kore。
Gemini 3.8 Flash TTS 如何处理语言?
Gemini 3.8 Flash TTS 会在130种语言中根据文稿自动识别语言。请用目标语言书写文稿,无需单独设置语言。
Gemini 3.8 Flash TTS 和 Gemini 3.8 Flash Lite TTS 该选哪个?
更看重演绎细节、方言和复杂对话时选择 Gemini 3.8 Flash TTS,Google 将其定位为旗舰创意档位,覆盖130种语言。Gemini 3.8 Flash Lite TTS 覆盖101种语言,每千字符6 credits,适合大批量任务。两者字段相同。
Gemini 3.8 Flash TTS 返回什么音频格式?
每个完成的任务会在 files 中返回一个 WAV 文件。如播放器或平台需要压缩格式,请在音频工具中转换为 MP3 或 Opus。
Gemini 3.8 Flash TTS 如何统计计费字符?
计费包括 Text、Style Instructions,以及对话中每条台词的 text 和 style_instructions,每1,000字符9 credits($0.045)。speaker_id 不计入。


