语音TTS · 文字转语音(Live,异步)

语音TTS · 文字转语音(Live·异步)

WebSocket 流式服务,长文本异步合成;返回 task_id,由 fish_tts:worker 执行

<details>
<summary>基本信息</summary>

字段内容
类型应用 API
应用名称语音TTS
应用编码voice_tts
API 名称文字转语音(Live·异步)
API 编码tts_live
请求方式POST
请求路径/api/v1/apps/voice_tts/tts_live
调用模式异步

</details>

鉴权

Authorization: Bearer <YOUR_API_KEY>
Content-Type: application/json

请求路径

POST /api/v1/apps/voice_tts/tts_live

该接口为异步任务,提交后返回 task_id,请通过 GET /api/v1/tasks/{task_id} 查询结果,或在请求中传 callback_url 接收完成回调。

业务参数

参数类型必填默认值可选值 / 范围示例说明
textstring是———待合成文本(WebSocket 流式服务,适合长文本)
modelstring否—s1 / s2-pro—TTS 模型:s1 / s2-pro,默认 s2-pro
top_pnumber否———Top-P
formatstring否—wav / pcm / mp3 / opus—wav / pcm / mp3 / opus,默认 mp3
latencystring否—low / normal / balanced—low / normal / balanced
prosodyobject否———语调:speed、volume、normalize_loudness(仅 s2-pro)
normalizeboolean否———文本规范化,默认 true
mp3_bitrateinteger否—64 / 128 / 192—MP3 比特率:64 / 128 / 192
sample_rateinteger否———采样率
temperaturenumber否———生成温度
callback_urlstring否—GET / api / v1 / tasks—回调 URL;不传则 GET /api/v1/tasks/{task_id} 轮询
chunk_lengthinteger否—100 ~ 300—文本分块长度 100~300,默认 300
opus_bitrateinteger否———Opus 比特率
reference_idstring否———音色模型ID。单说话人传 string;多说话人可传 string[](仅 s2-pro)
max_new_tokensinteger否———每分块最大音频 token
min_chunk_lengthinteger否—0 ~ 100—最小分块长度 0~100
repetition_penaltynumber否———重复惩罚
early_stop_thresholdnumber否—0 ~ 1—提前停止阈值,0~1
condition_on_previous_chunksboolean否———是否利用前一段音频作为上下文

请求示例

{
    "text": "string",
    "model": "s1",
    "top_p": 1,
    "format": "wav",
    "latency": "low",
    "prosody": {},
    "normalize": true,
    "mp3_bitrate": "64",
    "sample_rate": 1,
    "temperature": 1,
    "callback_url": "GET",
    "chunk_length": 1,
    "opus_bitrate": 1,
    "reference_id": "string",
    "max_new_tokens": 1,
    "min_chunk_length": 1,
    "repetition_penalty": 1,
    "early_stop_threshold": 1,
    "condition_on_previous_chunks": true
}

成功响应

{
    "task_id": "tsk_xxxxxxxxxxxxxxxx",
    "status": "pending",
    "created_at": 1740000000
}

查询任务结果

GET /api/v1/tasks/{task_id}
{
    "task_id": "tsk_xxxxxxxxxxxxxxxx",
    "status": "completed",
    "created_at": 1740000000,
    "completed_at": 1740000060,
    "result": {
        "output": "任务输出内容"
    },
    "usage": {
        "points": 100
    }
}

失败响应

{
    "error": {
        "message": "点数余额不足",
        "type": "insufficient_points",
        "code": "insufficient_points"
    }
}

错误码

HTTPcode含义
400invalid_request参数缺失或格式错误
401auth_failedAPI Key 缺失或无效
402insufficient_points点数余额不足
402key_quota_exceeded当前 API Key 点数额度不足
403permission_denied当前 API Key 无权调用该模型/应用
404not_found模型 / 应用 / 任务不存在
429queue_limit_exceeded排队任务已达上限
5xxserver_error服务异常,请稍后重试

同类文章