跳轉到主要內容
ARouter 提供三種模式的全面音訊支援:語音轉文字(轉錄和翻譯)、文字轉語音(TTS)以及音訊對話(接受音訊輸入並產生語音輸出的多模態模型)。

音訊轉錄

使用與 OpenAI 相容的 /v1/audio/transcriptions 端點將音訊檔案轉錄為文字。
curl https://api.arouter.ai/v1/audio/transcriptions \
  -H "Authorization: Bearer lr_live_xxxx" \
  -F file="@audio.mp3" \
  -F model="openai/whisper-large-v3"
from openai import OpenAI
client = OpenAI(base_url="https://api.arouter.ai/v1", api_key="lr_live_xxxx")
with open("audio.mp3", "rb") as audio_file:
    transcription = client.audio.transcriptions.create(
        model="openai/whisper-large-v3", file=audio_file, response_format="text"
    )
print(transcription.text)

轉錄參數

參數類型描述
filefile要轉錄的音訊檔案。支援格式:flacmp3mp4mpegmpgam4aoggwavwebm
modelstring模型 ID,例如 openai/whisper-large-v3
languagestringBCP-47 語言代碼(如 "en""zh")。指定後可提高準確性。
promptstring可選文字,用於引導轉錄風格或提供詞彙提示
response_formatstring輸出格式:json(預設)、textsrtverbose_jsonvtt
temperaturenumber採樣溫度 0–1。值越高隨機性越大。
timestamp_granularitiesstring[]帶時間戳輸出的粒度:["word"]["segment"](需要 verbose_json

單詞級時間戳

transcription = client.audio.transcriptions.create(
    model="openai/whisper-large-v3", file=audio_file,
    response_format="verbose_json", timestamp_granularities=["word"]
)
for word in transcription.words:
    print(f"{word.start:.2f}s - {word.end:.2f}s: {word.word}")

音訊翻譯

將任意語言的音訊翻譯為英文文字:
with open("foreign_audio.mp3", "rb") as audio_file:
    translation = client.audio.translations.create(
        model="openai/whisper-large-v3", file=audio_file, response_format="text"
    )
print(translation.text)

文字轉語音

將文字轉換為自然語音:
response = client.audio.speech.create(
    model="openai/tts-1-hd", voice="nova",
    input="Hello! Welcome to ARouter, the universal AI gateway."
)
response.stream_to_file("output.mp3")

TTS 參數

參數類型描述
modelstringTTS 模型,例如 openai/tts-1openai/tts-1-hd
inputstring要合成的文字。最多 4,096 個字元。
voicestring使用的聲音:alloyechofableonyxnovashimmer
response_formatstring音訊格式:mp3(預設)、opusaacflacwavpcm
speednumber播放速度,範圍 0.254.0(預設 1.0

可用聲音

聲音特點
alloy中性、均衡
echo柔和、沉思
fable富有表現力、敘事感
onyx深沉、權威
nova友善、充滿活力
shimmer溫暖、溫柔

音訊對話(多模態模型)

部分模型直接接受音訊作為聊天訊息輸入,並能以語音音訊進行回覆。

音訊輸入

{
  "model": "openai/gpt-5.4-audio-preview",
  "messages": [{
    "role": "user",
    "content": [{"type": "input_audio", "input_audio": {"data": "<base64-encoded-audio>", "format": "wav"}}]
  }]
}

支援的輸入音訊格式

格式MIME 類型
wavaudio/wav
mp3audio/mpeg
oggaudio/ogg
flacaudio/flac
m4aaudio/m4a
webmaudio/webm

音訊輸出

在模型回應中請求語音音訊:
{
  "model": "openai/gpt-5.4-audio-preview",
  "modalities": ["text", "audio"],
  "audio": {"voice": "nova", "format": "mp3"},
  "messages": [{"role": "user", "content": "Tell me a short joke."}]
}

支援的模型

語音轉文字

模型語言備註
openai/whisper-large-v399+最佳準確性
openai/whisper-large-v3-turbo99+更快、成本更低

文字轉語音

模型品質延遲
openai/tts-1標準
openai/tts-1-hd

Token 定價

音訊 Token 在 usage.prompt_tokens_details 中單獨統計:
{
  "usage": {
    "prompt_tokens": 150,
    "prompt_tokens_details": {"audio_tokens": 100, "cached_tokens": 0},
    "completion_tokens": 50,
    "completion_tokens_details": {"audio_tokens": 30}
  }
}
音訊 Token 的定價與文字 Token 不同。請查看回應中的 usage.cost 了解每次請求的實際費用。