Search code examples
c#dictionaryspeech-recognitionspeech

Limiting speech recognition choices in C#


I want to know if there is a way to limit the windows speech recogition library to a small library containing only a few words?

I tried makeing a voice operated program with a few words, but when i added words that was hard for the computer to recognice (Like names) it offen recogniced the name as another word. That's why i want to add a spesified dictionary like a list of names.

Eks: Sondre, Robert, Bob

And when saying a name, the program will only check if one of the 3 words where recogniced


Solution

  • I used this code below for my previous projects that I did using Kinect camera. I have limited the phrases {faster,slower,stop..} and build up a grammer. I hope it will answer your question

        private void initSpeech()
        {
                // You need to change here if you are not using kinect camera 
                RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == "SR_MS_en-US_Kinect_10.0").FirstOrDefault();
                if (ri == null)
                {
                        throw new ApplicationException("Could not locate speech recognizer. Ensure you have the Kinect Speech SDK/runtime/MSKinectLangPack_enUS installed.");
                }
    
                sr = new SpeechRecognitionEngine(ri.Id);
                //Phrases that will be recognised added
                Choices phrases = new Choices();
                phrases.Add(
                    "faster", 
                    "slower", 
                    "stop", 
                    "invert y",
                    "music volume",
                    "effects volume",
                    "okay");
                GrammarBuilder gb = new GrammarBuilder();
                //adding our phrases to the grammar builder
                gb.Append(phrases);
                // Loading the grammer 
                sr.LoadGrammar(new Grammar(gb));
        }