我正在寻找语音识别在Ionic2框架与cordova 插件。
如果可以实现,您能提供一个代码示例(.html和.ts)吗?
我发现了这一点,但是是针对Ionic1:http://devgirl.org/2016/01/08/speaking-with-cordova/和我无法为Ionic2修改代码。
我真的很感激你能提供的任何帮助,并为我的小英语感到抱歉。
发布于 2016-07-29 14:59:11
资料来源:https://github.com/macdonst/SpeechRecognitionPlugin.
使用命令行,将这个插件添加到Ionic2项目中:
cd Your_Project_Root_Folder从iOS 10开始,必须在info.plist中添加一个NSMicrophoneUsageDescription来访问麦克风。
要添加这个条目,您可以在插件安装上传递MICROPHONE_USAGE_DESCRIPTION变量。
ionic plugin add https://github.com/macdonst/SpeechRecognitionPlugin --variable MICROPHONE_USAGE_DESCRIPTION="your usage message"在iOS 10及更高版本上,它使用本机SFSpeechRecognizer (与Siri相同)。在iOS 9及更高版本上,它使用iSpeech SDK,需要一个API密钥,在https://www.ispeech.org/上获得一个,它是免费的。若要提供密钥,请在config.xml中添加此首选项
<preference name="apiKey" value="yourApiKeyHere" />在导入后的.ts文件的开头添加类定义之前的声明:
declare const SpeechRecognition: any;然后,在你的班上:
recognition: any;
constructor() {}
SpeechToText() {
this.platform.ready().then(() => {
this.recognition = new SpeechRecognition();
this.recognition.lang = 'en-US';
this.recognition.onnomatch = (event => {
console.log('No match found.');
});
this.recognition.onerror = (event => {
console.log('Error happens.');
});
this.recognition.onresult = (event => {
if (event.results.length > 0) {
console.log('Output STT: ', event.results[0][0].transcript);
}
});
this.recognition.start();
});
}iSpeech支持的语言是:英语(加拿大) (en-CA)英语(美国) (en-US)西班牙语(西班牙) (es-ES)法语(法国) (fr-FR)意大利语(意大利) (it-IT)波兰语(pl-PL)葡萄牙语(葡萄牙) (pt-PT)
ps:对于iOS 10错误kAFAssistantErrorDomain,或者如果您必须等待结果,请检查这。
完成!
编辑:在Ionic v3.0.1 (2017-04-06)上测试并运行良好:)
发布于 2016-11-20 22:42:41
我使用这个AngularJS指令:
https://stackoverflow.com/questions/38571063
复制相似问题