Speech (Text-to-Speech)
将文本转换为音频,兼容 OpenAI Audio Speech API。
POST https://api.wrouter.io/v1/audio/speech请求体
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | ✓ | 如 tts-1、tts-1-hd、gpt-4o-mini-tts、cosyvoice-v1 |
input | string | ✓ | 待合成文本,<= 4096 字符 |
voice | string | ✓ | 如 alloy、echo、fable、onyx、nova、shimmer,或厂商专属 voice |
response_format | string | mp3(默认)、opus、aac、flac、wav、pcm | |
speed | number | 语速,0.25 ~ 4.0,默认 1.0 |
响应
直接返回音频二进制流,Content-Type 为 audio/mpeg 等。
示例
bash
curl https://api.wrouter.io/v1/audio/speech \
-H "Authorization: Bearer $WROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "你好,我是 wrouter 的语音助手。",
"voice": "nova"
}' --output hello.mp3python
from pathlib import Path
from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://api.wrouter.io/v1")
resp = client.audio.speech.create(
model="tts-1-hd",
voice="alloy",
input="欢迎使用 wrouter 文字转语音。",
)
Path("welcome.mp3").write_bytes(resp.content)