POST
创建语音(TTS)
POST /v1/audio/speech — 文本转语音
创建语音(TTS)
将文本转为自然语音音频,支持多种音色和格式,支持流式返回实现边读边播效果。
POST
https://api000.com/v1/audio/speech
响应为二进制音频数据流,Content-Type 为 audio/mpeg 等音频 MIME 类型。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string | 必填 | TTS 模型,如 tts-1(快速)、tts-1-hd(高质量) |
input |
string | 必填 | 要转换的文本,最多 4096 字符 |
voice |
string | 必填 | 音色名称(见下方列表) |
response_format |
string | 可选 | 音频格式:mp3(默认)、opus、aac、flac、wav、pcm |
speed |
number | 可选 | 语速,范围 0.25 ~ 4.0,默认 1.0 |
可用音色
| 音色 ID | 风格 |
|---|---|
alloy |
中性、专业,适合播报 |
echo |
男声、沉稳 |
fable |
带英式口音,叙述感强 |
onyx |
深沉男声,权威感 |
nova |
女声、活泼清晰(推荐中文) |
shimmer |
女声、温柔轻盈 |
请求示例
cURL
curl https://api000.com/v1/audio/speech \
-H "Authorization: Bearer sk-xxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "欢迎使用零度API,我们提供高性价比的 AI 推理服务。",
"voice": "nova",
"speed": 1.0
}' \
--output speech.mp3
echo "✅ 已保存为 speech.mp3"
Python(流式写入文件)
from pathlib import Path
from openai import OpenAI
client = OpenAI(
base_url="https://api000.com/v1",
api_key="sk-xxxxxxxxxxxxxxxx"
)
speech_file = Path("speech.mp3")
with client.audio.speech.with_streaming_response.create(
model="tts-1",
voice="nova",
input="欢迎使用零度API!我们支持 OpenAI、Claude、Gemini 等多种大模型。",
speed=1.0
) as response:
response.stream_to_file(speech_file)
print(f"✅ 语音已保存: {speech_file}")
Node.js
import OpenAI from "openai";
import fs from "fs";
import path from "path";
const client = new OpenAI({
baseURL: "https://api000.com/v1",
apiKey: "sk-xxxxxxxxxxxxxxxx",
});
const speechFile = path.resolve("./speech.mp3");
const mp3 = await client.audio.speech.create({
model: "tts-1",
voice: "nova",
input: "欢迎使用零度API!",
});
const buffer = Buffer.from(await mp3.arrayBuffer());
fs.writeFileSync(speechFile, buffer);
console.log("✅ 已保存为 speech.mp3");
模型对比
| 模型 | 特点 | 延迟 |
|---|---|---|
tts-1 |
速度快,适合实时交互 | 低 |
tts-1-hd |
音质更优,适合内容制作 | 稍高 |