語音轉錄介面 (POST /v1/audio/transcriptions)
將音訊檔案轉錄為指定格式的文字,完全相容 OpenAI API 協定規範。
HTTP 請求
http
POST /v1/audio/transcriptions
Authorization: Bearer sk-oneasr-...
Content-Type: multipart/form-data請求主體欄位說明 (Multipart Form)
| 欄位名 | 類型 | 是否必填 | 參數說明 |
|---|---|---|---|
file | binary | 是 | 音訊檔案二進位物件 (mp3, mp4, wav, m4a, ogg, webm, flac 等)。 |
model | string | 是 | 呼叫的引擎/模型名稱(如 faster-whisper, qwen, whisper-1)。 |
language | string | 否 | ISO-639-1 語言代碼(如 zh, en, ja, de, ko)。 |
prompt | string | 否 | 引導轉錄風格或專業術語的上下文提示詞。 |
response_format | string | 否 | 回傳資料格式:json (預設), text, srt, verbose_json, vtt。 |
temperature | number | 否 | 取樣溫度參數 (0.0 到 1.0,預設: 0.0)。 |
timestamp_granularities | array | 否 | 時間戳記細粒度:["word"] (詞級), ["segment"] (分句級)。 |
呼叫範例程式碼
cURL
bash
curl -X POST http://localhost:8000/v1/audio/transcriptions -H "Authorization: Bearer sk-oneasr-v1-xxx" -F file="@meeting.mp3" -F model="faster-whisper" -F language="zh" -F response_format="verbose_json"Python (官方 OpenAI SDK)
python
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="sk-oneasr-v1-xxx"
)
with open("speech.mp3", "rb") as f:
result = client.audio.transcriptions.create(
model="faster-whisper",
file=f,
response_format="verbose_json"
)
print(result.text)回傳範例 (verbose_json)
json
{
"task": "transcribe",
"language": "chinese",
"duration": 5.24,
"text": "歡迎使用 OneASR 高效能私有化語音閘道。",
"segments": [
{
"id": 0,
"seek": 0,
"start": 0.0,
"end": 5.2,
"text": "歡迎使用 OneASR 高效能私有化語音閘道。",
"tokens": [50364, 4843, 284, 1530, 50589],
"temperature": 0.0,
"avg_logprob": -0.12,
"compression_ratio": 1.1,
"no_speech_prob": 0.001
}
]
}