音频输出

文本转语音 API

/v1/audio/speech 发送 JSON,并把二进制响应保存为音频文件。请根据控制能力、兼容性和计费单位选择模型。

线上请求已验证6 种输出格式二进制响应

选择 TTS 模型

模型适用场景输入限制核验价格
gpt-4o-mini-ttsinstructions 控制表达4,096 字符;模型上限 2,000 tokens文本输入 $0.60 / 1M tokens + 音频输出 $12 / 1M audio tokens
tts-1-hd传统高清 TTS 兼容4,096 字符$30 / 1M 字符

生成的声音是 AI 合成语音。对外发布或播放时,应向最终用户明确披露。

gpt-4o-mini-tts

instructions 可描述语气、速度、口音或情绪。响应是音频字节,因此 cURL 必须使用 --output

cURL · 生成 MP3
curl https://api-models.com/v1/audio/speech \
  -H "Authorization: Bearer $API_MODELS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini-tts",
    "input": "您的订单已经可以取货。",
    "voice": "marin",
    "instructions": "语气温暖,发音清晰,语速舒缓。",
    "response_format": "mp3",
    "speed": 1.0
  }' \
  --output speech.mp3
Python · requests
import os
import requests

response = requests.post(
    "https://api-models.com/v1/audio/speech",
    headers={"Authorization": f"Bearer {os.environ['API_MODELS_KEY']}"},
    json={
        "model": "gpt-4o-mini-tts",
        "input": "您的订单已经可以取货。",
        "voice": "marin",
        "instructions": "语气温暖,发音清晰,语速舒缓。",
        "response_format": "mp3",
    },
    timeout=120,
)
response.raise_for_status()
open("speech.mp3", "wb").write(response.content)
Node.js · fetch
import { writeFile } from "node:fs/promises";

const response = await fetch("https://api-models.com/v1/audio/speech", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.API_MODELS_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ model: "gpt-4o-mini-tts", input: "您的订单已经可以取货。", voice: "marin", instructions: "语气温暖,发音清晰。", response_format: "mp3" }),
});
if (!response.ok) throw new Error(await response.text());
await writeFile("speech.mp3", Buffer.from(await response.arrayBuffer()));

tts-1-hd

使用相同端点,但不要传 instructions。当前上游建议使用兼容音色 alloyechofableonyxnovashimmer;其中 novaalloy 已做线上请求验证。

cURL · 输出 WAV
curl https://api-models.com/v1/audio/speech \
  -H "Authorization: Bearer $API_MODELS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"tts-1-hd","input":"高清兼容语音示例。","voice":"nova","response_format":"wav","speed":0.9}' \
  --output speech.wav

参数与输出格式

字段要求说明
model必填两个精确模型 ID 之一
input必填最多 4,096 字符
voice必填必须与所选模型兼容
instructions仅 gpt-4o-mini-ttstts-1-hd 不支持
response_format可选mp3opusaacflacwavpcm
speed可选0.25–4.0,默认 1.0

当前网关只公开普通二进制响应。不要添加 stream_format=sse,它不在已验证的兼容范围内。

常见问题

现象处理
提示聊天接口错误改用 /v1/audio/speech
音频为空或损坏按二进制保存,写文件前检查 HTTP 状态
音色不兼容tts-1-hd 使用上文列出的兼容音色
instructions 被拒绝从 tts-1-hd 请求中移除