音訊

GetRouter 提供三種 OpenAI 相容的音訊操作:

操作端點
轉錄POST /v1/audio/transcriptions
翻譯POST /v1/audio/translations
文字轉語音POST /v1/audio/speech

請使用支援所需音訊操作的模型。

轉錄音訊

以 multipart 表單資料上傳來源檔案:

curl https://getrouter.ai/v1/audio/transcriptions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "[email protected]" \
  -F "model=MODEL_ID" \
  -F "response_format=json"

JSON 回應的逐字稿位於 text

API 結構描述中的選填轉錄欄位包括:

  • language — ISO-639-1 語言代碼
  • prompt — 上下文或詞彙提示
  • response_formatjsontextsrtverbose_jsonvtt
  • temperature
  • timestamp_granularitieswordsegment

選填欄位的支援情況取決於所選模型。

翻譯音訊

curl https://getrouter.ai/v1/audio/translations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "[email protected]" \
  -F "model=MODEL_ID" \
  -F "response_format=json"

回應採用與轉錄相同的基本 text 結構。

生成語音

curl https://getrouter.ai/v1/audio/speech \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_ID",
    "input": "GetRouter 將您的應用程式連接至多種 AI 模型。",
    "voice": "alloy",
    "response_format": "mp3"
  }' \
  --output speech.mp3

語音請求結構描述包含:

欄位說明
model必填的語音模型 ID
input必填的待合成文字
voice必填且模型支援的聲音
response_formatmp3opusaacflacwavpcm
speed相容模型的播放速度

Python 轉錄範例

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://getrouter.ai/v1",
)

with open("recording.mp3", "rb") as audio_file:
    transcript = client.audio.transcriptions.create(
        model="MODEL_ID",
        file=audio_file,
    )

print(transcript.text)
Tip

音訊上傳及生成的檔案可能很大。請適當設定用戶端逾時,並串流傳輸檔案資料,避免將不必要的副本載入記憶體。

計費與重試

音訊費用可能取決於模型、輸入大小、長度或生成的輸出。請查看 Pricing。重試前,請先判斷伺服器是否已完成請求,而只是檔案下載失敗。

後續步驟