音频生成
音频转写
whisper-1:OpenAI 兼容音频转写,同步,multipart 上传,返回文本、时间戳或字幕
POST/v1/audio/transcriptions
接收本地音频文件,同步返回识别文本、详细时间戳或字幕,适合会议记录、采访整理、字幕生成和语音输入。
| 项 | 值 |
|---|---|
| 模型 | whisper-1 |
| 模式 | 同步,multipart/form-data 上传 |
| 计费 | 按音频时长,不足一秒按一秒,价格以定价页为准 |
请求头:
Authorization: Bearer sk-lt-...
Content-Type: multipart/form-data快速开始
curl https://api.vibelab.me/v1/audio/transcriptions \
-H "Authorization: Bearer $LOOPTOKEN_API_KEY" \
-F "file=@meeting.mp3" \
-F "model=whisper-1" \
-F "language=zh" \
-F "response_format=json"{
"text": "这是一段测试音频的转写文本。"
}生成 SRT 字幕:
curl https://api.vibelab.me/v1/audio/transcriptions \
-H "Authorization: Bearer $LOOPTOKEN_API_KEY" \
-F "file=@interview.m4a" \
-F "model=whisper-1" \
-F "language=zh" \
-F "response_format=srt" \
--output interview.srtPython:
import os
import requests
with open("meeting.mp3", "rb") as audio:
response = requests.post(
"https://api.vibelab.me/v1/audio/transcriptions",
headers={"Authorization": f"Bearer {os.environ['LOOPTOKEN_API_KEY']}"},
files={"file": ("meeting.mp3", audio, "audio/mpeg")},
data={
"model": "whisper-1",
"language": "zh",
"response_format": "json",
},
timeout=300,
)
response.raise_for_status()
print(response.json()["text"])请求参数
| 参数 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
file | file | 是 | - | 音频文件,只能上传一个,最大 25 MB;扩展名为 mp3、mp4、mpeg、mpga、m4a、wav、webm |
model | string | 是 | - | 当前为 whisper-1 |
language | string | 否 | - | ISO-639-1 两字母语言代码,如中文 zh、英文 en、日文 ja、韩文 ko;显式传入可以减少语言检测歧义并提高处理速度 |
prompt | string | 否 | - | 补充专有名词、上下文或转写风格,处理上限为 224 tokens |
response_format | string | 否 | json | json、text、srt、verbose_json 或 vtt |
temperature | number | 否 | 0 | 采样温度,范围 0 到 1 |
不支持的字段、重复字段、重复文件、空文件、无效语言代码或超出范围的温度会直接返回参数错误。
响应
response_format=json 返回 HTTP 200 和精简 JSON(示例见快速开始)。其他格式:
| 格式 | Content-Type | 内容 |
|---|---|---|
text | text/plain; charset=utf-8 | 只包含完整转写文本 |
srt | application/x-subrip; charset=utf-8 | 带时间范围的 SRT 字幕 |
vtt | text/vtt; charset=utf-8 | 带 WEBVTT 头的 WebVTT 字幕 |
verbose_json | JSON | 转写语言、音频时长和分段时间戳 |
verbose_json 示例:
{
"task": "transcribe",
"language": "zh",
"duration": 2.4,
"text": "欢迎使用 LoopToken。",
"segments": [
{
"id": 0,
"start": 0,
"end": 2.4,
"text": "欢迎使用 LoopToken。"
}
]
}响应只包含公开协议字段,不会返回内部路由、原始服务错误或底层实现信息。
计费
whisper-1 按音频时长计费,不足一秒按一秒计算。
- 请求开始时预扣一分钟额度;识别完成后根据返回的实际音频时长补足或退回差额。
- 余额不足以完成最终结算时,接口返回
402且不会返回转写内容。 - 实际费率以定价页为准。
错误
错误体为 {"error": {"message": "...", "type": "...", "code": "...", "request_id": "..."}},不会混入音频或字幕内容。通用错误码见错误码。示例:
{
"error": {
"message": "file must not exceed 25 MB",
"type": "invalid_request_error",
"code": "invalid_request_error",
"request_id": "019c2a00-1111-7777-8888-999999999999"
}
}本接口常见错误:
| HTTP | code | 触发场景 | 处理 |
|---|---|---|---|
400 / 422 | invalid_request_error | multipart、字段、文件、格式或音频内容不合法 | 按 message 修正,不要自动重试 |
402 | insufficient_credits | 余额不足以预扣或结算 | 充值后重试 |
404 | model_not_found | 模型不存在或当前不可用 | 核对 model |
413 | invalid_request_error | 请求或文件超过 25 MB 限制 | 压缩或切分音频 |
429 | media_concurrency_exceeded | 用户或 API Key 的媒体并发超限(带 Retry-After) | 稍后重试 |
502 | upstream_error | 音频服务暂时不可用或返回无效结果 | 指数退避重试 |
503 | no_available_channel | 当前没有可用的音频转写通道 | 指数退避重试 |
注意事项
使用 cURL 或 SDK 时让工具自动生成 multipart boundary,不要手工固定 Content-Type 的 boundary。
- 所有失败请求都会释放未结算的预扣额度。
502和503→ 使用指数退避重试;参数错误 → 不要自动重试。