Kinect Speech Recognition

I have a project for recognition. It works, but if I use this project as a class and call its methods from another class, I have a problem with an exception in the line:

sre = new SpeechRecognitionEngine(ri.Id); 

Error:

There is no recognizer of the required identifier.

The code:

 KinectAudioSource source = kinectSensor.AudioSource; source.EchoCancellationMode = EchoCancellationMode.None; // No AEC for this sample source.AutomaticGainControlEnabled = false; // Important to turn this off for speech recognition // source.SystemMode = SystemMode.OptibeamArrayOnly; speechRecognizer = CreateSpeechRecognizer(); using (Stream s = source.Start()) { speechRecognizer.SetInputToAudioStream(s, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null)); Console.WriteLine("Recognizing speech. Say: 'purple', 'green' or 'blue'. Press ENTER to stop"); speechRecognizer.RecognizeAsync(RecognizeMode.Multiple); Console.ReadLine(); Console.WriteLine("Stopping recognizer ..."); speechRecognizer.RecognizeAsyncStop(); } private static SpeechRecognitionEngine CreateSpeechRecognizer() { RecognizerInfo ri = GetKinectRecognizer(); SpeechRecognitionEngine sre; //if (ri == null) return 0; sre = new SpeechRecognitionEngine(ri.Id); var colors = new Choices(); colors.Add("red"); colors.Add("green"); colors.Add("blue"); var gb = new GrammarBuilder { Culture = ri.Culture }; gb.Append(colors); // Create the actual Grammar instance, and then load it into the speech recognizer. var g = new Grammar(gb); sre.LoadGrammar(g); sre.SpeechRecognized += SreSpeechRecognized; sre.SpeechHypothesized += SreSpeechHypothesized; sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected; return sre; } private static RecognizerInfo GetKinectRecognizer() { Func<RecognizerInfo, bool> matchingFunc = r => { string value; r.AdditionalInfo.TryGetValue("Kinect", out value); return "True".Equals(value, StringComparison.InvariantCultureIgnoreCase) && "en-US".Equals(r.Culture.Name, StringComparison.InvariantCultureIgnoreCase); }; return SpeechRecognitionEngine.InstalledRecognizers().Where(matchingFunc).FirstOrDefault(); } 
+6
source share
2 answers

I think your GetKinectRecognizer () method is incorrect.

Does TryGetValue () not return a boolean value if it is found, and a value found as an out parameter? You are not doing anything with the return boolean from TryGetvalue ().

Do you expect the AdditionalInfo dictionary to have a key equal to "Kinect" and a string of "True" or "False"? This is what you seem to be looking for.

This code is based on an example you can point to. I really don't follow what you're testing in matchFunc. You ignore the return value from TryGetvalue, you look for the AdditionalInfo key with the name "Kinect" with the string value "True" and the resolver with the culture "en-US".

Why don't you just upload the contents of SpeechRecognitionEngine.InstalledRecognizers () and make sure that it contains what you think it contains. This is an old school, but useful:

 foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers()) { Debug.WriteLine(String.Format("Id={0}, Name={1}, Description={2}, Culture={3}", ri.Id, ri.Name, ri.Description, ri.Culture)); foreach(string key in ri.AdditionalInfo.Keys) { Debug.WriteLine(string.Format("{0} = {1}", key, ri.AdditionalInfo[key])); } Debug.WriteLine("-"); } 

I do not have the Kinect SDK, but on my Windows 7 computer it shows:

 Id=MS-1033-80-DESK, Name=MS-1033-80-DESK, Description=Microsoft Speech Recognizer 8.0 for Windows (English - US), Culture=en-US VendorPreferred = CommandAndControl = Version = 8.0 Language = 409;9 Desktop = SupportedLocales = 409;1009;3409;9 AudioFormats = 16;18;20;22;45;53;{6F50E21C-E30E-4B50-95E9-21E8F23D15BD} SpeakingStyle = Discrete;Continuous WildcardInCFG = Anywhere;Trailing Dictation = Hypotheses = Alternates = CC;Dictation windowsV6compatible = Name = MS-1033-80-DESK DictationInCFG = Anywhere;Trailing UPSPhoneSet = WordSequences = Anywhere;Trailing Vendor = Microsoft - Id=MS-2057-80-DESK, Name=MS-2057-80-DESK, Description=Microsoft Speech Recognizer 8.0 for Windows (English - UK), Culture=en-GB = VendorPreferred = CommandAndControl = Version = 8.0 Language = 809 Desktop = SupportedLocales = 809;C09;1409;1809;1C09;2009;2409;2809;2C09;3009;4009;4409;4809;9 AudioFormats = 16;18;20;22;45;53;{6F50E21C-E30E-4B50-95E9-21E8F23D15BD} SpeakingStyle = Discrete;Continuous WildcardInCFG = Anywhere;Trailing Dictation = Hypotheses = Alternates = CC;Dictation windowsV6compatible = Name = MS-2057-80-DESK DictationInCFG = Anywhere;Trailing UPSPhoneSet = WordSequences = Anywhere;Trailing Vendor = Microsoft - - 

Make sure that the values ​​you are looking for in the AdditionalInfo dictionary do exist. Then create your matchFunc to check it out.

+4
source

Try it. This works for me.

  private static RecognizerInfo GetKinectRecognizer() { foreach (RecognizerInfo recognizer in SpeechRecognitionEngine.InstalledRecognizers()) { System.Diagnostics.Debug.Write(recognizer.Culture.Name+"\n\n"); //string value; //recognizer.AdditionalInfo.TryGetValue("Kinect",out value); if ("en-US".Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase)) { return recognizer; } } return null; } 
+3
source

Source: https://habr.com/ru/post/915879/


All Articles