Beispiel #1
0
 public void stopEngine()
 {
     menuRule       = null;
     grammar        = null;
     objRecoContext = null;
     mEngineStarted = false;
 }
Beispiel #2
0
        private void VoiceCalibration()
        {
            // Get an insance of RecoContext. I am using the shared RecoContext.
            objRecoContext = new SpeechLib.SpSharedRecoContext();
            // Assign a eventhandler for the Hypothesis Event.
            objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(Hypo_Event);
            // Assign a eventhandler for the Recognition Event.
            objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
            //Creating an instance of the grammer object.
            grammar = objRecoContext.CreateGrammar(0);

            //Activate the Menu Commands.
            menuRule = grammar.Rules.Add("MenuCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
            object PropValue = "";

            menuRule.InitialState.AddWordTransition(null, "Cancel", " ", SpeechGrammarWordType.SGLexical, "Cancel", 1, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Yes", " ", SpeechGrammarWordType.SGLexical, "Yes", 2, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "No", " ", SpeechGrammarWordType.SGLexical, "No", 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "All Lights Off", " ", SpeechGrammarWordType.SGLexical, "All Lights Off", 4, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "All Lights On", " ", SpeechGrammarWordType.SGLexical, "All Lights On", 5, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "First Light On", " ", SpeechGrammarWordType.SGLexical, "First Light On", 6, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Second Light On", " ", SpeechGrammarWordType.SGLexical, "Second Light On", 7, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Third Light On", " ", SpeechGrammarWordType.SGLexical, "Third Light On", 8, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "First Light Off", " ", SpeechGrammarWordType.SGLexical, "First Light Off", 9, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Second Light Off", " ", SpeechGrammarWordType.SGLexical, "Second Light Off", 10, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Third Light Off", " ", SpeechGrammarWordType.SGLexical, "Third Light Off", 11, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Recalibrate", " ", SpeechGrammarWordType.SGLexical, "Recalibrate", 12, ref PropValue, 1.0F);
            grammar.Rules.Commit();
            grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);
        }
Beispiel #3
0
        private void comboBoxEx1_SelectedIndexChanged(object sender, EventArgs e)
        {
            _WAVFile = comboBoxEx1.SelectedText;
            if (_WAVFile == null)
            {
                return;
            }
            wavRecoContext = new SpeechLib.SpInProcRecoContext();

            ((SpInProcRecoContext)wavRecoContext).Recognition +=
                new _ISpeechRecoContextEvents_RecognitionEventHandler(wavRecoContext_Recognition);

            ((SpInProcRecoContext)wavRecoContext).EndStream +=
                new _ISpeechRecoContextEvents_EndStreamEventHandler(wavRecoContext_EndStream);

            Grammar = wavRecoContext.CreateGrammar(0);

            Grammar.DictationLoad("", SpeechLoadOption.SLOStatic);

            InputWAV = new SpFileStream();

            InputWAV.Open(@_WAVFile, SpeechStreamFileMode.SSFMOpenForRead, false);

            wavRecoContext.Recognizer.AudioInputStream = InputWAV;

            Grammar.DictationSetState(SpeechRuleState.SGDSActive);
        }
Beispiel #4
0
        private void InitializeSpeech()
        {
            try
            {
                // First of all, let's create the main reco context object.
                objRecoContext = new SpeechLib.SpSharedRecoContext();

                // Then, let's set up the event handler. We only care about
                // Hypothesis and Recognition events in this sample.

                objRecoContext.Recognition += new
                                              _ISpeechRecoContextEvents_RecognitionEventHandler(
                    RecoContext_Recognition);

                grammar = objRecoContext.CreateGrammar(grammarId);
                grammar.DictationLoad("", SpeechLoadOption.SLOStatic);
                grammar.DictationSetState(SpeechLib.SpeechRuleState.SGDSActive);

                speechInitialized = true;
                statusBar.Text    = "Speech recognition initialized";
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    "Exception caught when initializing SAPI."
                    + " This application may not run correctly.\r\n\r\n"
                    + e.ToString(),
                    "Error");
            }
        }
Beispiel #5
0
        private void cmdEnable_Click(object sender, System.EventArgs e)
        {
            label4.Text = "Initializing Speech Engine....";
            // Get an insance of RecoContext. I am using the shared RecoContext.
            objRecoContext = new SpeechLib.SpSharedRecoContext();
            // Assign a eventhandler for the Hypothesis Event.
            objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(Hypo_Event);
            // Assign a eventhandler for the Recognition Event.
            objRecoContext.Recognition += new
                                          _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
            //Creating an instance of the grammer object.
            grammar     = objRecoContext.CreateGrammar(0);
            label3.Text = "Speak Out one of the follwoing.\r\n1. New 2. Open 3. Close 4. Exit\r\n5. Cut 6. Copy 7. Paste 8. Delete";
            //Activate the Menu Commands.
            menuRule = grammar.Rules.Add("MenuCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
            object PropValue = "";

            menuRule.InitialState.AddWordTransition(null, "New", " ", SpeechGrammarWordType.SGLexical, "New", 1, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Open", " ", SpeechGrammarWordType.SGLexical, "Open", 2, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Close", " ", SpeechGrammarWordType.SGLexical, "Close", 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Exit", " ", SpeechGrammarWordType.SGLexical, "Exit", 4, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Cut", " ", SpeechGrammarWordType.SGLexical, "Cut", 5, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Copy", " ", SpeechGrammarWordType.SGLexical, "Copy", 6, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Paste", " ", SpeechGrammarWordType.SGLexical, "Paste", 7, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Delete", " ", SpeechGrammarWordType.SGLexical, "Delete", 8, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Continue", " ", SpeechGrammarWordType.SGLexical, "Continue", 9, ref PropValue, 1.0F);
            grammar.Rules.Commit();
            grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);
            label4.Text = "Speech Engine Ready for Input";
        }
Beispiel #6
0
 private SoundHelper()
 {
     ssrContex = new SpSharedRecoContextClass();
     isrg = ssrContex.CreateGrammar(1);
     SpeechLib._ISpeechRecoContextEvents_RecognitionEventHandler recHandle =
          new _ISpeechRecoContextEvents_RecognitionEventHandler(ContexRecognition);
     ssrContex.Recognition += recHandle;
 }
 private void InitVoice()
 {
     ssrContex = new SpSharedRecoContextClass();
     isrg      = ssrContex.CreateGrammar(1);
     SpeechLib._ISpeechRecoContextEvents_RecognitionEventHandler recHandle =
         new _ISpeechRecoContextEvents_RecognitionEventHandler(ContexRecognition);
     ssrContex.Recognition += recHandle;
 }
Beispiel #8
0
        /**
         * Initializes the Text to Speech and Speech to Text engines.
         * Finalize commands must be called before the Speech to Text engine will
         * work.
         */
        public Voice()
        {
            this.voice = new SpVoice();

            objRecoContext = new SpSharedRecoContext();
            objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoEvent);
            grammar = objRecoContext.CreateGrammar(0);
            menuRule = grammar.Rules.Add("cogitoCommands",SpeechRuleAttributes.SRATopLevel|SpeechRuleAttributes.SRADynamic,1);
            this.commandCount = 1;

            this._buffer = new Queue();
        }
        /// <summary>
        /// 音声認識で反応する単語(複数)を登録
        /// </summary>
        public void RegistWord(string[] words)
        {
            int max = words.Length;

            this.RecognizerGrammarRule = this.RecognizerRule.CreateGrammar(0);

            this.RecognizerGrammarRule.Reset(0);
            this.RecognizerGrammarRuleGrammarRule = this.RecognizerGrammarRule.Rules.Add("TopLevelRule",
                                                                                         SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic);

            foreach (string word in words)
            {
                this.RecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, word);
            }
            this.RecognizerGrammarRule.Rules.Commit();
        }
Beispiel #10
0
        private void labelX1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog dialog = new OpenFileDialog();

                dialog.Title = "Select a Speech file";

                dialog.ShowDialog();

                _WAVFile = dialog.FileName;

                if (_WAVFile == null)
                {
                    return;
                }

                comboBoxEx1.Items.Add(dialog.FileName);
                comboBoxEx1.SelectedText = dialog.FileName;

                wavRecoContext = new SpeechLib.SpInProcRecoContext();

                ((SpInProcRecoContext)wavRecoContext).Recognition +=

                    new _ISpeechRecoContextEvents_RecognitionEventHandler(wavRecoContext_Recognition);

                ((SpInProcRecoContext)wavRecoContext).EndStream +=
                    new _ISpeechRecoContextEvents_EndStreamEventHandler(wavRecoContext_EndStream);

                Grammar = wavRecoContext.CreateGrammar(0);

                Grammar.DictationLoad("", SpeechLoadOption.SLOStatic);

                InputWAV = new SpFileStream();

                InputWAV.Open(@_WAVFile, SpeechStreamFileMode.SSFMOpenForRead, false);

                wavRecoContext.Recognizer.AudioInputStream = InputWAV;

                Grammar.DictationSetState(SpeechRuleState.SGDSActive);
            }
            catch (Exception er)
            {
                //MessageBox.Show("An Error Occured!", "SpeechApp", MessageBoxButtons.OK, MessageBoxIcon.Error);
                System.Console.WriteLine(er.ToString());
            }
        }
        public void startEngine()
        {
            // Get an insance of RecoContext. I am using the shared RecoContext.
            objRecoContext = new SpeechLib.SpSharedRecoContext();
            // Assign a eventhandler for the Hypothesis Event.
            objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(Hypo_Event);
            // Assign a eventhandler for the Recognition Event.
            objRecoContext.Recognition += new
                _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
            //Creating an instance of the grammer object.
            grammar = objRecoContext.CreateGrammar(0);

            //Activate the Menu Commands.
            menuRule = grammar.Rules.Add("MenuCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
            object PropValue = "";

            menuRule.InitialState.AddWordTransition(null, "Nothing", " ", SpeechGrammarWordType.SGLexical, "Nothing", 1, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Continue", " ", SpeechGrammarWordType.SGLexical, "Continue", 2, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Stop", " ", SpeechGrammarWordType.SGLexical, "Stop", 3, ref PropValue, 1.0F);
            grammar.Rules.Commit();
            grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);
        }
Beispiel #12
0
        public void startEngine()
        {
            if (mEngineStarted)
            {
                return;
            }

            // Get an insance of RecoContext. I am using the shared RecoContext.
            objRecoContext = new SpeechLib.SpSharedRecoContext();
            // Assign a eventhandler for the Hypothesis Event.
            objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(Hypo_Event);
            // Assign a eventhandler for the Recognition Event.
            objRecoContext.Recognition += new
                                          _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
            //Creating an instance of the grammer object.
            grammar = objRecoContext.CreateGrammar(0);

            //Activate the Menu Commands.
            menuRule = grammar.Rules.Add("MenuCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
            object PropValue = "";

            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.NO_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.NO_COMMAND, 1, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.REPEAT_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.REPEAT_COMMAND, 2, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.STOP_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.STOP_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.PAUSE_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.PAUSE_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.BACK_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.BACK_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.FORWARD_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.FORWARD_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.CALIBRATE_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.CALIBRATE_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.SLOWMO_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.SLOWMO_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.TRAINING_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.TRAINING_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.CONTINUE_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.CONTINUE_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.SCORING_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.SCORING_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Current", " ", SpeechGrammarWordType.SGLexical, "Current", 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Video", " ", SpeechGrammarWordType.SGLexical, "Video", 3, ref PropValue, 1.0F);
            grammar.Rules.Commit();
            grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);

            mEngineStarted = true;
        }
Beispiel #13
0
        public void startEngine()
        {
            // Get an insance of RecoContext. I am using the shared RecoContext.
            objRecoContext = new SpeechLib.SpSharedRecoContext();
            // Assign a eventhandler for the Hypothesis Event.
            objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(Hypo_Event);
            // Assign a eventhandler for the Recognition Event.
            objRecoContext.Recognition += new
                                          _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
            //Creating an instance of the grammer object.
            grammar = objRecoContext.CreateGrammar(0);

            //Activate the Menu Commands.
            menuRule = grammar.Rules.Add("MenuCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
            object PropValue = "";

            menuRule.InitialState.AddWordTransition(null, "Nothing", " ", SpeechGrammarWordType.SGLexical, "Nothing", 1, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Continue", " ", SpeechGrammarWordType.SGLexical, "Continue", 2, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Stop", " ", SpeechGrammarWordType.SGLexical, "Stop", 3, ref PropValue, 1.0F);
            grammar.Rules.Commit();
            grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);
        }
Beispiel #14
0
        /// <summary>
        /// Create the main object (SpSharedRecoContext), init the gramar
        /// And activating the events ...
        /// 1.Recognition	=> if any phrase recognized
        /// 2.AudioLevel	=> to watch the mic volume
        /// </summary>
        private void initSAPI()
        {
            try
            {
                objRecoContext = new SpeechLib.SpSharedRecoContext();
                objRecoContext.AudioLevel+= new _ISpeechRecoContextEvents_AudioLevelEventHandler(RecoContext_VUMeter);
                objRecoContext.Recognition+= new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
                objRecoContext.EventInterests=SpeechLib.SpeechRecoEvents.SRERecognition | SpeechLib.SpeechRecoEvents.SREAudioLevel;

                //create grammar interface with ID = 0
                grammar=objRecoContext.CreateGrammar(0);
            }
            catch(Exception ex)
            {
                MessageBox.Show("Exception \n"+ex.ToString(),"Error - initSAPI");
            }
        }
Beispiel #15
0
 public void stopEngine()
 {
     menuRule       = null;
     grammar        = null;
     objRecoContext = null;
 }
Beispiel #16
0
        /// <summary>
        ///     This function will create the main SpSharedRecoContext object
        ///     and other required objects like Grammar and rules.
        ///     In this sample, we are building grammar dynamically since
        ///     listbox content can change from time to time.
        ///     If your grammar is static, you can write your grammar file
        ///     and ask SAPI to load it during run time. This can reduce the
        ///     complexity of your code.
        /// </summary>
        private void InitializeSpeech()
        {
            Debug.WriteLine("Initializing SAPI objects...");

            try
            {
                // First of all, let's create the main reco context object.
                // In this sample, we are using shared reco context. Inproc reco
                // context is also available. Please see the document to decide
                // which is best for your application.
                objRecoContext = new SpeechLib.SpSharedRecoContext();

                // Then, let's set up the event handler. We only care about
                // Hypothesis and Recognition events in this sample.
                objRecoContext.Hypothesis += new
                                             _ISpeechRecoContextEvents_HypothesisEventHandler(
                    RecoContext_Hypothesis);

                objRecoContext.Recognition += new
                                              _ISpeechRecoContextEvents_RecognitionEventHandler(
                    RecoContext_Recognition);

                // Now let's build the grammar.
                // The top level rule consists of two parts: "select <items>".
                // So we first add a word transition for the "select" part, then
                // a rule transition for the "<items>" part, which is dynamically
                // built as items are added or removed from the listbox.
                grammar      = objRecoContext.CreateGrammar(grammarId);
                ruleTopLevel = grammar.Rules.Add("TopLevelRule",
                                                 SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
                ruleListItems = grammar.Rules.Add("ListItemsRule",
                                                  SpeechRuleAttributes.SRADynamic, 2);

                SpeechLib.ISpeechGrammarRuleState stateAfterSelect;
                stateAfterSelect = ruleTopLevel.AddState();

                object PropValue = "";
                ruleTopLevel.InitialState.AddWordTransition(stateAfterSelect,
                                                            PreCommandString, " ", SpeechGrammarWordType.SGLexical,
                                                            "", 0, ref PropValue, 1.0F);

                PropValue = "";
                stateAfterSelect.AddRuleTransition(null, ruleListItems, "",
                                                   1, ref PropValue, 0F);

                // Now add existing list items to the ruleListItems
                RebuildGrammar();

                // Now we can activate the top level rule. In this sample, only
                // the top level rule needs to activated. The ListItemsRule is
                // referenced by the top level rule.
                grammar.CmdSetRuleState("TopLevelRule", SpeechRuleState.SGDSActive);
                speechInitialized = true;
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Exception caught when initializing SAPI."
                    + " This application may not run correctly.\r\n\r\n"
                    + e.ToString(),
                    "Error");
            }
        }
Beispiel #17
0
        private void initRecognizer()
        {
            mRecognizerRule = new SpeechLib.SpInProcRecoContext();
            bool hit = false;

            foreach (SpObjectToken recoPerson in mRecognizerRule.Recognizer.GetRecognizers())
            {
                if (recoPerson.GetAttribute("Language") == "411")
                {
                    mRecognizerRule.Recognizer.Recognizer = recoPerson;
                    hit = true;
                    break;
                }
            }
            if (!hit)
            {
                MessageBox.Show("日本語認識が利用できません");
                Application.Exit();
            }

            mRecognizerRule.Recognizer.AudioInput = createMicrofon();

            if (mRecognizerRule.Recognizer.AudioInput == null)
            {
                MessageBox.Show("マイク初期化エラー");
                Application.Exit();
            }

            mRecognizerRule.Hypothesis +=
                delegate(int streamNumber, object streamPosition, SpeechLib.ISpeechRecoResult result)
            {
                string strText = result.PhraseInfo.GetText();
                textBox1.Text = strText;
            };
            mRecognizerRule.Recognition +=
                delegate(int streamNumber, object streamPosition, SpeechLib.SpeechRecognitionType srt, SpeechLib.ISpeechRecoResult isrr)
            {
                SpeechEngineConfidence confidence = isrr.PhraseInfo.Rule.Confidence;
                switch (confidence)
                {
                case SpeechEngineConfidence.SECHighConfidence:
                    label3.Text = "Confidence is High";
                    break;

                case SpeechEngineConfidence.SECNormalConfidence:
                    label3.Text = "Confidence is Normal";
                    break;

                case SpeechEngineConfidence.SECLowConfidence:
                    label3.Text   = "Confidence is Low";
                    textBox2.Text = "信頼性が低すぎます";
                    return;
                }
                string strText = isrr.PhraseInfo.GetText();
                //isrr.PhraseInfo.
                label4.Text = isrr.RecoContext.Voice.Volume.ToString();
                if (strText == "えんいー")
                {
                    Application.Exit();
                }

                if (itunes != null)
                {
                    switch (strText)
                    {
                    case "あいちゅーんず.つぎのきょく":
                    case "あいちゅーんず.つぎ":
                        itunes.NextTrack();
                        break;

                    case "あいちゅーんず.まえのきょく":
                    case "あいちゅーんず.まえ":
                        itunes.PreviousTrack();
                        break;

                    case "あいちゅーんず.いちじていし":
                        itunes.Pause();
                        break;

                    case "あいちゅーんず.ていし":
                        itunes.Stop();
                        break;

                    case "あいちゅーんず.さいせい":
                        itunes.Play();
                        break;

                    case "あいちゅーんず.しね":
                        itunes.Quit();
                        unhockiTunes();
                        break;

                    case "あいちゅーんず.しずかに":
                        itunes.SoundVolume = 50;
                        break;

                    case "あいちゅーんず.おおきく":
                        itunes.SoundVolume = 100;
                        break;

                    case "あいちゅーんず.らんだむ":
                        itunes.CurrentPlaylist.Shuffle = !itunes.CurrentPlaylist.Shuffle;
                        break;
                    }
                }
                else
                {
                    if (strText == "あいちゅーんず.おきろ")
                    {
                        initiTunes();
                    }
                }
                textBox2.Text = strText;
            };
            mRecognizerRule.StartStream +=
                delegate(int streamNumber, object streamPosition)
            {
                textBox1.Text = textBox2.Text = "";
            };
            mRecognizerRule.FalseRecognition +=
                delegate(int streamNumber, object streamPosition, SpeechLib.ISpeechRecoResult isrr)
            {
                textBox1.Text = textBox2.Text = label3.Text = "--Error!--";
            };

            mRecognizerGrammarRule = mRecognizerRule.CreateGrammar();
            mRecognizerGrammarRule.Reset();
            mRecognizerGrammarRuleGrammarRule = mRecognizerGrammarRule.Rules.Add("TopLevelRule", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic);

            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.おきろ");
            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.つぎのきょく");
            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.まえのきょく");
            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.つぎ");
            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.まえ");
            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.いちじていし");
            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.ていし");
            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.さいせい");
            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.しね");
            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.しずかに");
            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.おおきく");
            mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "あいちゅーんず.らんだむ");
            // mRecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "えんいー");

            mRecognizerGrammarRule.Rules.Commit();
            mRecognizerGrammarRule.CmdSetRuleState("TopLevelRule", SpeechRuleState.SGDSActive);
        }
Beispiel #18
0
        /// <summary>
        /// constructor
        /// </summary>
        public HmfHearingAssist()
        {
            //ルール認識 音声認識オブジェクトの生成
            this.RecognizerRule = new SpeechLib.SpInProcRecoContext();
            this.RecognizerDictation = new SpeechLib.SpInProcRecoContext();
            //マイクから拾ってね。
            this.RecognizerRule.Recognizer.AudioInput = CreateMicrofon();
            this.RecognizerDictation.Recognizer.AudioInput = CreateMicrofon();

            //イベント設定(中継)

            //認識途中のデフォルト処理
            this.RecognizerRule.Hypothesis +=
                delegate(int streamNumber, object streamPosition, SpeechLib.ISpeechRecoResult result)
                { this.Hypothesis(streamNumber, streamPosition, result); };

            //認識完了時のデフォルト処理
            this.RecognizerRule.Recognition +=
                delegate(int streamNumber, object streamPosition, SpeechLib.SpeechRecognitionType srt, SpeechLib.ISpeechRecoResult isrr)
                {
                    //ここでDictationでマッチした語を見て、 必ず入っていなければいけない文字列がなければ握りつぶす.
                    if (this.MustMatchString.Length >= 1
                         && this.DictationString.IndexOf(this.MustMatchString) <= -1
                       )
                    {//握りつぶす.
                        this.FalseRecognition(streamNumber, streamPosition, isrr);
                        return;
                    }
                    this.Recognition(streamNumber, streamPosition, srt, isrr);
                };
            //ストリーム開始時のデフォルト処理
            this.RecognizerRule.StartStream +=
                delegate(int streamNumber, object streamPosition)
                {
                    this.DictationString = ""; //開始時に前回マッチした文字列を消す.
                    this.StartStream(streamNumber, streamPosition);
                };
            //認識失敗時のデフォルト処理
            this.RecognizerRule.FalseRecognition +=
                delegate(int streamNumber, object streamPosition, SpeechLib.ISpeechRecoResult isrr)
                { this.FalseRecognition(streamNumber, streamPosition, isrr); };
            //ストリーム終了時のデフォルト処理
            this.RecognizerRule.EndStream +=
                delegate(int streamNumber, object streamPosition, bool streamReleased)
                { this.EndStream(streamNumber, streamPosition, streamReleased); };

            //Dictationでマッチした文字列. RuleよりDictationの方がマッチ順は早いらしい。
            this.RecognizerDictation.Recognition +=
                delegate(int streamNumber, object streamPosition, SpeechLib.SpeechRecognitionType srt, SpeechLib.ISpeechRecoResult isrr)
                {
                    //マッチした文字列の記録
                    this.DictationString = isrr.PhraseInfo.GetText(0, -1, true);
                    //コールバック用のデリゲートを呼ぶ.(これくらいあってもいいかな)
                    this.DictationRecognition(streamNumber, streamPosition, srt, isrr);
                };

            //言語モデルの作成
            this.RecognizerGrammarRule = this.RecognizerRule.CreateGrammar(0);
            this.RecognizerGrammarDictation = this.RecognizerDictation.CreateGrammar(0);

            //言語モデルのルールのトップレベルを作成する.
            this.RecognizerGrammarRuleGrammarRule = this.RecognizerGrammarRule.Rules.Add("TopLevelRule", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic);
            //文字列の追加.
            this.RecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "検索");
            this.RecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "予定");
            this.RecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "認識");
            this.RecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "メモ");
            this.RecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "認証");

            //ルールを反映させる。
            this.RecognizerGrammarRule.Rules.Commit();
            this.RecognizerGrammarRule.CmdSetRuleState("TopLevelRule", SpeechRuleState.SGDSActive);
            this.RecognizerGrammarDictation.DictationSetState(SpeechRuleState.SGDSInactive);
        }
Beispiel #19
0
        private void InitializeSpeech()
        {
            try
            {
                // First of all, let's create the main reco context object.
                objRecoContext = new SpeechLib.SpSharedRecoContext();

                // Then, let's set up the event handler. We only care about
                // Hypothesis and Recognition events in this sample.

                objRecoContext.Recognition += new
                    _ISpeechRecoContextEvents_RecognitionEventHandler(
                    RecoContext_Recognition);

                grammar = objRecoContext.CreateGrammar(grammarId);
                grammar.DictationLoad("", SpeechLoadOption.SLOStatic);
                grammar.DictationSetState(SpeechLib.SpeechRuleState.SGDSActive);

                speechInitialized = true;
                statusBar.Text = "Speech recognition initialized";
            }
            catch(Exception e)
            {
                MessageBox.Show(
                    "Exception caught when initializing SAPI."
                    + " This application may not run correctly.\r\n\r\n"
                    + e.ToString(),
                    "Error");
            }
        }
        private void VoiceCalibration()
        {
            // Get an insance of RecoContext. I am using the shared RecoContext.
            objRecoContext = new SpeechLib.SpSharedRecoContext();
            // Assign a eventhandler for the Hypothesis Event.
            objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(Hypo_Event);
            // Assign a eventhandler for the Recognition Event.
            objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
            //Creating an instance of the grammer object.
            grammar = objRecoContext.CreateGrammar(0);

            //Activate the Menu Commands.
            menuRule = grammar.Rules.Add("MenuCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
            object PropValue = "";
            menuRule.InitialState.AddWordTransition(null, "Cancel", " ", SpeechGrammarWordType.SGLexical, "Cancel", 1, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Yes", " ", SpeechGrammarWordType.SGLexical, "Yes", 2, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "No", " ", SpeechGrammarWordType.SGLexical, "No", 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "All Lights Off", " ", SpeechGrammarWordType.SGLexical, "All Lights Off", 4, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "All Lights On", " ", SpeechGrammarWordType.SGLexical, "All Lights On", 5, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "First Light On", " ", SpeechGrammarWordType.SGLexical, "First Light On", 6, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Second Light On", " ", SpeechGrammarWordType.SGLexical, "Second Light On", 7, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Third Light On", " ", SpeechGrammarWordType.SGLexical, "Third Light On", 8, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "First Light Off", " ", SpeechGrammarWordType.SGLexical, "First Light Off", 9, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Second Light Off", " ", SpeechGrammarWordType.SGLexical, "Second Light Off", 10, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Third Light Off", " ", SpeechGrammarWordType.SGLexical, "Third Light Off", 11, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Recalibrate", " ", SpeechGrammarWordType.SGLexical, "Recalibrate", 12, ref PropValue, 1.0F);
            grammar.Rules.Commit();
            grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);
        }
 public void stopEngine()
 {
     menuRule = null;
     grammar = null;
     objRecoContext = null;
     mEngineStarted = false;
 }
Beispiel #22
0
        /// <summary>
        ///     This function will create the main SpSharedRecoContext object 
        ///     and other required objects like Grammar and rules. 
        ///     In this sample, we are building grammar dynamically since 
        ///     listbox content can change from time to time.
        ///     If your grammar is static, you can write your grammar file 
        ///     and ask SAPI to load it during run time. This can reduce the 
        ///     complexity of your code.
        /// </summary>
        private void InitializeSpeech()
        {
            Debug.WriteLine("Initializing SAPI objects...");

            try
            {
                // First of all, let's create the main reco context object. 
                // In this sample, we are using shared reco context. Inproc reco
                // context is also available. Please see the document to decide
                // which is best for your application.
                objRecoContext = new SpeechLib.SpSharedRecoContext();

                // Then, let's set up the event handler. We only care about
                // Hypothesis and Recognition events in this sample.
                objRecoContext.Hypothesis += new 
                    _ISpeechRecoContextEvents_HypothesisEventHandler(
                    RecoContext_Hypothesis);

                objRecoContext.Recognition += new 
                    _ISpeechRecoContextEvents_RecognitionEventHandler(
                    RecoContext_Recognition);

                // Now let's build the grammar.
                // The top level rule consists of two parts: "select <items>". 
                // So we first add a word transition for the "select" part, then 
                // a rule transition for the "<items>" part, which is dynamically 
                // built as items are added or removed from the listbox.
                grammar = objRecoContext.CreateGrammar(grammarId);
                ruleTopLevel = grammar.Rules.Add("TopLevelRule", 
                    SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
                ruleListItems = grammar.Rules.Add("ListItemsRule", 
                    SpeechRuleAttributes.SRADynamic, 2);

                SpeechLib.ISpeechGrammarRuleState   stateAfterSelect;
                stateAfterSelect = ruleTopLevel.AddState();

                object      PropValue = "";
                ruleTopLevel.InitialState.AddWordTransition(stateAfterSelect,
                    PreCommandString, " ", SpeechGrammarWordType.SGLexical,
                    "", 0, ref PropValue, 1.0F );

                PropValue = "";
                stateAfterSelect.AddRuleTransition(null, ruleListItems, "", 
                    1, ref PropValue, 0F);

                // Now add existing list items to the ruleListItems
                RebuildGrammar();

                // Now we can activate the top level rule. In this sample, only 
                // the top level rule needs to activated. The ListItemsRule is 
                // referenced by the top level rule.
                grammar.CmdSetRuleState("TopLevelRule", SpeechRuleState.SGDSActive);
                speechInitialized = true;
            }
            catch(Exception e)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Exception caught when initializing SAPI." 
                    + " This application may not run correctly.\r\n\r\n"
                    + e.ToString(),
                    "Error");
            }
        }
        public void startEngine()
        {
            if (mEngineStarted)
                return;

            // Get an insance of RecoContext. I am using the shared RecoContext.
            objRecoContext = new SpeechLib.SpSharedRecoContext();
            // Assign a eventhandler for the Hypothesis Event.
            objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(Hypo_Event);
            // Assign a eventhandler for the Recognition Event.
            objRecoContext.Recognition += new
                _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
            //Creating an instance of the grammer object.
            grammar = objRecoContext.CreateGrammar(0);

            //Activate the Menu Commands.
            menuRule = grammar.Rules.Add("MenuCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
            object PropValue = "";

            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.NO_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.NO_COMMAND, 1, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.REPEAT_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.REPEAT_COMMAND, 2, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.STOP_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.STOP_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.PAUSE_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.PAUSE_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.BACK_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.BACK_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.FORWARD_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.FORWARD_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.CALIBRATE_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.CALIBRATE_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.SLOWMO_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.SLOWMO_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.TRAINING_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.TRAINING_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.CONTINUE_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.CONTINUE_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, VoiceCommandEventArgs.SCORING_COMMAND, " ", SpeechGrammarWordType.SGLexical, VoiceCommandEventArgs.SCORING_COMMAND, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Current", " ", SpeechGrammarWordType.SGLexical, "Current", 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, "Video", " ", SpeechGrammarWordType.SGLexical, "Video", 3, ref PropValue, 1.0F);
            grammar.Rules.Commit();
            grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);

            mEngineStarted = true;
        }
Beispiel #24
0
 public void startMicTrainingWizard()
 {
     menuRule       = null;
     grammar        = null;
     objRecoContext = null;
 }
Beispiel #25
0
        /// <summary>
        ///     This function will create the main SpInProcRecoContext object
        ///     and other required objects like Grammar and rules.
        ///     In this sample, we are building grammar dynamically since
        ///     listbox content can change from time to time.
        ///     If your grammar is static, you can write your grammar file
        ///     and ask SAPI to load it during run time. This can reduce the
        ///     complexity of your code.
        /// </summary>
        private void InitializeSpeech()
        {
            Debug.WriteLine("Initializing SAPI objects...");

            try
            {
                // First of all, let's create the main reco context object.
                // In this sample, we are using inproc reco context. Shared reco
                // context is also available. Please see the document to decide
                // which is best for your application.
                objRecoContext = new SpeechLib.SpInProcRecoContext();

                SpeechLib.SpObjectTokenCategory objAudioTokenCategory = new SpeechLib.SpObjectTokenCategory();
                objAudioTokenCategory.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryAudioIn, false);

                SpeechLib.SpObjectToken objAudioToken = new SpeechLib.SpObjectToken();
                objAudioToken.SetId(objAudioTokenCategory.Default, SpeechLib.SpeechStringConstants.SpeechCategoryAudioIn, false);

                objRecoContext.Recognizer.AudioInput = objAudioToken;

                // Then, let's set up the event handler. We only care about
                // Hypothesis and Recognition events in this sample.
                //objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(RecoContext_Hypothesis);

                objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);

                // Now let's build the grammar.
                // The top level rule consists of two parts: "select <items>".
                // So we first add a word transition for the "select" part, then
                // a rule transition for the "<items>" part, which is dynamically
                // built as items are added or removed from the listbox.
                grammar       = objRecoContext.CreateGrammar(grammarId);
                ruleTopLevel  = grammar.Rules.Add("TopLevelRule", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
                ruleCommand   = grammar.Rules.Add("CommandRule", SpeechRuleAttributes.SRADynamic, 2);
                ruleNumbers   = grammar.Rules.Add("NumberRule", SpeechRuleAttributes.SRADynamic, 3);
                ruleListItems = grammar.Rules.Add("ListItemsRule", SpeechRuleAttributes.SRADynamic, 4);

                //Prepare states
                SpeechLib.ISpeechGrammarRuleState stateAfterPre;
                SpeechLib.ISpeechGrammarRuleState stateAfterCommand;
                SpeechLib.ISpeechGrammarRuleState stateAfterNumber;
                stateAfterPre     = ruleTopLevel.AddState();
                stateAfterCommand = ruleTopLevel.AddState();
                stateAfterNumber  = ruleTopLevel.AddState();

                //Add keywords: add,set,delete
                object PropValue = "";
                ruleTopLevel.InitialState.AddWordTransition(stateAfterPre, PreCommandString, null, SpeechGrammarWordType.SGLexicalNoSpecialChars, "", 0, ref PropValue, 1.0F);

                String word;
                PropValue = "";
                word      = "Add";
                ruleCommand.InitialState.AddWordTransition(null, word, "", SpeechGrammarWordType.SGLexicalNoSpecialChars, word, 0, ref PropValue, 1f);

                word = "Set";
                ruleCommand.InitialState.AddWordTransition(null, word, "", SpeechGrammarWordType.SGLexicalNoSpecialChars, word, 1, ref PropValue, 1f);

                word = "Remove";
                ruleCommand.InitialState.AddWordTransition(null, word, "", SpeechGrammarWordType.SGLexicalNoSpecialChars, word, 2, ref PropValue, 1f);

                stateAfterPre.AddRuleTransition(stateAfterCommand, ruleCommand, "", 1, ref PropValue, 1F);

                PropValue = "";
                for (int x = 0; x <= 100; x++)
                {
                    word = Convert.ToString(x);

                    // Note: if the same word is added more than once to the same
                    // rule state, SAPI will return error. In this sample, we
                    // don't allow identical items in the list box so no need for
                    // the checking, otherwise special checking for identical words
                    // would have to be done here.
                    ruleNumbers.InitialState.AddWordTransition(null, word, "", SpeechGrammarWordType.SGLexicalNoSpecialChars, word, x, ref PropValue, 1F);
                }

                stateAfterCommand.AddRuleTransition(stateAfterNumber, ruleNumbers, "", 2, ref PropValue, 1.0F);

                PropValue = "";
                stateAfterNumber.AddRuleTransition(null, ruleListItems, "", 3, ref PropValue, 1.0F);

                // Now add existing list items to the ruleListItems
                RebuildGrammar();

                // Now we can activate the top level rule. In this sample, only
                // the top level rule needs to activated. The ListItemsRule is
                // referenced by the top level rule.
                grammar.CmdSetRuleState("TopLevelRule", SpeechRuleState.SGDSActive);
                speechInitialized = true;
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Exception caught when initializing SAPI."
                    + " This application may not run correctly.\r\n\r\n"
                    + e.ToString(),
                    "Error");

                throw;
            }
        }
 public void startMicTrainingWizard()
 {
     menuRule = null;
     grammar = null;
     objRecoContext = null;
 }
Beispiel #27
0
 private void cmdEnable_Click(object sender, System.EventArgs e)
 {
     label4.Text = "Initializing Speech Engine....";
     // Get an insance of RecoContext. I am using the shared RecoContext.
     objRecoContext = new SpeechLib.SpSharedRecoContext();
     // Assign a eventhandler for the Hypothesis Event.
     objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(Hypo_Event);
     // Assign a eventhandler for the Recognition Event.
     objRecoContext.Recognition += new
         _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
     //Creating an instance of the grammer object.
     grammar = objRecoContext.CreateGrammar(0);
     label3.Text = "Speak Out one of the follwoing.\r\n1. New 2. Open 3. Close 4. Exit\r\n5. Cut 6. Copy 7. Paste 8. Delete";
     //Activate the Menu Commands.
     menuRule = grammar.Rules.Add("MenuCommands",SpeechRuleAttributes.SRATopLevel|SpeechRuleAttributes.SRADynamic,1);
     object      PropValue = "";
     menuRule.InitialState.AddWordTransition(null,"New"," ",SpeechGrammarWordType.SGLexical,"New", 1, ref PropValue, 1.0F );
     menuRule.InitialState.AddWordTransition(null,"Open"," ",SpeechGrammarWordType.SGLexical,"Open", 2, ref PropValue, 1.0F );
     menuRule.InitialState.AddWordTransition(null,"Close"," ",SpeechGrammarWordType.SGLexical,"Close",3, ref PropValue, 1.0F );
     menuRule.InitialState.AddWordTransition(null,"Exit"," ",SpeechGrammarWordType.SGLexical,"Exit",4, ref PropValue, 1.0F );
     menuRule.InitialState.AddWordTransition(null,"Cut"," ",SpeechGrammarWordType.SGLexical,"Cut",5, ref PropValue, 1.0F );
     menuRule.InitialState.AddWordTransition(null,"Copy"," ",SpeechGrammarWordType.SGLexical,"Copy",6, ref PropValue, 1.0F );
     menuRule.InitialState.AddWordTransition(null,"Paste"," ",SpeechGrammarWordType.SGLexical,"Paste",7, ref PropValue, 1.0F );
     menuRule.InitialState.AddWordTransition(null,"Delete"," ",SpeechGrammarWordType.SGLexical,"Delete",8, ref PropValue, 1.0F );
     menuRule.InitialState.AddWordTransition(null, "Continue", " ", SpeechGrammarWordType.SGLexical, "Continue", 9, ref PropValue, 1.0F);
     grammar.Rules.Commit();
     grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);
     label4.Text = "Speech Engine Ready for Input";
 }
 public void stopEngine()
 {
     menuRule = null;
     grammar = null;
     objRecoContext = null;
 }
Beispiel #29
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Title = "Select a Speech file";

            dialog.ShowDialog();

            _WAVFile = dialog.FileName;

            if (_WAVFile == null)
            {
                return;
            }

            //***********************************************

            // Now we have the WAV file, we can set up the

            // inline SPeech Engine to process it

            //***********************************************

            // create the recognition context

            wavRecoContext = new SpeechLib.SpInProcRecoContext();

            //******************************************************************

            // Register our event as a listener on the Recognition event

            // that way, anytime the speech engine thinks it "hears" something

            // that it recognize, we're called to check it out for ourselves

            //********************************************************************

            ((SpInProcRecoContext)wavRecoContext).Recognition +=

                new _ISpeechRecoContextEvents_RecognitionEventHandler(wavRecoContext_Recognition);

            //******************************************************************

            // Register a method on the endStream event so we can do basic clean-up

            // when the Audio file is finished

            //******************************************************************

            ((SpInProcRecoContext)wavRecoContext).EndStream += new _ISpeechRecoContextEvents_EndStreamEventHandler(wavRecoContext_EndStream);

            //*************************************************************************

            // the parameter passed to CreateGrammar is any int. It is only used as if

            // you have more than one grammar active, so you can specify which one is

            // to be used....

            //*************************************************************************

            Grammar = wavRecoContext.CreateGrammar(1);

            // I simply use the default Frammar for dictation

            Grammar.DictationLoad("", SpeechLoadOption.SLOStatic);

            //*************************************************************************

            //Speech engine is now ready to go, so set it to the

            // audio file TO do this, we open the requested file

            // using the SPeechStreamFileMode, and pass that to the

            // speech engine to use as its input source

            //*************************************************************************

            InputWAV = new SpFileStream();

            InputWAV.Open(@_WAVFile, SpeechStreamFileMode.SSFMOpenForRead, false);

            wavRecoContext.Recognizer.AudioInputStream = InputWAV;

            //*************************************************************************

            // the way you "Turn On" the speech engine is by setting the Diction State

            // of its grammar to "Active"

            //*************************************************************************

            Grammar.DictationSetState(SpeechRuleState.SGDSActive);

            //*************************************************************************

            // the result will be handled by wavRecoContext_Recognition()

            //*************************************************************************
        }