通用开放接口音频 API
POST /v1/audio/speech
POST
/v1/audio/speech文本转语音(TTS)。
鉴权:Bearer Token
Content-Type:application/json
请求体
{ "model": "tts-1", "input": "Hello, welcome to YunSell AI 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 YunSell AI text-to-speech service.", "voice": "alloy", "response_format": "mp3", "speed": 1.0 }' \ -o speech.mp3CosyVoice 模型:
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 OKContent-Type: audio/mpegContent-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" }}