跳轉到主要內容
POST
Python
使用此端點透過相容 OpenAI 的音訊 API 將文字轉換為音訊檔案。這適用於旁白、簡短語音提示、朗讀功能,以及應用程式已有文字並需要語音輸出的其他工作流程。

第一個請求

先使用三個欄位:model、input 和 voice。第一個請求應保持簡短,讓你在調整速度或輸出格式之前,可以先驗證驗證方式、音訊格式和檔案處理。

讀取回應

回應是二進位音訊,而非 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.

最後修改於 2026年11月14日