Skip to main content
POST
Python
使用此端點可透過與 OpenAI 相容的音訊 API,將文字轉換為音訊檔案。它適合用於旁白、簡短語音提示、朗讀功能,以及其他你的應用程式已經有文字內容且需要語音輸出的工作流程。

First request

先從三個欄位開始:modelinputvoice。請讓第一次請求保持簡短,以便在調整速度或輸出格式之前,先驗證驗證資訊、音訊格式與檔案處理。

Read the response

回應是二進位音訊,而非 JSON。在 SDK 範例中,請將回應寫入檔案,例如 output.mp3。在直接使用 HTTP 用戶端時,請儲存回應主體,並將副檔名設為與請求的 response_format 相符。

Next steps

  • 當你需要將語音轉回文字時,請使用 建立轉錄
  • 當你需要從非英文音訊取得英文文字時,請使用 建立翻譯

授權

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.