---
url: https://limapi.com/docs/guide/tts.md
---
# 语音合成 TTS

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

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

::: tip 流式实时场景
如需边输入文本边输出音频（对话播报、长文本、低延迟场景），请使用 [实时语音合成（WebSocket）](/guide/realtime-tts)。
:::

## Request

| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| model | string | \* | 模型 ID，如 `tts-1`、`tts-1-hd` |
| input | string | \* | 要转换的文本内容 |
| voice | string | \* | 语音角色，如 `alloy`、`echo`、`fable`、`onyx`、`nova`、`shimmer` |
| response\_format | string | 可选 | 音频格式：`mp3`（默认）/ `opus` / `aac` / `flac` / `wav` / `pcm` |
| speed | number | 可选 | 语速，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")
```
