前言
F5-TTS 异步语音合成接口分为两个步骤:
- 提交任务 - 提交合成请求,立即返回
request_id
- 查询结果 - 使用
request_id 轮询查询任务状态,完成后返回音频 URL
特点:
- 适合较长文本(≤2000字符)
- 提交即返回,不阻塞调用方
- 音频自动下载到本站服务器,永久有效
- 通过
request_id 轮询查询任务进度
一、提交任务
接口地址: POST https://www.yuntts.com/api/v1/f5-tts-async
请求 Headers
| Header |
值 |
必填 |
说明 |
Authorization |
Bearer {api_key} |
是 |
API 密钥,格式为 Bearer + 密钥 |
Content-Type |
application/json |
是 |
请求体格式 |
请求 Body
| 参数 |
类型 |
必填 |
默认值 |
说明 |
gen_text |
string |
是 |
- |
要合成的文本,汉字按2倍计费,异步模式≤2000字符 |
ref_audio_url |
string |
是 |
- |
参考音频 URL(用于音色克隆),必须是可公开访问的音频文件 |
ref_text |
string |
否 |
- |
参考音频对应的文本内容(可选,提供可提升克隆效果) |
model_type |
string |
否 |
F5-TTS |
模型类型,当前仅支持 F5-TTS |
请求示例
curl --location --request POST 'https://www.yuntts.com/api/v1/f5-tts-async'
--header 'Authorization: Bearer sk-your-api-key'
--header 'Content-Type: application/json'
--data-raw '{
"gen_text": "这是一段较长的测试文本,适用于异步合成模式,提交后可以立即获取任务ID,稍后再来查询合成结果。",
"ref_audio_url": "https://example.com/ref-speaker.wav",
"ref_text": "这是参考音频说的内容"
}'
响应
成功响应(200)
{
"code": 200,
"message": "任务提交成功",
"data": {
"request_id": "019e4446-94d6-7763-a19e-735c2c1be9c5",
"char_count": 46,
"cost": 0.01,
"status": "pending",
"queue_position": 0,
"message": "任务提交成功"
}
}
| 字段 |
类型 |
说明 |
request_id |
string |
302.AI 任务ID(用于后续查询结果) |
char_count |
int |
计费字符数(汉字×2计算) |
cost |
float |
实际扣费金额(元),最低0.001元 |
status |
string |
任务状态,初始为 pending |
queue_position |
int |
排队位置 |
message |
string |
结果消息 |
错误响应
{
"code": 400,
"error": "empty_text",
"message": "请输入要合成的文字"
}
| 错误代码 |
HTTP 状态码 |
说明 |
method_not_allowed |
405 |
仅支持 POST 请求 |
empty_text |
400 |
合成文本为空 |
missing_ref_audio |
400 |
参考音频 URL 为空 |
invalid_url |
400 |
参考音频 URL 格式无效 |
invalid_model |
400 |
不支持的模型类型 |
text_too_long |
400 |
文本超长(异步模式≤2000字符) |
insufficient_balance |
402 |
余额不足 |
api_error |
500 |
API 调用失败 |
二、查询结果
接口地址: POST https://www.yuntts.com/api/v1/f5-tts-status
请求 Headers
| Header |
值 |
必填 |
说明 |
Authorization |
Bearer {api_key} |
是 |
API 密钥,格式为 Bearer + 密钥 |
Content-Type |
application/json |
是 |
请求体格式 |
请求 Body
| 参数 |
类型 |
必填 |
说明 |
request_id |
string |
是 |
提交任务时返回的 request_id |
请求示例
curl --location --request POST 'https://www.yuntts.com/api/v1/f5-tts-status'
--header 'Authorization: Bearer sk-your-api-key'
--header 'Content-Type: application/json'
--data-raw '{
"request_id": "019e4446-94d6-7763-a19e-735c2c1be9c5"
}'
响应
处理中响应(200)
{
"code": 200,
"message": "任务正在处理中",
"data": {
"task_id": "019e4446-94d6-7763-a19e-735c2c1be9c5",
"status": "processing",
"message": "任务正在处理中"
}
}
完成响应(200)
{
"code": 200,
"message": "语音合成成功",
"data": {
"task_id": "019e4446-94d6-7763-a19e-735c2c1be9c5",
"status": "completed",
"char_count": 46,
"cost": 0.01,
"audio_url": "https://www.yuntts.com/wp-content/uploads/audio/processed/f5tts_async_xxx.wav",
"file_size": 291644,
"content_type": "application/octet-stream",
"message": "语音合成成功"
}
}
| 字段 |
类型 |
说明 |
task_id |
string |
302.AI 任务ID |
status |
string |
任务状态:processing(处理中)、completed(已完成) |
char_count |
int |
计费字符数(仅在 completed 时返回) |
cost |
float |
实际扣费金额(仅在 completed 时返回) |
audio_url |
string |
音频文件 URL,存储在本站服务器(仅在 completed 时返回) |
file_size |
int |
音频文件大小(字节,仅在 completed 时返回) |
content_type |
string |
音频 MIME 类型(仅在 completed 时返回) |
message |
string |
结果消息 |
错误响应
{
"code": 500,
"error": "task_failed",
"message": "任务处理失败"
}
| 错误代码 |
HTTP 状态码 |
说明 |
method_not_allowed |
405 |
仅支持 POST 请求 |
missing_request_id |
400 |
未提供 request_id |
task_failed |
500 |
任务处理失败 |
调用流程
sequenceDiagram
调用方->>+F5-TTS异步接口: POST /api/v1/f5-tts-async
F5-TTS异步接口-->>-调用方: { request_id, status: "pending" }
loop 轮询(建议间隔3-5秒)
调用方->>+F5-TTS状态接口: POST /api/v1/f5-tts-status
F5-TTS状态接口-->>-调用方: { status: "processing" }
end
调用方->>+F5-TTS状态接口: POST /api/v1/f5-tts-status
F5-TTS状态接口-->>-调用方: { status: "completed", audio_url }
计费说明
- 价格: ¥400/百万字符
- 计费方式: 汉字按2倍计数,其他字符按1倍计数
- 最低收费: 0.001 元
- 免费额度:
- BossVIP 用户:享有永久免费字符额度(后台配置)
- VIP 用户:享有月度免费字符额度(后台配置)
- 超出免费额度部分:BossVIP 8折、VIP 9折
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)