语音听写

[!TIP|labelVisibility:hidden|iconVisibility:hidden] navigator.speechrecognition.speechRecognition(success, error,options)

支持平台:

  • Android
  • iOS

参数说明

参数 类型 必填 说明
success Function 成功回调函数
error Function 失败回调函数
options Object 数据对象

success函数会返回一个对象,其属性包含以下一项或多项:

  • result(String)--语音听写的结果
  • audioPath(String)-- 音频存放路径

error函数会返回一个字符串,返回识别失败码和失败原因,错误码参考:https://shimo.im/sheet/w3yUy39uNKs0J7DT

options参数为一个对象,其属性包含以下一项或多项:

  • haveView (Bool/ 可选) -- 是否有界面,默认false
  • speechTimeout (String/ 可选) -- 语音输入超时时间,单位:ms,默认30000,最大可取值60000ms
  • language(String/ 可选) -- 语言,支持:zh_cnzh_twen_us,默认zh_cn
  • accent(String/ 可选) -- 语言区域,参考科大讯飞后台,默认mandarin(普通话)
  • dot(String/ 可选) -- 是否识别标点符号,可取值“0”或“1”,默认“1”(识别标点)
  • audioFormat(String/ 可选) -- 保存音频格式支持pcmwav,默认为pcm
  • isPath(Bool/ 可选) -- 是否保存音频,默认false

示例代码

// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
    // 监听’deviceready‘事件
    document.addEventListener('deviceready', onDeviceReady, false)
    function onDeviceReady(){
        navigator.speechrecognition.speechRecognition(
        function (successCallback) {
            alert(JSON.stringify(successCallback));
        },function (errorCallback) {
            alert(JSON.stringify(errorCallback));
        },{'haveView':'false','speechTimeout':'30000','language':'zh_cn','dot':'1','accent':'mandarin','isPath':true,'audioFormat':'pcm'});
    }
</script>

响应示例代码:

{
    "result": "你好,你好,你好你好,你好,你好你好。",
    "audioPath": "cdvfile://localhost/cache/1578553855454.pcm"
}

results matching ""

    No results matching ""