Skip to content

Speech (Text-to-Speech)

將文本轉換為音訊,採用通用 Speech 協議格式。

POST https://wrouter.ai/v1/audio/speech

請求體

引數型別必填說明
modelstringtts-1tts-1-hdgpt-4o-mini-ttscosyvoice-v1
inputstring待合成文本,<= 4096 字元
voicestringalloyechofableonyxnovashimmer,或廠商專屬 voice
response_formatstringmp3(預設)、opusaacflacwavpcm
speednumber語速,0.25 ~ 4.0,預設 1.0

響應

直接返回音訊二進位制流,Content-Typeaudio/mpeg 等。

示例

bash
curl https://wrouter.ai/v1/audio/speech \
  -H "Authorization: Bearer $WROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tts-1",
    "input": "你好,我是 WRouter 的語音助手。",
    "voice": "nova"
  }' --output hello.mp3
python
from pathlib import Path
from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://wrouter.ai/v1")

resp = client.audio.speech.create(
    model="tts-1-hd",
    voice="alloy",
    input="歡迎使用 WRouter 文字轉語音。",
)
Path("welcome.mp3").write_bytes(resp.content)