GrammarRecognizer not working

I have KeywordRecognizer working fine and now I’m looking to do something more advanced so I’m trying to switch to GrammarRecognizer. Can anyone confirm if it’s working?

I started from the example on the Microsoft page. To make sure it’s not a problem with my SRGS I used the super simple music player control grammar from this example. I tried saying “start the track” and some of the other phrases. I declared my recognizer as:

protected GrammarRecognizer grammarRecognizer;

And got it setup in Start():

grammarRecognizer = new GrammarRecognizer(Application.dataPath +
“/StreamingAssets/SRGS/myGrammar.xml”);
grammarRecognizer.OnPhraseRecognized += GrammarRecognizer_OnPhraseRecognized;
grammarRecognizer.Start();

My callback is just an output:

private void GrammarRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
Debug.Log(“Phrase recognized!!”);
}

I put a check in Update() and grammarRecognizer.IsRunning is returning true. I’m pretty sure it’s loaded the SRGS because if I put in a bogus filename it doesn’t return a valid recognizer. I can see in Visual Studio that my grammar has my callback configured within it. I’m using the microphone built into the Rift but I don’t think that’s a problem because it works great with KeywordRecognizer from my same project.

Hey, which build are you on? Are you getting any errors in the log? I assume you’re testing in the editor?

I’ve tried 5.4.0b19 & b20. I’m testing in the editor and I’m not seeing anything in the log.

I just tried it on latest 5.4, but GrammarRecognizer didn’t have changes for ages, so it b19 and b20 should behave identically. Unfortunately, I couldn’t reproduce the issue with your repro project :confused:

Are you using a laptop microphone by any chance? I found those to require you to speak louder than the microphones that are connected to PCs, are in the phones or the hololens. Especially when the phrases consist of more than 1 word.

I’m using the mic built into the Oculus Rift and it works fine with the KeywordRecognizer every time. Just to be sure I completely disconnected the Rift and plugged in a regular old headset mic and held it right up to my mouth. Again it worked fine for the KeywordRecognizer but not the GrammarRecognizer. At one point I got a strangely worded error which read “Failed to start stopping speech recognizer (hr = 0x80131509)” in the console. I’m not sure if that’s coming from Unity or perhaps from the Microsoft SAPI.

That’s most definitely coming from Unity. I suppose you can’t reproduce this error consistently?

No it only happened once. I’m wondering if it’s an indication of the SAPI not being disposed of properly. According to the documentation only the DictationRecognizer seems to require an explicit Dipose call so as you can see in my example I’m not doing special to stop and/or destroy it. I’ve also noticed that with the KeywordRecognizer it sometimes doesn’t seem to pick up changes to keywords. I edit the string in Visual Studio, save it out and restart the game in the editor but once and while it doesn’t recognize the new phrase unless I completely quit the editor and restart it. I’ve not been able to reproduce that consistently either.

I tried the same project on a nearly identical machine and it worked just fine. I’ll try and find some way to test grammars outside of Unity to see if there’s some problem with the SAPI on the original machine.

Hi, QA tried on several 5.4 betas, but couldn’t reproduce the issue either (they responded to your bug report).

It turns out somehow my original computer had its speech input language set to “English (United Kingdom)”. I installed Windows 10 from media purchased in the USA and with my time zone set so I have no idea how it got set this way. I don’t have a UK accent but as I explained it was still recognizing phrases as keywords very reliably. It’s possible that the reason it didn’t recognize anything from the example grammar is because it had "xml:lang=“en-US” on the first line. Thanks for your help!