使用已有的语音模型将文本转换为语音
POST /api/open/tts
// JSON 格式 Content-Type: application/json Authorization: Bearer YOUR_API_TOKEN // API密钥 // MessagePack 格式 Content-Type: application/msgpack Authorization: Bearer YOUR_API_TOKEN // API密钥
{
"reference_id": string, // 必填,声音模型ID
"text": string, // 必填,要转换的文本
"speed": number, // 可选,语速,范围:0.5-2.0,默认:1
"volume": number, // 可选,音量,范围:-20-20,默认:0
"version": string, // 可选,TTS版本。可选值:"v1"、"v2"、"s1"(传统版本),"v3-turbo"、"v3-hd"(V3版本),默认:"v1"
"format": string, // 可选,音频格式,可选值:"mp3"、"wav"、"pcm",默认:"mp3"
"emotion": string, // 可选,情绪控制(仅V3版本支持),可选值:"happy"、"sad"、"angry"、"fearful"、"disgusted"、"surprised"、"calm"、"fluent"、"auto",默认:"auto"
"cache": boolean // 可选,是否缓存音频并返回URL,默认:false
}// 成功响应 (cache=false) - 200
Content-Type: audio/mpeg
<二进制音频数据>
// 成功响应 (cache=true) - 200
Content-Type: application/json
{
"success": boolean, // 是否成功
"audio_url": string, // 音频文件URL
"format": string, // 音频格式
"characters_used": number, // 使用的字符数
"quota_remaining": number // 剩余API积分
}
// 错误响应
{
"error": string // 错误提示信息
}# JSON 格式 - 传统版本(使用 s1 版本,推荐)
curl -X POST https://fishaudio.net/api/open/tts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
"reference_id": "your_model_id",
"text": "要转换的文本内容",
"speed": 1.0,
"volume": 0,
"version": "s1",
"format": "mp3",
"cache": false
}' \
--output output.mp3
# JSON 格式 - V3 模型(使用 HD 版本)
curl -X POST https://fishaudio.net/api/open/tts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
"reference_id": "your_model_id",
"text": "要转换的文本内容",
"speed": 1.0,
"volume": 0,
"version": "v3-hd",
"emotion": "happy",
"format": "mp3",
"cache": false
}' \
--output output.mp3
# 支持的音频格式:mp3, wav, pcm
# 支持的TTS版本:v1, v2, s1(传统版本),v3-turbo, v3-hd(V3版本)
# V3版本支持的情绪控制:happy, sad, angry, fearful, disgusted, surprised, calm, fluent, auto
# 根据选择的格式,输出文件扩展名应相应更改
# MessagePack 格式 (需要使用支持 MessagePack 的客户端库)状态码说明:
200 OK - 请求成功
400 Bad Request - 请求参数错误
401 Unauthorized - API Token 无效
403 Forbidden - 禁止访问
404 Not Found - 资源不存在
413 Payload Too Large - 上传文件过大
429 Too Many Requests - 请求频率超限/积分不足
500 Server Error - 服务器内部错误
错误响应格式:
{
"error": string, // 错误信息
"details": string, // 详细错误信息(可选)
"code": string // 错误代码(可选)
}