angular - Voice recognition (speech to text - STT cordova plugin) -
i'm looking speech recognition in ionic2 framework cordova plugin.
if can implemented, gently provide example of code (.html , .ts)?
i found this, ionic1: http://devgirl.org/2016/01/08/speaking-with-cordova/ , can't adapt code ionic2.
i appreciate can provide, , sorry little english.
source: https://github.com/macdonst/speechrecognitionplugin.
using command line, add plugin ionic2 project:
cd your_project_root_folder
since ios 10 it's mandatory add nsmicrophoneusagedescription
in info.plist access microphone.
to add entry can pass microphone_usage_description
variable on plugin install.
ionic plugin add https://github.com/macdonst/speechrecognitionplugin --variable microphone_usage_description="your usage message"
on ios 10 , greater uses native sfspeechrecognizer (same siri). on ios 9 , older uses ispeech sdk, api key required, 1 on https://www.ispeech.org/, it's free. provide key, add preference inside config.xml
<preference name="apikey" value="yourapikeyhere" />
add declaration @ beginning of .ts file, after import, before class definition:
declare const speechrecognition: any;
then, in class:
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 supported languages are: english (canada) (en-ca) english (united states) (en-us) spanish (spain) (es-es) french (france) (fr-fr) italian (italy) (it-it) polish (poland) (pl-pl) portuguese (portugal) (pt-pt)
ps: ios 10 error kafassistanterrordomain or if have wait results, check this.
done!
edit: tested on ionic v3.0.1 (2017-04-06) , works fine :)
Comments
Post a Comment