语音转录接口 (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
}
]
}