介紹

文字轉語音(TTS)API 基於先進的生成 AI 模型,可以將輸入的文字轉換為逼真的語音音頻。支援多種用途:
  • 為書面部落格文章配音
  • 生成多種語言的語音音頻
  • 提供即時音頻輸出串流
可用模型列表:
  • gpt-4o-audio-preview —— OpenAI 最新的音頻生成模型,支援對話式音頻生成
  • gpt-4o-mini-tts —— 智慧即時應用的首選模型,支援進階語音控制,可以透過提示詞控制多種語音特性:
    • 口音 (Accent)
    • 情感範圍 (Emotional range)
    • 語調 (Intonation)
    • 印象/風格 (Impressions)
    • 語速 (Speed of speech)
    • 語調 (Tone)
    • 輕聲說話 (Whispering)
  • tts-1-hd —— 高清音質的上一代 TTS 模型
  • tts-1 —— 標準 TTS 模型,平衡品質和速度
效能建議: 為獲得最快的響應時間,建議使用 wavpcm 作為響應格式。對於高品質音頻,建議使用 tts-1-hd;對於更快的生成速度,使用 tts-1;對於智慧語音應用,推薦使用 gpt-4o-mini-tts音色預覽: 你可以在 OpenAI.fm 試聽不同音色效果。

模型調用方式

標準 TTS 模型(tts-1, tts-1-hd)

使用 /v1/audio/speech 端點,透過 client.audio.speech.create() 方法調用。

gpt-4o-mini-tts 模型

使用 /v1/audio/speech 端點,支援 instructions 參數進行進階語音控制。

gpt-4o-audio-preview 模型

使用 /v1/chat/completions 端點,需要設定 modalities: ["text", "audio"]audio 配置。

請求參數

標準 TTS 參數(適用於 tts-1, tts-1-hd, gpt-4o-mini-tts)

model
string
required
要使用的模型 ID。可選值:tts-1tts-1-hdgpt-4o-mini-tts
input
string
required
要生成音頻的文字,最大長度為 4096 個字元
voice
string
required
用於合成的語音。可選值:alloyechofableonyxnovashimmer
response_format
string
音頻輸出格式。支援格式:mp3opusaacflacwavpcm。預設為 mp3
speed
number
生成音頻的語速。取值範圍 0.25 到 4.0。預設為 1.0。注意:gpt-4o-mini-tts 不支援此參數,但你可以透過自然語言描述來控制語速
instructions
string
語音生成指令(僅適用於 gpt-4o-mini-tts 模型),可以詳細指定語音風格、語調、情感等特性

gpt-4o-audio-preview 參數

model
string
required
設定為 gpt-4o-audio-preview
modalities
array
required
設定為 ["text", "audio"] 啟用音頻輸出
audio
object
required
音頻配置物件,包含 voiceformat 欄位
messages
array
required
聊天訊息陣列,與標準聊天格式相同

使用方法

curl https://aihubmix.com/v1/audio/speech \
  -H "Authorization: Bearer $AIHUBMIX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tts-1",
    "input": "The quick brown 🦊 jumped over the lazy dog.",
    "voice": "alloy"
  }' \
  --output speech.mp3