addEventListener(){
var that = this;
// 监听语音识别事件
plus.speech.addEventListener("start", function(){
// 监听开始识别
that.voiceContent = '';
}, false);
plus.speech.addEventListener("recognition", function(e){
console.log('recognition', e);
// 监听最终语音
that.voiceContent += e.result;
}, false);
plus.speech.addEventListener("end", function(){
// 监听识别结束
that.sendInputValue += that.voiceContent;
}, false);
plus.speech.addEventListener("error", function(e){
// 监听识别错误
console.log('error', e);
}, false);
},
async startRecognize () {
// #ifdef APP-PLUS
let status = await this.checkPermission();
if (status !== 1) {
return;
}
// #endif
var options = {};
var that = this;
options.engine = 'baidu';
plus.speech.startRecognize(options, function (s) {
console.log(s);
}, function (e) {
console.log("语音识别失败:" + e.message);
});
},
async checkPermission() {
let status = permision.isIOS ? await permision.requestIOS('record') :
await permision.requestAndroid('android.permission.RECORD_AUDIO');
if (status === null || status === 1) {
status = 1;
} else if (status === 2) {
uni.showModal({
content: "系统麦克风已关闭",
confirmText: "确定",
showCancel: false,
success: function(res) {
}
})
} else {
uni.showModal({
content: "需要麦克风权限",
confirmText: "设置",
success: function(res) {
if (res.confirm) {
permision.gotoAppSetting();
}
}
})
}
console.log(status);
return status;
},
- 发布:2020-06-08 11:07
- 更新:2020-11-16 10:35
- 阅读:1497
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 2.7.9
手机系统: iOS
手机系统版本号: iOS 13.4
手机厂商: 苹果
手机机型: 苹果7,苹果7p
页面类型: vue
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
打印结果
11:03:32.963 permissionStatus:1970168948 at common/permission.js:104
11:03:32.983 [Number] 1 at pages/order/payOnlineChatApp/payOnlineChatApp.js:246
打印结果
11:03:32.963 permissionStatus:1970168948 at common/permission.js:104
11:03:32.983 [Number] 1 at pages/order/payOnlineChatApp/payOnlineChatApp.js:246
预期结果:
语音识别成功
语音识别成功
实际结果:
语音识别失败
语音识别失败
bug描述:
uniapp IOS端使用startRecognize语音识别卡着不动了
语音识别SDK是baidu的
测试机型
iPhone7, iPhone7p