外观
文本转语音
POST
https://vip.zen-ai.top/v1/audio/speech将文本合成为自然语音,响应体是音频文件的二进制内容。
请求体
modelstring必填模型名称,如 gpt-4o-mini-tts、tts-1、tts-1-hd。
inputstring必填要合成的文本,最长 4096 个字符。
voicestring必填音色。tts-1 系列支持的音色较少,建议使用 alloy、echo、fable、onyx、nova、shimmer。
可选值
alloyashballadcoralechofablenovaonyxsageshimmerverseinstructionsstring语气、情感、语速等风格描述,仅 gpt-4o-mini-tts 支持。
response_formatstring默认 mp3音频格式。
可选值
mp3opusaacflacwavpcmspeednumber默认 1语速,0.25–4.0。
响应
音频二进制内容,Content-Type 与 response_format 对应(如 audio/mpeg)。
请求示例
bash
curl https://vip.zen-ai.top/v1/audio/speech \
-H "Authorization: Bearer $VIP_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "你好,欢迎使用语音合成服务。",
"voice": "coral"
}' \
--output speech.mp3python
from openai import OpenAI
client = OpenAI(base_url="https://vip.zen-ai.top/v1", api_key="sk-xxxxxxxx")
with client.audio.speech.with_streaming_response.create(
model="gpt-4o-mini-tts",
voice="coral",
input="你好,欢迎使用语音合成服务。",
instructions="语气温暖亲切,语速稍慢。",
) as response:
response.stream_to_file("speech.mp3")js
import OpenAI from "openai";
import { writeFile } from "node:fs/promises";
const client = new OpenAI({ baseURL: "https://vip.zen-ai.top/v1", apiKey: process.env.VIP_API_KEY });
const speech = await client.audio.speech.create({
model: "gpt-4o-mini-tts",
voice: "coral",
input: "你好,欢迎使用语音合成服务。",
});
await writeFile("speech.mp3", Buffer.from(await speech.arrayBuffer()));Gemini 语音合成
Gemini TTS 模型(如 gemini-2.5-flash-preview-tts、gemini-3.1-flash-tts-preview)通过 Gemini 原生接口 调用,返回 24kHz 单声道 16 位 PCM 数据(base64),需要自行封装为 WAV:
python
import base64
import wave
import requests
resp = requests.post(
"https://vip.zen-ai.top/v1beta/models/gemini-2.5-flash-preview-tts:generateContent",
headers={"x-goog-api-key": "sk-xxxxxxxx"},
json={
"contents": [{"parts": [{"text": "用开心的语气说:今天是个好日子!"}]}],
"generationConfig": {
"responseModalities": ["AUDIO"],
"speechConfig": {"voiceConfig": {"prebuiltVoiceConfig": {"voiceName": "Kore"}}},
},
},
timeout=300,
).json()
pcm = base64.b64decode(resp["candidates"][0]["content"]["parts"][0]["inlineData"]["data"])
with wave.open("gemini_tts.wav", "wb") as wf:
wf.setnchannels(1)
wf.setsampwidth(2)
wf.setframerate(24000)
wf.writeframes(pcm)在 Gemini 原生接口页面使用在线调试时,返回的 PCM 音频会自动转换为可播放的 WAV。