要将语音转换为文本,我正在使用cordova ios应用程序的cordova-plugin-speechrecognition插件。开始语音识别并显示部分结果时,它可以正常工作。但是,如果我尝试重新启动以删除以前的消息并从新的新语音中开始识别,则语音识别插件会引发异常“ Error Domain = kAFAssistantErrorDomain Code = 203”
我在ios中启动语音识别的方式
首次请求许可
if (window.cordova) {
window.plugins.speechRecognition.requestPermission(
() => {
this.hasPermission = true;
console.log('Permission' + this.hasPermission);
return true;
},
() => {
this.hasPermission = false;
console.log('Permission' + this.hasPermission);
return false;
}
);
}
然后开始收听
if (window.cordova) {
if (!this.hasPermission) {
alert(
'Please enable microphone permission from Settings'
);
return;
}
const options: any = {
language: 'en-US',
matches: 500,
showPartial: true
};
window.plugins.speechRecognition.startListening(
(result: any [] | any) => {
console.log('Get speech data: ');
console.log(result[0]);
// callback function callback(result[0])
},
error => {
if (errorCallback) {
errorCallback();
}
console.log('failed' + error);
},
options
);
}
当我尝试停止识别时,我调用stop方法
window.plugins.speechRecognition.stopListening(
() => {
console.log('Stopped!');
},
() => {
console.log('Failed to stop!');
}
);
当我尝试停止监听“ Error Domain = kAFAssistantErrorDomain Code = 203”时收到的错误消息