音频 API
文本转语音(TTS)与音色列表查询
音频接口提供文本转语音(TTS)与音色查询能力。
接口一览
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /v1/audio/voice/{model} | 获取指定 TTS 模型的音色列表 |
| POST | /v1/audio/speech | 文本转语音(TTS) |
推荐调用顺序:先调用音色列表接口获取 data[].code,再传入 TTS 请求的 voice 字段。
GET /v1/audio/voice/{model}
获取指定 TTS 模型的可用音色列表。
鉴权:Bearer Token
Path 参数:model — TTS 模型名,如 tts-1、cosyvoice-v3-flash
请求:无请求体
请求示例(curl)
curl https://www.yunsell.com/v1/audio/voice/cosyvoice-v3-flash \
-H "Authorization: Bearer sk-xxx"
响应体
HTTP 200
{
"success": true,
"object": "list",
"data": [
{
"name": "龙小淳",
"code": "longxiaochun"
},
{
"name": "Cherry",
"code": "Cherry"
}
]
}
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
success | boolean | 是否成功 |
object | string | 固定为 list |
data | array | 音色列表 |
data[].name | string | 音色展示名称 |
data[].code | string | 音色代码,TTS 请求中传入 voice 字段 |
无可用音色时:
{
"success": true,
"object": "list",
"data": []
}
失败响应
HTTP 400
{
"success": false,
"message": "model is required"
}
| 字段 | 类型 | 说明 |
|---|---|---|
success | boolean | 固定为 false |
message | string | 失败原因 |
说明:
- 渠道音色:
name与code相同,来自渠道配置 - 平台音色库:
name为展示名,code为voice_key;若模型支持用户私有音色,会一并返回
POST /v1/audio/speech
文本转语音(TTS)。
鉴权:Bearer Token
Content-Type:application/json
请求体
{
"model": "tts-1",
"input": "Hello, welcome to 云擎数智 text-to-speech service.",
"voice": "alloy",
"response_format": "mp3",
"speed": 1.0
}
请求字段
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | TTS 模型,如 tts-1、cosyvoice-v3-flash |
input | string | 是 | 待合成文本 |
voice | string | 是 | 音色代码(见上文音色列表) |
response_format | string | 否 | 输出格式:mp3(默认)、opus、aac、flac、wav、pcm |
speed | number | 否 | 语速,0.25–4.0,默认 1.0 |
CosyVoice 模型示例:
{
"model": "cosyvoice-v3-flash",
"input": "你好,欢迎使用语音合成服务。",
"voice": "longxiaochun",
"response_format": "mp3",
"speed": 1.0
}
请求示例(curl)
curl https://www.yunsell.com/v1/audio/speech \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "Hello, welcome to 云擎数智 text-to-speech service.",
"voice": "alloy",
"response_format": "mp3",
"speed": 1.0
}' \
-o speech.mp3
CosyVoice 模型:
curl https://www.yunsell.com/v1/audio/speech \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "cosyvoice-v3-flash",
"input": "你好,欢迎使用语音合成服务。",
"voice": "longxiaochun",
"response_format": "mp3",
"speed": 1.0
}' \
-o speech.mp3
响应体
HTTP 200
- Content-Type:
audio/mpeg(mp3)或对应格式 MIME - Body:音频二进制流(非 JSON)
响应 Header 示例:
HTTP/1.1 200 OK
Content-Type: audio/mpeg
Content-Length: 45632
响应说明
| 项 | 说明 |
|---|---|
| HTTP 状态码 | 200 |
| Content-Type | 由 response_format 决定,见下表 |
| 响应体 | 音频二进制流,非 JSON |
response_format 与 Content-Type 对应关系
response_format | Content-Type |
|---|---|
mp3(默认) | audio/mpeg |
opus | audio/opus |
aac | audio/aac |
flac | audio/flac |
wav | audio/wav |
pcm | audio/pcm |
失败响应
HTTP 400,格式见 标准错误。
{
"error": {
"message": "voice is required",
"type": "invalid_request_error",
"code": "invalid_request"
}
}

