深色模式
预置语音识别模型服务接口说明
接口地址:https://platform.wair.ac.cn/maas/ws/taichu_asr
请求方式:post 请求
语音识别模型 Taichu-ASR
websocket 协议
实时语音识别服务,提供 websocket 协议接入
完整流程分以下 4 个步骤:
1.发送语音识别开始指令,设置一些识别参数
payload(json):
{
"appkey": "",
"signal": "start",
"mode": 1,
"nbest": 1,
"continuous_decoding": true,
"enable_voice_detection": true,
"enable_semantic_segmentation": false,
"enable_itn": false,
"enable_punc": false,
"enable_wakeup": false,
"sample_rate": 16000,
"format": "wav",
"speaker_num": 1
}
字段 | 类型 | 备注 |
---|---|---|
appkey | string | 业务名称 |
signal | string | 1. start 表示识别开始 2. end 表示识别结束 |
mode | int | 0. offline 1. online 2. two-pass 三种识别模型。默认是在线模式。离线,在线(流式),two-pass(中间结果流式输出,最终结果使用离线方式解码,提高准确率,但是最后识别耗时会增加) |
nbest | int | 识别结果候选条数 |
continuous_decoding | bool | 是否开启连续说 |
enable_voice_detection | bool | 是否开启语音检测,如果开了连续说,服务会忽略本字段的值,必然开启语音检测 |
enable_semantic_segmentation | bool | 是否开启语义分段,默认 false,如果开启,必须同时开启 continuous_decoding |
enable_itn | bool | ITN(逆文本 inverse text normalization)中文数字转换阿拉伯数字。设置为 True 时,中文数字将转为阿拉伯数字输出,默认是 True |
enable_punc | bool | 增加标点符号,默认是 True |
enable_wakeup | bool | 是否开启唤醒,默认是 False。开启唤醒,必须要唤醒之后才会做识别 |
sample_rate | int | 音频采样率,默认 16000 |
format | string | 音频格式,pcm、wav |
speaker_num | int | 说话人数目,默认 0, 表示不做说话人识别 |
2. 发送音频二进制流
payload: 音频数据 (当前仅支持 wav 或 pcm ,采样率为 16000,单通道数据)
3.发送结束识别(唤醒)指令
payload:
{
"signal": "end"
}
4. 循环读取识别结果
response payload
字段 | 类型 | 备注 |
---|---|---|
status | string | 1. ok (响应正常)2. failed (响应失败) |
type | string | 1. server_ready (发送 start 指令后,返回服务 ready 信息)2. partial_result (流式识别的中间识别结果)3. final_result (流式识别的最终识别结果)4. wakeup (唤醒结果)5. speech_end (识别结束) |
nbest | array | type 为 final_result 时,数组元素对象中才有 word_pieces 字段 |
tail_elapsed | int | 尾包耗时,单位为 ms,type 为 final_result 时,才有本字段 |
message | string | status 为 failed 时,才有本字段 |
session_id | string | websocket 连接的 id |
几种响应的示例
● 4.1 连接服务成功
{
"status": "ok",
"type": "server_ready",
"session_id": ""
}
● 4.2 中间识别结果
{
"status": "ok",
"type": "partial_result",
"nbest": [{"sentence": "今天的"}],
"speakers": [{
"id": "xxx",
"start": 100, // 说话人开始时间,单位 ms
"end": 1020 // 说话人结束时间,单位 ms
}
],
"session_id": ""
}
● 4.3 最终识别结果
{
"status": "ok",
"type": "final_result",
"nbest": [
{
"sentence": "今天的天气怎么样",
"global_start": 0, // 分段开始时间,单位 ms
"global_end": 1080, // 分段结束时间, 单位 ms
"word_pieces": [
{"word": "今", "start": 660, "end": 760},
{"word": "天", "start": 820, "end": 920},
{"word": "的", "start": 980, "end": 1080},
{"word": "天", "start": 1180, "end": 1280},
{"word": "气", "start": 1380, "end": 1480},
{"word": "怎", "start": 1540, "end": 1640},
{"word": "么", "start": 1660, "end": 1760},
{"word": "样", "start": 1780, "end": 1880}
]
}
],
"speakers": [{
"id": "xxx",
"start": 100, // 说话人开始时间,单位 ms
"end": 1020 // 说话人结束时间,单位 ms
}
],
"tail_elapsed": 100,
"session_id": ""
}
send start 的时候如果开启了连续说(continuous_decoding=true), 可能会有多个 final_result
● 4.4 唤醒结果
{
"status": "ok",
"type": "wakeup",
"keyword": "你好小初",
"start": 810,
"end": 1350
}
● 4.5 识别结束
{
"status": "ok",
"type": "speech_end"
}
● 4.6 异常结果
"status": "failed",
"message": "Unexpected signal type"
}
强制替换
请求说明
同样也是 websocket 协议
请求字段
字段 | 类型 | 是否必须 | 说明 |
---|---|---|---|
appkey | string | 是 | 业务名称 |
signal | string | 是 | 指令,固定为 upload_replacements |
replacements | string | 是 | 强制替换配置,格式见示例 |
请求 json
{
"appkey": "",
"signal": "upload_replacements",
"replacements": "三新堆=三星堆\n悟汉热干面=武汉热干面",
}
返回 json
{
"status":"ok",
"message":"upload replacements success",
"session_id":"56801b37-f2a3-4b18-ba97-9036aa78d06d"
}
上传 Contexts
请求说明
同样也是 websocket 协议
请求字段
字段 | 类型 | 是否必须 | 说明 |
---|---|---|---|
appkey | string | 是 | 业务名称 |
signal | string | 是 | 指令,固定为 upload_contexts |
contexts | list[string] | 是 | contexts 配置,格式见示例 |
请求 json
{
"appkey": "",
"signal": "upload_contexts",
"contexts": ["人民大会堂", "中国人民大学", "中国人民银行"]
}
返回 json
{
"status":"ok",
"message":"upload contexts success",
"session_id":"e09c0934-79e6-4bd7-a13c-2eb99b36cae8"
}