Skip to content

语音合成 TTS

POST /api/v1/audio/speech
Authorization: Bearer sk-xxx
Content-Type: application/json

将文本转换为语音音频,返回二进制音频流。

流式实时场景

如需边输入文本边输出音频(对话播报、长文本、低延迟场景),请使用 实时语音合成(WebSocket)

Request

字段类型必填说明
modelstring*模型 ID,如 tts-1tts-1-hd
inputstring*要转换的文本内容
voicestring*语音角色,如 alloyechofableonyxnovashimmer
response_formatstring可选音频格式:mp3(默认)/ opus / aac / flac / wav / pcm
speednumber可选语速,0.25 ~ 4.0,默认 1.0

请求示例:

json
{
  "model": "tts-1",
  "input": "你好,欢迎使用 LimAPI 语音合成服务",
  "voice": "alloy"
}

Response

返回二进制音频数据,Content-Type 为对应的音频格式 MIME 类型。

bash
curl https://limapi.com/api/v1/audio/speech \
  -H "Authorization: Bearer sk-xxx" \
  -H "Content-Type: application/json" \
  -d '{"model":"tts-1","input":"你好","voice":"alloy"}' \
  --output speech.mp3

Python 示例

python
from openai import OpenAI

client = OpenAI(
    base_url="https://limapi.com/api/v1",
    api_key="sk-xxx",
)

with client.audio.speech.with_streaming_response.create(
    model="tts-1",
    voice="alloy",
    input="你好,欢迎使用 LimAPI 语音合成服务",
) as response:
    response.stream_to_file("speech.mp3")

LimAPI — 大模型聚合网关