语音识别
AI搜索开放平台支持通过API的方式调用语音识别服务,可将视频或音频中的语音内容快速转化为结构化文本,可用于会议记录、视频检索、在线客服等场景。
服务列表
|
服务名称 |
服务ID(service_id) |
服务描述 |
API调用QPS限制(含主账号与RAM子账号) |
|
语音识别服务 |
ops-audio-asr-001 |
提取音频信息生成字幕文件。 |
5 说明 如需扩充QPS,请通过工单联系技术支持协助。 |
获取身份鉴权信息
通过API调用AI搜索开放平台服务时,需要对调用者身份进行鉴权,如何获取鉴权信息请参见获取API-KEY。
获取服务调用地址
支持通过公网和VPC两种方式调用服务,详情请参见获取服务接入地址。
创建语音识别异步任务
请求方式:POST
URL
POST {host}/v3/openapi/workspaces/{workspace_name}/audio-asr/{service_id}/async
-
host:调用服务的地址,支持通过公网和VPC两种方式调用API服务,可参见获取服务接入地址。
登录AI搜索开放平台控制台,在左上角选择目标工作空间(如default(默认空间)),在左侧导航栏单击API Keys,在访问域名区域可分别查看公网API域名和私网API域名。
-
workspace_name:工作空间名称,例如default。
-
service_id: 系统内置服务ID,例如ops-audio-asr-001。
请求参数
Header参数
API-KEY认证
|
参数 |
类型 |
必填 |
描述 |
示例值 |
|
Content-Type |
String |
是 |
请求类型:application/json |
application/json |
|
Authorization |
String |
是 |
API-Key |
Bearer OS-d1**2a |
Body参数
|
参数 |
类型 |
必填 |
描述 |
|
input |
Object(input) |
是 |
指定待处理的多媒体文件。 |
|
parameters |
Object |
否 |
指定服务的参数。 |
|
output |
Object(output) |
是 |
控制输出。 |
input
|
参数 |
类型 |
必填 |
描述 |
|
content |
String |
否 |
视频/音频内容的base64编码数据。 音频格式支持mp3、wav、aac、flac、ogg、m4a、alac、wma。 视频格式数据支持mp4、avi、mkv、mov、flv、webm。 说明
input.content 和 input.oss 参数互斥,只能二选一。
使用BASE64数据:将编码后的BASE64数据传递给
示例:
|
|
oss |
String |
否 |
输入文件的OSS路径,例如 oss://<BUCKET_NAME>/xxx/xxx.mp3。 |
|
file_name |
String |
否 |
视频/音频文件的名称,如果没有设置,则从内容的文件名中解析。 |
output
|
参数 |
类型 |
必填 |
描述 |
|
type |
String |
否 |
text:将语音识别结果以文本形式返回,仅同步任务调用下支持。 oss: 音频文件放在OSS中(默认)。 |
|
oss |
String |
否 |
输出文件的OSS路径,在type为oss的情况下必须填写。 示例: |
返回参数
|
参数 |
类型 |
描述 |
示例值 |
|
result.task_id |
String |
语音识别任务的唯一标识ID。 |
asr-xxxx-abc-123 |
Curl请求示例
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <您的API-KEY>" \
"http://***-hangzhou.opensearch.aliyuncs.com/v3/openapi/workspaces/default/audio-asr/ops-audio-asr-001/async"
--data '{
"input":{
"oss":"oss://<BUCKET_NAME>/xxx/xxx.mp3",
"file_name":"xxx"
},
"output" :{
"type":"oss",
"oss":"oss://<BUCKET_NAME>/result"
}
}' \
响应示例
{
"request_id":"3eb8de02091b59431601f3bff******",
"latency":37,
"usage":{},
"result":{
"task_id":"asr-20250610164552-1108418170738252-******",
"status":"PENDING"
}
}
获取异步语音识别任务状态
请求方式:GET
URL
{host}/v3/openapi/workspaces/{workspace_name}/audio-asr/{service_id}/async/task-status?task_id={task_id}
-
host:调用服务的地址,支持通过公网和VPC两种方式调用API服务,可参见获取服务接入地址。
-
workspace_name:工作空间名称,例如default。
-
service_id: 系统内置服务ID,例如ops-audio-asr-001。
-
task_id:创建异步语音识别任务返回参数中的任务标识。
请求参数
|
参数 |
类型 |
必填 |
描述 |
示例 |
|
Content-Type |
String |
是 |
请求类型:application/json |
application/json |
|
Authorization |
String |
是 |
API-Key |
Bearer OS-d1**2a |
返回参数
|
参数 |
类型 |
描述 |
示例 |
|
request_id |
String |
系统对一次API调用赋予的唯一标识。 |
3C09570D-12DB-46B4-BF0F-A100D79B**** |
|
latency |
Float/Int |
请求耗时,单位ms。 |
3.0 |
|
result.task_id |
String |
异步任务ID。 |
a7e4c0f6-874c-47e3-b05b-02278a96e**** |
|
result.status |
String |
任务状态:
|
PENDING |
|
result.error |
String |
status=FAIL时的错误信息内容,正常情况为空。 |
|
|
result.data |
List(AsrResult) |
语音识别的结果。当异步任务状态未成功完成(SUCCESS)时,该字段为空。 |
|
|
usage.duration |
Float.duration |
语音文件的时长。 |
AsrResult
|
参数 |
类型 |
描述 |
|
text |
String |
语音识别得到的文本数据。 |
|
start |
Float |
当前文本在视频中起始时间戳,单位s。 |
|
end |
Float |
当前文本在视频中结束时间戳,单位s。 |
Curl请求示例
curl -X GET \
-H"Content-Type: application/json" \
-H "Authorization: Bearer <您的API-KEY>" \
"http://***-hangzhou.opensearch.aliyuncs.com/v3/openapi/workspaces/default/audio-asr/ops-audio-asr-001/async/task-status?task_id=asr-20250618112151-1108418170738252-******"
响应示例
{
"request_id": "1a1a4ca4b7a91dd630a40c54af******",
"latency": 9,
"usage": {
"duration": 9
},
"result": {
"task_id": "asr-20250618112151-1108418170738252-******",
"status": "SUCCESS",
"data": [
{
"text": "容杰律斗以和煦如春阳的头声娓娓道来,",
"start": 0.0,
"end": 3.9
},
{
"text": "透出了欣欣向荣的生命力,温暖每一个倾听的耳朵。",
"start": 4.24,
"end": 9.06
}
]
}
}
创建语音识别同步任务
请求方式:POST
URL
{host}/v3/openapi/workspaces/{workspace_name}/audio-asr/{service_id}/sync
-
host:调用服务的地址,支持通过公网和VPC两种方式调用API服务,可参见获取服务接入地址。
-
workspace_name:工作空间名称,例如default。
-
service_id: 系统内置服务ID,例如ops-audio-asr-001。
请求参数
Header参数
API-KEY认证
|
参数 |
类型 |
必填 |
描述 |
示例值 |
|
Content-Type |
String |
是 |
请求类型:application/json |
application/json |
|
Authorization |
String |
是 |
API-Key |
Bearer OS-d1**2a |
Body参数
|
参数 |
类型 |
必填 |
描述 |
|
input |
Object(input) |
是 |
指定待处理的多媒体文件。 |
|
parameters |
Object |
否 |
指定服务的参数。 |
|
output |
Object(output) |
是 |
控制输出。 |
input
|
参数 |
类型 |
必填 |
描述 |
|
content |
String |
否 |
视频/音频内容的base64编码数据。 音频格式支持mp3、wav、aac、flac、ogg、m4a、alac、wma。 视频格式数据支持mp4、avi、mkv、mov、flv、webm。 说明
input.content 和 input.oss 参数互斥,只能二选一。
使用BASE64数据:将编码后的BASE64数据传递给
示例:
|
|
oss |
String |
否 |
输入文件的OSS路径,例如 oss://<BUCKET_NAME>/xxx/xxx.mp3。 |
|
file_name |
String |
否 |
视频/音频文件的名称,如果没有设置,则从内容的文件名中解析。 |
Output
|
参数 |
类型 |
必填 |
描述 |
|
type |
String |
否 |
text:将语音识别结果以文本形式返回,仅同步调用下支持。 oss:视频/音频文件放在OSS中(默认)。 |
|
oss |
String |
否 |
输出文件的OSS路径,在type为oss的情况下必须填写。
示例: |
返回参数
|
参数 |
类型 |
描述 |
示例值 |
|
result.task_id |
String |
语音识别任务的唯一标识ID。 |
asr-xxxx-abc-123 |
Curl请求示例
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <您的API-KEY>" \
"http://***-hangzhou.opensearch.aliyuncs.com/v3/openapi/workspaces/default/audio-asr/ops-audio-asr-001/sync"
--data '{
"input":{
"oss":"oss://<BUCKET_NAME>/xxx/xxx.mp3",
"file_name":"xxx"
},
"output" :{
"type":"oss",
"oss":"oss://<BUCKET_NAME>/result"
}
}' \
响应示例
{
"request_id": "df96b5c444281e0e79561fe9f8******",
"latency": 570,
"usage": {
"duration": 9
},
"result": {
"task_id": "asr-20250618132401-1108418170738252-******",
"status": "SUCCESS",
"data": [
{
"text": "容杰律斗以和煦如春阳的头声娓娓道来,",
"start": 0.0,
"end": 3.9
},
{
"text": "透出了欣欣向荣的生命力,温暖每一个倾听的耳朵。",
"start": 4.24,
"end": 9.06
}
]
}
}
状态码说明
在访问请求出错的情况下,输出的结果中会通过code和message指明出错原因。
{
"request_id": "6F33AFB6-A35C-4DA7-AFD2-9EA16CCF****",
"latency": 2.0,
"code": "InvalidParameter",
"http_code": 400,
"message": "JSON parse error: Cannot deserialize value of type `ImageStorage` from String \\"xxx\\"
}
|
HTTP 状态码 |
错误码 |
描述 |
|
200 |
- |
请求成功,包括任务失败场景,实际任务状态需从result.status中判断。 |
|
404 |
BadRequest.TaskNotExist |
任务不存在。 |
|
400 |
InvalidParameter |
不合法请求。 |
|
500 |
InternalServerError |
内部错误。 |
更多状态码说明,请参见状态码说明。