

There are four dictation events that can be subscribed to and handled to implement dictation behavior.

It will release these resources automatically during garbage collection at an extra performance cost if they aren't released before that. Once done with the recognizer, it should be disposed using Dispose() to release the resources it uses. Start() and Stop() methods respectively enable and disable dictation recognition.

The DictationRecognizer exposes dictation functionality and supports registering and listening for hypothesis and phrase completed events, so you can give feedback to your user both while they speak and afterwards. Use the DictationRecognizer to convert the user's speech to text. Types: DictationRecognizer, SpeechError, SpeechSystemStatus SemanticMeaning meanings = manticMeanings įinally, start recognizing! grammarRecognizer.Start() private void Grammar_OnPhraseRecognized(PhraseRecognizedEventArgs args) Most of the important information will be provided in the semanticMeanings array. You'll get a callback containing information specified in your SRGS grammar, which you can handle appropriately. Now register for the OnPhraseRecognized event grammarRecognizer.OnPhraseRecognized += grammarRecognizer_OnPhraseRecognized GrammarRecognizer = new GrammarRecognizer(Application.streamingDataPath + "/SRGS/myGrammar.xml") Once you have your SRGS grammar, and it is in your project in a StreamingAssets folder: /Assets/StreamingAssets/SRGS/myGrammar.xmlĬreate a GrammarRecognizer and pass it the path to your SRGS file: private GrammarRecognizer grammarRecognizer See: Create Grammars Using SRGS XML for file format information. This can be useful if your app has more than just a few keywords, if you want to recognize more complex phrases, or if you want to easily turn on and off sets of commands. The GrammarRecognizer is used if you're specifying your recognition grammar using SRGS. Types: GrammarRecognizer, PhraseRecognizedEventArgs, SpeechError, SpeechSystemStatus If (keywords.TryGetValue(args.text, out keywordAction))įinally, start recognizing! keywordRecognizer.Start() if the keyword recognized is in our dictionary, call that Action. Now register for the OnPhraseRecognized event keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized Īn example handler is: private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args) action to be performed when this keyword is spokenĬreate the keyword recognizer and tell it what we want to recognize: keywordRecognizer = new KeywordRecognizer(()) We're adding the "activate" keyword in this example: //Create keywords for keyword recognizer Now add a keyword to the dictionary, for example in of a Start() method. Then let's add a few fields to your class to store the recognizer and keyword->action dictionary: KeywordRecognizer keywordRecognizer We'll need a few using statements to save some keystrokes: using Types: KeywordRecognizer, PhraseRecognizedEventArgs, SpeechError, SpeechSystemStatus
