音訊
Markdown採用 OpenAI Audio 格式的文字轉語音(TTS)與語音辨識(STT)。
完整指南
https://api.ailoot.ai/v1/audio/speech# 語音合成
curl https://api.ailoot.ai/v1/audio/speech \
-H "Authorization: Bearer $AILOOT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "qwen-audio-3.0-tts-plus", "input": "您好!這是語音合成範例。", "voice": "longanlingxin"}' \
--output speech.mp3
# 辨識
curl https://api.ailoot.ai/v1/audio/transcriptions \
-H "Authorization: Bearer $AILOOT_API_KEY" \
-F model=qwen-asr \
-F file=@meeting.wav# 語音辨識
with open("meeting.wav", "rb") as f:
tr = client.audio.transcriptions.create(model="qwen-asr", file=f)
print(tr.text){
"text": "各位同事,大家好。先從本週成果開始…"
}身分驗證
- Authorizationheader必填
金鑰格式為
Bearer sk-…。也可使用標頭x-api-key或x-goog-api-key。
文字轉語音:請求本文
- modelstring必填
文字轉語音模型:
gemini-3.8-flash-tts,qwen-audio-3.0-tts-plus,speech-2.8-turbo,gemini-3.8-flash-lite-tts,speech-2.8-hd,gemini-3.1-flash-tts-preview,speech-2.6-turbo,speech-2.6-hd,speech-02-turbo,speech-02-hd。 - inputstring必填
用於文字轉語音的文字。MiniMax 模型須少於 10 000 個字元;
qwen-audio-3.0-tts-plus—最多 600 個字元。 - voicestring
音色。MiniMax 模型必填 (
speech-2.8-hd與其他speech-…): MiniMax 音色 ID (拉丁字母、數字、_與-,最多 128 個字元). 而qwen-audio-3.0-tts-plus預設為longanlingxin,Gemini TTS 模型—Kore。 - response_formatstring選填
MiniMax—僅支援
mp3;qwen-audio-3.0-tts-plus—mp3,wav或pcm; Gemini TTS—wav或json(檔案連結)。
回應為音訊檔案 (MiniMax 為audio/mpeg). 依目錄所列,以文字字元數或 token 數計費。
語音辨識
https://api.ailoot.ai/v1/audio/transcriptions- filefile必填
WAV 音訊檔案,採用
multipart/form-data。qwen-asr,qwen-asr-latest與qwen-audio-3.0-asr-flash:完整、未壓縮的 PCM WAV,最長 5 分鐘,檔案約最多 7,5 MB (base64 格式最多 10 MB)。asr-1.0:PCM WAV,最長 500 秒、最大 50 MB。gemini-3.5-transcribe:WAV,最大 64 MB。 - modelstring必填
語音辨識模型:
gemini-3.5-transcribe,qwen-audio-3.0-asr-flash,asr-1.0。 - response_formatstring選填
僅支援
json(或不指定)。
欄位language不會被這些模型使用。回應:{"text": "…"}。依錄音時長計費 (秒、分鐘或小時—各模型採用不同單位)。
即時語音
使用qwen-audio-3.0-realtime-plus時,請開啟 WebSocket wss://api.ailoot.ai/v1/realtime?model=qwen-audio-3.0-realtime-plus並包含標頭Authorization: Bearer <API_KEY>。請從伺服器端傳送金鑰:不接受查詢字串中的金鑰。請等待session.created以所選模型建立的事件,接著傳送設定、訊息與response.create。以下是音訊工作階段中用於取得文字回應的三個依序傳送的 JSON 文字訊框:
{"type":"session.update","session":{"modalities":["text"],"turn_detection":null,"max_history_turns":20,"instructions":"請簡短回答。"}}{"type":"conversation.item.create","item":{"type":"message","role":"user","content":[{"type":"input_text","text":"請說好。"}]}}{"type":"response.create"}請持續讀取回應事件,直到response.done及其最終 usage;錯誤會透過事件error。每個已確認回應依文字與音訊 token 數計費。音訊輸入:事件input_audio_buffer.append包含audio —base64 PCM16 mono 16 kHz;接著input_audio_buffer.commit與response.create。音訊輸出為 PCM16 mono 24 kHz。此工作階段不接受二進位訊框。
支援的用戶端事件:session.update,input_audio_buffer.append/commit/clear,response.create/cancel,conversation.item.create/retrieve/delete。對話項目僅支援訊息或文字;不支援函式工具、網頁搜尋與聲紋。工作階段限制:600 秒、20 個回應、20 個歷史對話回合、2000 位元組的 instructions,以及 8000 位元組的用戶端文字。閒置逾時取決於設定 (預設為 60 秒)。