文本转语音(TTS)
OpenAI 兼容
文本转语音(TTS)
POST /v1/audio/speech —— 把文本合成为语音
POST
文本转语音(TTS)
把文本合成为自然语音。
请求
参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | ✅ | tts-1 / tts-1-hd / gpt-4o-mini-tts |
input | string | ✅ | 待合成文本(最长 4096 字符) |
voice | string | ✅ | 音色:alloy / echo / fable / onyx / nova / shimmer / coral / verse 等 |
response_format | string | mp3(默认) / opus / aac / flac / wav / pcm | |
speed | number | 0.25 - 4.0(默认 1.0) | |
instructions | string | gpt-4o-mini-tts 专属,可对语气 / 风格描述 |
响应
直接返回 二进制音频流,Content-Type 与所选 response_format 对应:
| response_format | Content-Type |
|---|---|
mp3 | audio/mpeg |
opus | audio/ogg |
aac | audio/aac |
flac | audio/flac |
wav | audio/wav |
pcm | audio/pcm |
Python 示例
gpt-4o-mini-tts 进阶
新一代 TTS 支持通过instructions 控制语气: