Skip to main content
POST
Python
使用此端点可通过兼容 OpenAI 的音频 API 将文本转换为音频文件。它适用于旁白、简短语音提示、朗读功能,以及其他你的应用已经有文本并需要语音输出的工作流。

首次请求

从三个字段开始:modelinputvoice。保持首次请求简短,这样你就可以在调整速度或输出格式之前,先验证认证、音频格式和文件处理是否正常。

读取响应

响应是二进制音频,而不是 JSON。在 SDK 示例中,将响应写入文件,例如 output.mp3。在直接使用 HTTP 客户端时,保存响应体,并将文件扩展名设置为与你请求的 response_format 一致。

后续步骤

  • 当你需要将语音转换回文本时,请使用 创建转录
  • 当你需要从非英语音频中获取英文文本时,请使用 创建翻译

授权

Authorization
string
header
必填

Bearer token authentication. Use your CometAPI key.

请求体

application/json
model
string
默认值:tts-1
必填

The TTS model to use. Choose a current speech model from the Models page.

input
string
必填

The text to generate audio for. Maximum length is 4096 characters.

Maximum string length: 4096
voice
enum<string>
默认值:alloy
必填

The voice to use for speech synthesis.

可用选项:
alloy,
ash,
ballad,
coral,
echo,
fable,
onyx,
nova,
sage,
shimmer
response_format
enum<string>
默认值:mp3

The audio output format.

可用选项:
mp3,
opus,
aac,
flac,
wav,
pcm
speed
number
默认值:1

The speed of the generated audio. Select a value between 0.25 and 4.0.

必填范围: 0.25 <= x <= 4

响应

200 - audio/mpeg

The audio file content.

The response is of type file.