语音识别
SenseTime TokenPlan 当前模型与接入说明
语音识别
OpenAI 兼容的语音识别接口,请求体为 multipart/form-data。
请求地址
POST https://token.sensetime.com/api/v1/audio/transcriptions
- Content-Type:
multipart/form-data - OpenAI 兼容客户端的
base_url/baseURL填写https://token.sensetime.com/api/v1,不要再额外拼接/v1。audio.transcriptions.create对应此路径。
授权
请求必须携带 API Key:
Authorization: Bearer <API_KEY>
将 <API_KEY> 替换为工作台创建的密钥。下面的示例使用环境变量 TOKENPLAN_API_KEY。
模型选择
当前语音识别模型:seed-asr-2.0。
调用前查询模型列表,确认账号具备该模型的语音识别权限。
请求体
file 与 file_id 二选一。推荐音频为 16 kHz、mono、WAV 或 PCM。常见格式(wav、mp3、m4a、flac 等)由 ffmpeg 解析。单个文件最大 10 MB。
固定 seed-asr-2.0。
音频文件,最大 10 MB。与 file_id 二选一。
先通过 POST /v1/files/upload 上传得到,表单字段 purpose 为 speech_to_text。与 file 二选一。
json、text 或 verbose_json,默认 json。srt 和 vtt 返回 400。
语言提示,例如 zh。
是否做数字、时间标准化。
是否加标点。
是否返回情感。当前上游支持有限。
是否做说话人分离。当前上游支持有限。
最大说话人数。
热词。
auto 或 record_only。
word 或 segment,配合 verbose_json。
为 true 时返回 SSE。
请求示例
curl -sS \
"https://token.sensetime.com/api/v1/audio/transcriptions" \
-H "Authorization: Bearer $TOKENPLAN_API_KEY" \
-F model=seed-asr-2.0 \
-F file=@audio.wav \
-F response_format=json流式识别:
curl -sS -N \
"https://token.sensetime.com/api/v1/audio/transcriptions" \
-H "Authorization: Bearer $TOKENPLAN_API_KEY" \
-F model=seed-asr-2.0 \
-F file=@audio.wav \
-F stream=true
响应
response_format 为 json 时:
{ "text": "API gateway processes https requests with JSON payloads." }
text 时,Content-Type 为 text/plain,响应体是原始文本。
verbose_json 时:
{
"duration": 5.08,
"segments": [
{ "id": 0, "start": 0.28, "end": 4.98, "text": "API gateway processes https requests with JSON payloads." }
],
"words": [
{ "word": "API", "start": 0.28, "end": 0.36 },
{ "word": "gateway", "start": 0.84, "end": 0.92 }
],
"text": "API gateway processes https requests with JSON payloads."
}
stream 为 true 时,响应是 text/event-stream。extra_fields 是上游路由信息,可以忽略。以 transcript.text.done 或 data: [DONE] 作为结束。
data: {"text":"API.","type":"transcript.text.delta"}
data: {"text":"API gateway ...","type":"transcript.text.done","usage":{"type":"duration","seconds":5.08}}
data: [DONE]
持续推麦克风音频使用分段语音识别。低延迟字幕使用实时语音识别。
错误处理
失败时响应体为 { "code", "message" }。response_format 为 srt 或 vtt 时返回 400,code 为 invalid。
| code | HTTP | 含义 |
|---|---|---|
invalid | 400 | 参数不合法、格式不支持 |
authentication_error | 401 | API Key 无效或缺失 |
forbidden | 403 | 无权限 |
gone | 410 | 接口已下线 |
too_many_requests | 429 | 限流或额度不足 |
internal | 500 | 服务内部或上游错误 |