我创建了离子应用程序,并使用了cordova-plugin-speechreognition进行语音到文本的转换。
应用中使用的代码如下:
initSpeech() {
this.speechRecognition.hasPermission()
.then((hasPermission: boolean) => {
console.log(hasPermission)
if (!hasPermission) {
this.speechRecognition.requestPermission()
.then(
() => console.log('granted'),
() => console.log('Denied')
)
}
})
}
start() {
// Start the recognition process
this.speechRecognition.startListening()
.subscribe(
(matches: Array<string>) => { this.voicetext = matches[0]; this.mainForm.controls['comments'].setValue(matches[0]); },
(onerror) => console.log('error:', onerror)
)
}
//stop listening for(ios only)
stop() {
this.speechRecognition.stopListening();
}
此代码在调用Google语音Api的android上运行良好。 当我在iOS上运行它时,我做了必要的更改,例如添加 ios的info.plist中的NSSpeechRecognitionUsageDescription权限。
不确定,但是当我通过Apple开发者帐户测试飞行应用程序对其进行测试时,语音识别在ios 13.3上不起作用。
预先感谢