流式语音合成
流式合成语音并返回字词级时间戳对齐快照,适用于字幕、卡拉 OK 与时间轴编辑。
流式将文本合成为语音,并附带字词/短语级时间戳对齐,适用于卡拉 OK 高亮、同步字幕与时间轴编辑。
响应为 text/event-stream。每个 SSE message 包含一段 Base64 音频块,以及(在可用时)该 chunk_seq 的最新累计对齐快照。请按到达顺序拼接 audio_base64;同一 chunk_seq 的新快照应覆盖旧快照,不要追加分段。
Base URL
https://api.autorouter.top— Production
Authentication
BearerAuth: http (bearer)
使用 Bearer Token 认证。
格式: Authorization: Bearer sk-xxxxxx
Endpoints
POST /fishaudio/v1/tts/stream/with-timestamp
创建带时间戳的流式语音合成
请求头可设置 model:s1、s2-pro、s2.1-pro(默认)、s2.1-pro-free、drama-3-preview。多说话人对话仅 S2 系列与 drama-3-preview 支持,不支持 s1。
Request Body
Content-Type: application/json
Example:
{
"text": "Hello! Welcome to Fish Audio.",
"reference_id": "model-id",
"format": "opus",
"latency": "balanced"
}Properties:
| Name | Type | Required | Description |
|---|---|---|---|
text | string | Yes | 待合成文本。多说话人可用 <|speaker:0|>、<|speaker:1|> 标记切换 |
reference_id | string | string[] | null | No | 音色 ID。单说话人为字符串;多说话人为 ID 数组 |
references | object[] | No | 内联参考音频,用于零样本克隆。需 MessagePack,JSON 无法携带二进制 |
format | string | No | 输出格式:wav、pcm、mp3(默认)、opus。推荐 opus @ 48 kHz |
latency | string | No | 延迟与质量权衡:normal(默认,最佳质量)、balanced、low。balanced 下长文本可能拆成多个文本块 |
prosody | object | No | 语速与音量 |
chunk_length | integer | No | 文本分段长度,[100, 300],默认 300 |
normalize | boolean | No | 是否规范化中英文文本(提升数字朗读稳定性)。默认 true |
sample_rate | integer | null | No | 采样率(Hz)。null 时按格式默认:多数 44100,opus 48000 |
mp3_bitrate | integer | No | MP3 码率(kbps):64、128(默认)、192 |
opus_bitrate | integer | No | Opus 码率(bps)。-1000(默认,自动)、24000、32000、48000、64000 |
temperature | number | No | 表现力,[0, 1],默认 0.。越高越多样 |
top_p | number | No | nucleus sampling,[0, 1],默认 0. |
max_new_tokens | integer | No | 每个文本块最多生成的音频 token。默认 1024 |
repetition_penalty | number | No | 重复惩罚。大于 1. 减少重复。默认 1. |
min_chunk_length | integer | No | 拆分新块前的最少字符数,[0, 100],默认 50 |
condition_on_previous_chunks | boolean | No | 是否用前一段音频作为上下文以保持音色一致。默认 true |
pronunciation_dictionary | object[] | No | 最多 3 个发音词典(平台引用或内联,二者互斥) |
prosodyobject(可选)
语速与音量调整。
语速倍率,[0.5, 2.0]。1.0 为正常语速。
音量调整(dB)。0 不变,正值更响,负值更轻。
是否归一化响度。仅 s2-pro 与 S2.1-Pro 系列支持。
Responses
200: SSE 流
Content-Type: text/event-stream
401: 无权限
Content-Type: application/json
402: 余额不足
Content-Type: application/json
503: 服务过载
Content-Type: application/json
请求示例
curl --no-buffer -X POST "https://api.autorouter.top/fishaudio/v1/tts/stream/with-timestamp" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxxx" \
-H "model: s2-pro" \
-d '{
"text": "Hello! Welcome to Fish Audio.",
"reference_id": "model-id",
"format": "opus",
"latency": "balanced"
}'响应示例
{
"audio_base64": "SUQzBAAAAAAA...",
"content": "Hello world",
"chunk_seq": 0,
"chunk_audio_offset_sec": 0.0,
"alignment": {
"audio_duration": 0.86,
"segments": [
{
"text": "Hello",
"start": 0,
"end": 0.42
},
{
"text": "world",
"start": 0.42,
"end": 0.86
}
]
}
}响应字段说明:
| Name | Type | Description |
|---|---|---|
audio_base64 | string | 一段 Base64 音频块。按到达顺序拼接即可还原完整音频。这是传输块,不是句/词边界 |
content | string | 本事件最新对齐快照所描述的文本。长输入可拆成多个 content 块 |
alignment | object | null | 该 chunk_seq 的最新累计时间戳快照。有值时覆盖旧快照,不要追加。首个快照前或不可用时为 null |
alignment. | number | 该文本块生成音频的时长(秒) |
alignment. | object[] | 有序文本时间段 |
alignment. | string | 片段文本 |
alignment. | number | 相对该文本块音频起点的开始时间(秒) |
alignment. | number | 相对该文本块音频起点的结束时间(秒) |
chunk_seq | integer | 对齐所属文本块序号。按此值分桶保存快照 |
chunk_audio_offset_sec | number | 该文本块在完整音频中的绝对起点(秒)。加上 segment 的 start/end 得到全局时间轴 |
处理建议:
- 即使
alignment为null,也要按顺序拼接每个audio_base64。 - 用 map 以
chunk_seq为键保存对齐;每次非空alignment覆盖该键。 - 将 segment 本地时间加上
chunk_audio_offset_sec得到全局时间。
错误处理
HTTP 401 / 403 鉴权错误
401 Unauthorized:API Key 无效或已过期403 Forbidden:API Key 无权访问此模型(检查 token 的模型白名单)
HTTP 402 余额不足
返回 insufficient user quota。请前往 AutoRouter 控制台充值。
HTTP 503 服务过载
服务端负载过高,无法处理请求。请稍后重试。