Voice recognition for Angular 5
NgxSpeech allows to trigger actions using voice commands.
ngSpeechContext directive allows to define context. For instance, "menu" could be a context that will allow to activate the menu commands, and "search" another context enabling search commands.
Say "pizza" and then choose your pizza
ngSpeechAction directive allow to register a command into a context and bind it to method.
will trigger the
order() method if we say "Napolitana" only if we are in the "pizza" context (i.e. we said "pizza" before saying "Napolitana").
All the words corresponding to a command or a context are referenced in a grammar.
A command or a sub-context can be activcayed only if we are in the parent context, but a first-level context can activatyed from anywhere.
SpeechService exposes useful observables:
message, the last recognized word(s), even if it is not part of the current grammar,
context, the current context as a path (like
command, the last comnmand.
npm install ngx-speech
In our app module, we need to import the
SpeechModule and to provide the language to use:
To start the speech recognition, we ned to call the
;...constructorpublic speech: SpeechServicengOnInit