Example #1
0
        public MainEngine(MainSystemTray form)
        {
            //Fetch the list of commands
            commandList = SettingsSingleton.Instance().Commands;
            // Create the speech recognition engine
            speechRecognizer = createSpeechRecogntionEngine(form);

            stateController = new StateController();

            //Register to the event that provides the fixations
            EventSingleton.Instance().fixationEvent += sharedData_fixationEvent;
            //Register to the event that fires when keyboard keys are pressed
            EventSingleton.Instance().systemHook.KeyDown += sharedData_keyboardEvent;
            speechRecognizer.SpeechRecognized += SpeechRecognised;
        }
Example #2
0
        private SpeechRecognitionEngine createSpeechRecogntionEngine(MainSystemTray form)
        {
            SpeechRecognitionEngine newSpeechRecognizer = new SpeechRecognitionEngine(CultureInfo.CurrentCulture);

            //Setting up the grammars for the voice recognizer
            Grammar commandGrammar = createCommandGrammar();
            commandGrammar.Weight = 1f;

            //"grammar:dictation#pronunciation"
            Grammar dictationGrammar = new DictationGrammar("grammar:dictation");
            dictationGrammar.Name = DictationState.GRAMMARNAME;
            dictationGrammar.Weight = .3f;

            //Setting up the voice recognizer to start listening for commands and send them to the SpeechRecognised method
            newSpeechRecognizer.RequestRecognizerUpdate();
            newSpeechRecognizer.LoadGrammar(commandGrammar);
            newSpeechRecognizer.LoadGrammar(dictationGrammar);
            try
            {
                newSpeechRecognizer.SetInputToDefaultAudioDevice();
                newSpeechRecognizer.RecognizeAsync(RecognizeMode.Multiple);
            }
            catch (System.InvalidOperationException)
            {
                if (MessageBox.Show(
                    "You do not have an audio capture device installed \nPlease install a microphone and restart the program",
                    "No Capture Device", MessageBoxButtons.OK) == DialogResult.OK)
                {
                    form.ExitProgram();
                }

            }

            return newSpeechRecognizer;
        }