Audio API
文本转语音
通过 OpenAI speech 端点调用 ElevenLabs、OpenAI TTS 和 Gemini TTS。音乐模型也在此提供。
POSThttps://api.oxyy.ai/v1/audio/speech返回音频字节
参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| model | string | 必填 | 文本转语音或音乐 model id。 |
| 输入 | string | 必填 | 要朗读的文本。最多 4,096 个字符。 |
| voice | string | 必填 | 用于发音的声音。OpenAI 的声音名称(alloy、echo、fable、onyx、nova、shimmer)适用于 OpenAI 和 Gemini 模型。对于其他模型,请使用为该模型列出的声音之一(在 GET /v1/models 的 options.voices 中),或者在 ElevenLabs 模型上使用 20 个字符的 ElevenLabs voice id。音乐和声音模型不需要声音。 |
| response_format | string | 可选 | 音频容器。 以下之一:mp3opusaacflacwavpcm 默认 mp3 |
| speed | number | 可选 | 播放速度,0.25–4。 默认 1 |
| 说明 | string | 可选 | 支持该功能的模型的声音输出方向(例如 gpt-4o-mini-tts)。 |
| stream_format | string | 可选 | 以下之一:sseaudio |
| async | boolean | 可选 | 返回作业而不等待 — 适用于长输入。轮询 GET /v1/audio/speech/{id}。 默认 false |
| user | string | 可选 | 你自己的最终用户的稳定 ID。 |
代码示例
import os from pathlib import Path from openai import OpenAI client = OpenAI( api_key=os.environ["OXYY_API_KEY"], base_url="https://api.oxyy.ai/v1" ) with client.audio.speech.with_streaming_response.create( model="gemini-3.1-flash-tts-preview", voice="alloy", input="Hello! This is a text-to-speech test.", response_format="mp3", speed=1.0, ) as response: response.stream_to_file(Path("output.mp3"))
# The body is raw audio bytes — write it straight to a file. curl https://api.oxyy.ai/v1/audio/speech \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OXYY_API_KEY" \ -d '{ "model": "gemini-3.1-flash-tts-preview", "voice": "alloy", "input": "Hello from Oxyy.", "response_format": "mp3" }' \ --output speech.mp3
响应
audio/mpeg
// The response body is raw audio bytes, not JSON. // // HTTP/1.1 200 OK // Content-Type: audio/mpeg // Content-Length: 45321 // X-Request-Id: 8f2c... // // Write it straight to a file or pipe it to a player. // response_format picks the container: mp3, opus, aac, flac, wav, pcm.
可用模型
28 models
模型
Model ID
