Source: https://ailoot.ai/docs/zh-hant-tw/api/audio/
Canonical: https://ailoot.ai/docs/zh-hant-tw/api/audio/
Language: zh-hant-tw

[API](https://ailoot.ai/docs/zh-hant-tw/) 

# 音訊

[Markdown](https://ailoot.ai/docs/zh-hant-tw/api/audio/index.md)

採用 OpenAI Audio 格式的文字轉語音（TTS）與語音辨識（STT）。

POST`https://api.ailoot.ai/v1/audio/speech`

音訊

```bash
# 語音合成
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
```

```python
# 語音辨識
with open("meeting.wav", "rb") as f:
    tr = client.audio.transcriptions.create(model="qwen-asr", file=f)
print(tr.text)
```

200 OK · 語音辨識

```json
{
  "text": "各位同事，大家好。先從本週成果開始…"
}
```

## 身分驗證

| 參數 | 類型 | 必填 | 說明 |
| --- | --- | --- | --- |
| `Authorization` | header | 必填 | 金鑰格式為`Bearer sk-…`。也可使用標頭`x-api-key`或`x-goog-api-key`。 |

## 文字轉語音：請求本文

| 參數 | 類型 | 必填 | 說明 |
| --- | --- | --- | --- |
| `model` | string | 必填 | 文字轉語音模型：`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`。 |
| `input` | string | 必填 | 用於文字轉語音的文字。MiniMax 模型須少於 10 000 個字元； `qwen-audio-3.0-tts-plus` —最多 600 個字元。 |
| `voice` | string |  | 音色。**MiniMax 模型必填** (`speech-2.8-hd`與其他`speech-…`): MiniMax 音色 ID (拉丁字母、數字、 `_`與`-`，最多 128 個字元). 而`qwen-audio-3.0-tts-plus`預設為`longanlingxin`，Gemini TTS 模型— `Kore`。 |
| `response_format` | string | 選填 | MiniMax—僅支援`mp3`; `qwen-audio-3.0-tts-plus` — `mp3`，`wav`或`pcm`; Gemini TTS— `wav`或`json` (檔案連結)。 |

回應為音訊檔案 (MiniMax 為`audio/mpeg`). 依目錄所列，以文字字元數或 token 數計費。

## 語音辨識

POST`https://api.ailoot.ai/v1/audio/transcriptions`

| 參數 | 類型 | 必填 | 說明 |
| --- | --- | --- | --- |
| `file` | file | 必填 | 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。 |
| `model` | string | 必填 | 語音辨識模型：`gemini-3.5-transcribe`，`qwen-audio-3.0-asr-flash`，`asr-1.0`。 |
| `response_format` | string | 選填 | 僅支援`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 文字訊框：

```json
{"type":"session.update","session":{"modalities":["text"],"turn_detection":null,"max_history_turns":20,"instructions":"請簡短回答。"}}
```

```json
{"type":"conversation.item.create","item":{"type":"message","role":"user","content":[{"type":"input_text","text":"請說好。"}]}}
```

```json
{"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 秒)。

此處說明的語音模式為`qwen-audio-3.0-realtime-plus`; 其他即時模型另有各自規則。路徑`/v1/realtime/sessions`與暫時權杖 (ephemeral tokens) 均不受支援。

還有疑問嗎？請提供 Request ID與問題描述，我們會協助釐清。[聯絡支援](mailto:support@ailoot.ai)

## Ailoot · 公司及其專案組合





Ailoot以累積的營運經驗、廣大的客戶群、穩定的服務及持續的KPI管理為基礎。





公司及其專案組合：數百萬客戶，每月銷售額達數十億。





Ailoot將這些營運經驗用於API存取，讓客戶的產品、代理、應用程式及自動化流程使用AI功能。
