音频流识别
[!TIP|labelVisibility:hidden|iconVisibility:hidden] navigator.speechrecognition.speechStreamRecognition(success, error,options)
支持平台:
- Android
- iOS
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
success | Function | 否 | 成功回调函数 |
error | Function | 否 | 失败回调函数 |
options | Object | 是 | 数据对象 |
success
函数会返回一个对象,其属性包含以下一项或多项:
result
(String)--语音识别的结果
error
函数会返回一个字符串,返回识别失败码和失败原因,错误码参考:https://shimo.im/sheet/w3yUy39uNKs0J7DT
options
参数为一个对象,其属性包含以下一项或多项:
audioPath
(String/ 必选) -- 识别的音频路径,仅支持file://
和cdvfile://
(注意:音频支持的格式是pcm
和wav
格式、音频采样率要是16k
或者8k
,采样精度16位、单声道音频)speechTimeout
(String/ 可选) -- 语音输入超时时间,单位:ms,默认30000,最大可取值60000mslanguage
(String/ 可选) -- 语言,支持:zh_cn
,zh_tw
,en_us
,默认zh_cn
accent
(String/ 可选) -- 语言区域,参考科大讯飞后台,默认mandarin
(普通话)dot
(String/ 可选) -- 是否识别标点符号,可取值“0”或“1”,默认“1”(识别标点)
示例代码
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
navigator.speechrecognition.speechStreamRecognition(
function (successCallback) {
alert(JSON.stringify(successCallback));
},function (errorCallback) {
alert(JSON.stringify(errorCallback));
},{'audioPath':"cdvfile://localhost/cache/1578553855454.pcm"});
}
</script>
响应示例代码:
{
"result": "你好,你好,你好你好,你好,你好你好。"
}