跳到主要内容

语音文件异步识别

1. 接口介绍

语音文件异步接口支持异步处理检测数据,适用于针对时长大于 60 秒的音频大文件进行检测识别。

  • 并发限制:测试期允许最多同时处理 50 个文件,正式使用请与我们沟通协商
  • 文件大小限制:100M 以内;
  • 允许识别的格式:amr, mp3, wmv, wav, flv, ogg, spx, m4a

2. 异步调用请求

2.1 请求地址

区域请求地址
国内http://api.speech.tuputech.com/v3/recognition/speech/recording/async/<secretId>
提示

<secretId> 需替换为您的 secretId,请联系我们为您开通 secretId

2.2 请求方法

POST

2.3 请求头

Content-Type: application/json

2.4 请求参数说明

参数名类型是否必填说明
recordingRecording语音文件信息,详见 Recording 参数
timestampNumber当前的服务器的 Unix 时间戳
nonceNumber随机数
signatureString

RSA-SHA256 算法签名。签名步骤:

  1. 将参与签名的参数(secretIdtimestampnonce)用英文半角逗号 , 拼接,得到 SignString
  2. 使用您的私钥以 RSA-SHA256 算法对 SignString 签名,然后进行 Base64 编码,得到 signature 字符串。
tasksArray指定运行的任务 ID 列表

Recording 参数

参数名类型是否必填说明
urlString语音文件地址
callbackUrlString检测结果的回调地址(支持 http, https)。失败重试 2 次,需保证回调地址正常
callbackRuleString不传值表示出现违规才回调;all 表示回调全部结果
languageString语言代码,在进行多语种语音转译或审核时必填。多语种语音转译类产品需联系图普进行配置使用。对应语言代码详见:语音转译审核(多语种)语言代码列表
roomIdString房间 ID
userIdString用户 ID
forumIdString板块 ID,数据 ID
customInfoObject自定义信息,用于给请求附加额外信息(比如:关联的信息)

2.5 请求示例

json 请求示例

{
"recording": {
"url": "http://www.tupu.com/test.mp3",
"callbackUrl": "http://your_cb.com",
"roomId": "your_room_id",
"userId": "your_user_id",
"forumId": "your_forum_id",
"customInfo": {
"hello": true,
"other": "your other message"
}
},
"timestamp": 1541499770,
"nonce": 0.8469537531104208,
"signature": "your_signature"
}

curl 请求示例

  • 不指定任务
curl -X POST --header 'Content-Type: application/json' \
-d '{
"recording": {
"url": "rtmp://pili-Room-4daedc9c7a5db36c325f6609000c0201",
"callbackUrl": "http://www.tupu.com/callback",
"callbackRule": "all",
"roomId": "111111",
"userId": "23231",
"forumId": "321313",
"customInfo": {
"hello": true,
"other": "your other message"
}
},
"timestamp": 1541499770,
"nonce": 0.8469537531104208,
"signature": "CsIMcHuWqn/QFEnHWcFEhrB7ydcg5xTKawpRpNqA9Nw2WlCVIDR5jDcyUF85"
}' \
'http://api.speech.tuputech.com/v3/recognition/speech/recording/async/your_secretId'
  • 指定任务
curl -X POST --header 'Content-Type: application/json' \
-d '{
"recording": {
"url": "rtmp://pili-Room-4daedc9c7a5db36c325f6609000c0201",
"callbackUrl": "http://www.tupu.com/callback",
"callbackRule": "all",
"roomId": "111111",
"userId": "23231",
"forumId": "321313",
"customInfo": {
"hello": true,
"other": "your other message"
}
},
"timestamp": 1541499770,
"nonce": 0.8469537531104208,
"signature": "CsIMcHuWqn/QFEnHWcFEhrB7ydcg5xTKawpRpNqA9Nw2WlCVIDR5jDcyUF85",
"tasks": [ "5caee6b2a76925c55a09a6d2", "5c8213b9bc807806aab0a574" ]
}' \
'http://api.speech.tuputech.com/v3/recognition/speech/recording/async/your_secretId'

3. 请求同步返回

3.1 返回参数说明

结果的数据结构

参数名类型是否必有说明
resultResult详见以下 Result 数据结构

Result 数据结构

参数名类型是否必有说明
requestIdString客户提交的音频的唯一请求 ID,后续可以通过该 ID 查到音频的相关信息
urlString音频文件地址
callbackUrlString检测结果的回调地址
roomIdString房间 ID
userIdString用户 ID
forumIdString板块 ID,数据 ID
customInfoObject自定义信息,用于给请求附加额外信息(比如:关联的信息)

3.2 返回示例

json 字段数据示例:

{
"result": {
"requestId": "tupu_request_id",
"url": "http://www.tupu.com/test.mp3",
"callbackUrl": "http://your_cb.com",
"callbackRule": "all",
"roomId": "your_room_id",
"userId": "your_user_id",
"forumId": "your_forum_id",
"customInfo": {
"hello": true,
"other": "your other message"
}
},
"code": 0,
"message": "success",
"nonce": "0.01627771095362096",
"timestamp": 1552391372490
}

4. 结果回调

4.1 回调请求

4.1.1 请求地址

request callbackUrl 参数值里的地址

4.1.2 请求方法

POST

4.1.3 请求头

Content-Type: application/json

4.1.4 回调结果

回调结果 json 里的公共结构
参数名类型是否必有说明
requestIdString客户提交的音频的唯一请求 ID
speechInfoSpeechInfo语音文件信息,详见 SpeechInfo
roomIdString房间 ID
userIdString用户 ID
forumIdString板块 ID,数据 ID
customInfoObject自定义信息,用于给请求附加额外信息(比如:关联的信息)
<任务 ID>Object审核任务的 ID,不同任务数据结构不同,请参看 4.2 各识别任务回调参数
SpeechInfo
参数名类型是否必有说明
durationNumber语音文件时长,单位:秒

4.2 各识别任务回调参数

4.3 回调示例

{
"requestId": "63ec935d73d73c0af97f5fe9",
"roomId": "test-room",
"userId": "test-user",
"forumId": "test-forum",
"customInfo": {
"key": "value"
},
"speechInfo": {
"duration": 51
},
"5caee6b2a76925c55a09a6d2": {
"violations": [
{
"content": "今天是二零一零年一月十九号,星期二,欢迎收看东方新闻,我是晓蕾,我是袁鸣,我们在上海的直播室向各位问好。今天离中国二零一零年上海世博会开幕还有一百零二天,在快速",
"action": "pass",
"label": "Normal",
"review": false,
"rate": 1,
"startTime": 0,
"endTime": 15,
"hasVoice": true,
"details": []
},
{
"content": "浏览了今天的主要新闻之后,我们来看详细报道。上海市党政负责干部会议昨天下午举行传达学习贯彻胡锦涛总书记在上海考察时的重要讲话精神。中共中央政治局委员上海市委书记俞正声强",
"action": "block",
"label": "Politics",
"review": false,
"rate": 1,
"startTime": 15,
"endTime": 30,
"hasVoice": true,
"details": [
{
"keyword": "胡锦涛",
"hint": "胡锦涛",
"mainLabel": "Politics",
"subLabel": "Political_Negative_events"
},
{
"keyword": "总书记",
"hint": "总书记",
"mainLabel": "Politics",
"subLabel": "Political_Negative_events"
},
{
"keyword": "(中央+书记)",
"hint": "中央政治局委员上海市委书记",
"mainLabel": "Politics",
"subLabel": "Political_Negative_events"
},
{
"keyword": "(中共+政治)",
"hint": "中共中央政治",
"mainLabel": "Politics",
"subLabel": "Political_Negative_events"
},
{
"keyword": "(中央+委员)",
"hint": "中央政治局委员",
"mainLabel": "Politics",
"subLabel": "Political_Negative_events"
},
{
"keyword": "俞正声",
"hint": "俞正声",
"mainLabel": "Politics",
"subLabel": "Political_Negative_events"
}
]
},
{
"content": "调要承担起中央交给上海的重任,不辜负党中央和胡锦涛总书记的殷切期望,努力把上海世博会办成一届成功精彩的,难忘的盛会,努力开创上海改革开放和社会主义现代化建设的新局",
"action": "block",
"label": "Politics",
"review": false,
"rate": 1,
"startTime": 30,
"endTime": 45,
"hasVoice": true,
"details": [
{
"keyword": "(中央+书记)",
"hint": "中央和胡锦涛总书记",
"mainLabel": "Politics",
"subLabel": "Political_Negative_events"
},
{
"keyword": "党中央",
"hint": "党中央",
"mainLabel": "Politics",
"subLabel": "Political_Negative_events"
},
{
"keyword": "社会主义",
"hint": "社会主义",
"mainLabel": "Politics",
"subLabel": "National_policy"
}
]
},
{
"content": "面,当好推动科学发展,促进社会和谐的排头兵。",
"action": "pass",
"label": "Normal",
"review": false,
"rate": 1,
"startTime": 45,
"endTime": 60,
"hasVoice": true,
"details": []
}
],
"text": "今天是二零一零年一月十九号,星期二,欢迎收看东方新闻,我是晓蕾,我是袁鸣,我们在上海的直播室向各位问好。今天离中国二零一零年上海世博会开幕还有一百零二天,在快速浏览了今天的主要新闻之后,我们来看详细报道。上海市党政负责干部会议昨天下午举行传达学习贯彻胡锦涛总书记在上海考察时的重要讲话精神。中共中央政治局委员上海市委书记俞正声强调要承担起中央交给上海的重任,不辜负党中央和胡锦涛总书记的殷切期望,努力把上海世博会办成一届成功精彩的,难忘的盛会,努力开创上海改革开放和社会主义现代化建设的新局面,当好推动科学发展,促进社会和谐的排头兵。",
"label": "Politics",
"action": "block",
"review": false,
"rate": 1
},
"riskType": 1,
"suggestion": 1,
"code": 0,
"message": "success",
"nonce": "0.5767297909345241",
"timestamp": 1676448608228
}

4.4 回调响应

http 状态为 200 则表示回调成功,所以客户端成功收到回调后,需尽快响应并携带 200 状态码,防止回调重复发送。