音频模型
创建语音
使用 CometAPI POST /v1/audio/speech,通过选定的文本转语音模型和输出格式将文本转换为音频。
POST
Python
使用此端点可通过兼容 OpenAI 的音频 API 将文本转换为音频文件。它适用于旁白、简短语音提示、朗读功能,以及其他你的应用已经有文本并需要语音输出的工作流。
首次请求
从三个字段开始:model、input 和 voice。保持首次请求简短,这样你就可以在调整速度或输出格式之前,先验证认证、音频格式和文件处理是否正常。
读取响应
响应是二进制音频,而不是 JSON。在 SDK 示例中,将响应写入文件,例如output.mp3。在直接使用 HTTP 客户端时,保存响应体,并将文件扩展名设置为与你请求的 response_format 一致。
后续步骤
授权
Bearer token authentication. Use your CometAPI key.
请求体
application/json
The TTS model to use. Choose a current speech model from the Models page.
The text to generate audio for. Maximum length is 4096 characters.
Maximum string length:
4096The voice to use for speech synthesis.
可用选项:
alloy, ash, ballad, coral, echo, fable, onyx, nova, sage, shimmer The audio output format.
可用选项:
mp3, opus, aac, flac, wav, pcm 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.