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

将文本异步合成为语音音频文件(适合长文本),通过回调或轮询获取结果

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

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

</details>

鉴权

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

请求路径

POST /api/v1/apps/voice_tts/tts_async

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

业务参数

参数类型必填默认值可选值 / 范围示例说明
textstring是———待合成文本,适合长文本(最大约 10000 字符)
modelstring否—s1 / s2-pro—TTS 模型,可选 s1 / s2-pro,默认 s2-pro
top_pnumber否—0 ~ 1—Top-P 采样,0~1,默认 0.7
formatstring否—wav / pcm / mp3 / opus—输出格式:wav / pcm / mp3 / opus,默认 mp3
latencystring否—low / normal / balanced—延迟模式:low / normal / balanced
prosodyobject否———语调控制对象:speed、volume、normalize_loudness
normalizeboolean否———文本规范化,默认 true
mp3_bitrateinteger否—64 / 128 / 192—MP3 比特率:64 / 128 / 192
sample_rateinteger否———采样率按格式限制
temperaturenumber否—0 ~ 1—生成温度,0~1,默认 0.7
callback_urlstring否———回调通知URL;不传则通过任务接口轮询
chunk_lengthinteger否—100 ~ 300—文本分块长度,范围 100~300,默认 300
opus_bitrateinteger否—-1000 / 24 / 32 / 48 / 64—Opus 比特率:-1000 / 24 / 32 / 48 / 64
reference_idstring否———音色模型ID。单说话人传 string;多说话人模式可传 string[](仅 s2-pro)
max_new_tokensinteger否———每个分块最多生成音频 token,默认 1024
min_chunk_lengthinteger否—0 ~ 100—最小分块长度,范围 0~100,默认 50
repetition_penaltynumber否———重复惩罚,默认 1.2
early_stop_thresholdnumber否—0 ~ 1—提前停止阈值,范围 0~1,默认 1
condition_on_previous_chunksboolean否———是否利用前一段音频作为上下文,默认 true

请求示例

{
    "text": "string",
    "model": "s1",
    "top_p": 1,
    "format": "wav",
    "latency": "low",
    "prosody": {},
    "normalize": true,
    "mp3_bitrate": "64",
    "sample_rate": 1,
    "temperature": 1,
    "callback_url": "string",
    "chunk_length": 1,
    "opus_bitrate": "-1000",
    "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服务异常,请稍后重试

同类文章