自动语音识别¶
POST /api/v5/audio/transcriptions
该接口提供自动语音识别功能,接收音频文件(支持 mp3、wav、m4a、flac、webm 格式),经模型识别后返回对应的文本内容。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
Authorization |
header | string | 否 | 用户个人令牌(匿名访问时可省略) |
Request Body:
请求体为 multipart/form-data 格式,包含音频文件与识别参数。
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"file": {
"description": "音频文件(支持 mp3、wav、m4a、flac、webm 格式)",
"type": "string",
"format": "binary"
},
"model": {
"description": "模型名称,默认 openai/whisper-large-v3",
"type": "string",
"default": "openai/whisper-large-v3"
},
"temperature": {
"description": "采样温度(0.0-1.0),默认 0.6",
"type": "string",
"default": "0.6"
}
},
"required": ["file", "model"]
}
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
text |
string | 是 | 否 | 识别出的文本内容 |
失败响应¶
只有
200/成功响应是不够的:调用方需要知道失败长什么样才能写错误处理。
400 参数错误
401 未认证
429 请求过于频繁
错误字段名以后端实际返回为准。
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
400 |
参数错误(Bad request) |
401 |
需要认证(Requires authentication) |
429 |
请求过于频繁(Rate limited) |
500 |
系统内部错误(Internal server error) |
请求示例¶
参数说明¶
示例使用 multipart/form-data 上传音频文件。匿名访问时可省略 Authorization 头;携带令牌时以该用户身份执行识别。
<token>替换为你的 AtomGit 用户访问令牌(可选);<path/to/audio.mp3>替换为本地音频文件路径,支持 mp3、wav、m4a、flac、webm 格式。
cURL¶
curl -X POST 'https://api.atomgit.com/api/v5/audio/transcriptions' \
-H 'Authorization: Bearer <token>' \
-F 'file=@<path/to/audio.mp3>' \
-F 'model=openai/whisper-large-v3' \
-F 'temperature=0.6'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const form = new FormData();
form.append("file", new Blob([audioBuffer], { type: "audio/mpeg" }), "audio.mp3");
form.append("model", "openai/whisper-large-v3");
form.append("temperature", "0.6");
const response = await fetch("https://api.atomgit.com/api/v5/audio/transcriptions", {
method: "POST",
headers: {
"Authorization": "Bearer <YOUR-TOKEN>",
},
body: form,
});
if (!response.ok) {
throw new Error(`请求失败: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.post(
"https://api.atomgit.com/api/v5/audio/transcriptions",
headers={
"Authorization": "Bearer <YOUR-TOKEN>",
},
files={"file": open("<path/to/audio.mp3>", "rb")},
data={
"model": "openai/whisper-large-v3",
"temperature": "0.6",
},
timeout=60,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误或请求无法解析 |
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
404 |
请求路径不存在 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc