예제 #1
0
        private SpeechRecognition()
        {
            ssrContex = new SpSharedRecoContext();
            isrg      = ssrContex.CreateGrammar(1);
            _ISpeechRecoContextEvents_RecognitionEventHandler recHandle =
                new _ISpeechRecoContextEvents_RecognitionEventHandler(ContexRecognition);

            ssrContex.Recognition += recHandle;
        }
예제 #2
0
        private void startSpeech()
        {
            if (RecoContext == null)
            {
                RecoContext = new SpSharedRecoContext();
                grammar     = RecoContext.CreateGrammar(1);
                grammar.DictationLoad();
            }

            grammar.DictationSetState(SpeechRuleState.SGDSActive);    // Opens up diction possibility.
        }
예제 #3
0
        public CommandRecognizer()
        {
            m_context = new SpSharedRecoContext();

            // We want to know when a phrase is recognized and also when one fails to be recognized
            m_context.EventInterests = SpeechRecoEvents.SRERecognition | SpeechRecoEvents.SREFalseRecognition;
            m_context.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(RecognitionHandler);
            m_context.FalseRecognition += new _ISpeechRecoContextEvents_FalseRecognitionEventHandler(FailedRecognitionHandler);

            m_grammar = m_context.CreateGrammar(0);
            m_grammar.Reset(0);
        }
예제 #4
0
        /// <summary>
        /// Starts the listening
        /// </summary>
        public void Start()
        {
            recoContext              = new SpSharedRecoContextClass();
            recoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(recoContext_Recognition);

            recoGrammar     = recoContext.CreateGrammar(0);
            recoGrammarRule = recoGrammar.Rules.Add("VoiceCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);

            object propValue = "";

            for (int i = 0; i < commands.Count; i++)
            {
                recoGrammarRule.InitialState.AddWordTransition(null, commands[i].ToString(), " ", SpeechGrammarWordType.SGLexical, Commands[i].ToString(), i, ref propValue, 1.0F);
            }

            recoGrammar.Rules.Commit();
            recoGrammar.CmdSetRuleState("VoiceCommands", SpeechRuleState.SGDSActive);
        }
예제 #5
0
        public NamesFromSpeech(Form1 parent, List <string> names)
        {
            // SAPI 5.4 Overview: http://msdn.microsoft.com/en-us/library/ee125077%28v=vs.85%29.aspx
            // Some code from https://github.com/kring/Voodoo-Voice/blob/master/VoiceRecognition/CommandRecognizer.cs

            m_parent = parent;
            m_names  = new List <string>();

            m_context = new SpSharedRecoContext();
            m_context.EventInterests = SpeechRecoEvents.SRERecognition;
            m_context.Recognition   += context_Recognition;

            m_grammar = m_context.CreateGrammar();
            m_grammar.Reset();

            foreach (string name in names)
            {
                AddRuleForName(name);
            }

            CommitAndActivate();
        }
예제 #6
0
        static void Ma()
        {
            SpSharedRecoContext ssrc = new SpSharedRecoContext();
            SpeechLib.ISpeechRecoGrammar isrg = null;

             //       ssrc = // SpSharedRecoContextClass();

            ssrc.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(RecognitionEvent);

            isrg = ssrc.CreateGrammar(1);
            isrg.DictationLoad(null, SpeechLib.SpeechLoadOption.SLOStatic);
            isrg.DictationSetState(SpeechLib.SpeechRuleState.SGDSActive);
        }
        //private void initSpeech() {
        //    //Debug.WriteLine("Initializing SAPI");
        //    try {
        //        //create Main context Obj
        //        objRecoContext = new SpSharedRecoContext();
        //        objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(objRecoContext_Recognition);
        //        grammar = objRecoContext.CreateGrammar(0);
        //        string path = "Grammar.xml";
        //        grammar.CmdLoadFromFile(path, SpeechLoadOption.SLODynamic);
        //        //activate Top Level Rule
        //        grammar.CmdSetRuleIdState(0, SpeechRuleState.SGDSActive);
        //        //speechInitialized = true;
        //    } catch (Exception e) {
        //        logOut("Exception: " + e.ToString());
        //    }
        //}
        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

                grammar = objRecoContext.CreateGrammar(10);
                ruleTopLevel = grammar.Rules.Add("TopLevelRule", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
                ruleListItemsDefault = grammar.Rules.Add("ListItemsRule", SpeechRuleAttributes.SRADynamic, 2);

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

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

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

                voiceInfoAutomat.RebuildGrammar(this.grammar, this.speechEnabled, this.objRecoContext, ruleListItemsDefault);

                // 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");
            }
        }
예제 #8
0
        /// <summary>
        /// Starts the listening
        /// </summary>
        public void Start()
        {
            recoContext = new SpSharedRecoContextClass();
            recoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(recoContext_Recognition);

            recoGrammar = recoContext.CreateGrammar(0);
            recoGrammarRule = recoGrammar.Rules.Add("VoiceCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);

            object propValue = "";

            for (int i = 0; i < commands.Count; i++)
                recoGrammarRule.InitialState.AddWordTransition(null, commands[i].ToString(), " ", SpeechGrammarWordType.SGLexical, Commands[i].ToString(), i, ref propValue, 1.0F);

            recoGrammar.Rules.Commit();
            recoGrammar.CmdSetRuleState("VoiceCommands", SpeechRuleState.SGDSActive);
        }
        private void startSpeech()
        {
            if (RecoContext == null)
            {
                RecoContext = new SpSharedRecoContext();
                grammar = RecoContext.CreateGrammar(1);
                grammar.DictationLoad();
            }

            grammar.DictationSetState(SpeechRuleState.SGDSActive);    // Opens up diction possibility.
        }