コード例 #1
0
ファイル: Program.cs プロジェクト: saveenr/saveenr
        private static void wreck_a_nice_beach()
        {
            var sre = new SSR.SpeechRecognitionEngine();
            sre.SetInputToDefaultAudioDevice();
            sre.UnloadAllGrammars();

            var gb1 = new SSR.GrammarBuilder();
            gb1.Append(new SSR.Choices("cut", "copy", "paste", "delete", "quit"));


            var g1 = new SSR.Grammar(gb1);
            sre.LoadGrammar(g1);

            sre.SpeechRecognized += SreOnSpeechRecognized;
            sre.SpeechDetected += SreOnSpeechDetected;
            sre.SpeechHypothesized += SreOnSpeechHypothesized;
            sre.SpeechRecognitionRejected += SreOnSpeechRecognitionRejected;
            sre.AudioSignalProblemOccurred += SreOnAudioSignalProblemOccurred;

            sre.RecognizeAsync(SSR.RecognizeMode.Multiple);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Hagser/csharp
        private void loadGrammar()
        {
            sre.UnloadAllGrammars();
            htWords.Clear();
            StreamReader sr = File.OpenText(strGrammarFile);
            int icnt = 0;
            while (!sr.EndOfStream && icnt <10000)
            {
                string strLine = sr.ReadLine();
                if (strLine != "")
                {
                    SSR.GrammarBuilder gb = new System.Speech.Recognition.GrammarBuilder();
                    gb.Append(strLine);
                    SSR.Grammar gram = new System.Speech.Recognition.Grammar(gb);
                    sre.LoadGrammar(gram);

                    htWords.Add(htWords.Count, strLine.ToLower());
                }
                icnt++;
            }
        }
コード例 #3
0
        private void loadGrammar()
        {
            sre.UnloadAllGrammars();
            htWords.Clear();
            StreamReader sr   = File.OpenText(strGrammarFile);
            int          icnt = 0;

            while (!sr.EndOfStream && icnt < 10000)
            {
                string strLine = sr.ReadLine();
                if (strLine != "")
                {
                    SSR.GrammarBuilder gb = new System.Speech.Recognition.GrammarBuilder();
                    gb.Append(strLine);
                    SSR.Grammar gram = new System.Speech.Recognition.Grammar(gb);
                    sre.LoadGrammar(gram);

                    htWords.Add(htWords.Count, strLine.ToLower());
                }
                icnt++;
            }
        }
コード例 #4
0
        private static void wreck_a_nice_beach()
        {
            var sre = new SSR.SpeechRecognitionEngine();

            sre.SetInputToDefaultAudioDevice();
            sre.UnloadAllGrammars();

            var gb1 = new SSR.GrammarBuilder();

            gb1.Append(new SSR.Choices("cut", "copy", "paste", "delete", "quit"));


            var g1 = new SSR.Grammar(gb1);

            sre.LoadGrammar(g1);

            sre.SpeechRecognized           += SreOnSpeechRecognized;
            sre.SpeechDetected             += SreOnSpeechDetected;
            sre.SpeechHypothesized         += SreOnSpeechHypothesized;
            sre.SpeechRecognitionRejected  += SreOnSpeechRecognitionRejected;
            sre.AudioSignalProblemOccurred += SreOnAudioSignalProblemOccurred;

            sre.RecognizeAsync(SSR.RecognizeMode.Multiple);
        }
コード例 #5
0
        private void SpeechToText()
        {
            // Configure the input to the recognizer.
            sre.SetInputToDefaultAudioDevice();

            // Create a simple grammar that recognizes "red", "green", or "blue".
            recog.Choices queries = new recog.Choices();
            queries.Add(dictionary);

            // Create a GrammarBuilder object and append the Choices object.
            recog.GrammarBuilder gb = new recog.GrammarBuilder();
            gb.Append(queries);

            // Create the Grammar instance and load it into the speech recognition engine.
            recog.Grammar g = new recog.Grammar(gb);
            sre.LoadGrammar(g);

            // Register a handler for the SpeechRecognized event.
            sre.SpeechRecognized += new EventHandler<recog.SpeechRecognizedEventArgs>(sre_SpeechRecognized);

            // Start recognition.
            sre.Recognize();
        }
コード例 #6
0
 private sp.Grammar GeneratePauseGrammar()
 {
     sp.Choices choices = new sp.Choices();
     foreach (string pausePhrase in this.currentProfile.PauseRecognitionPhrases)
     {
         sp.SemanticResultValue temp = new sp.SemanticResultValue(pausePhrase, "PauseVoiceRecognitionCommand");
         choices.Add(temp);
     }
     foreach (string unpausePhrase in this.currentProfile.UnpauseRecognitionPhrases)
     {
         sp.SemanticResultValue temp = new sp.SemanticResultValue(unpausePhrase, "UnpauseVoiceRecognitionCommand");
         choices.Add(temp);
     }
     sp.GrammarBuilder builder = new sp.GrammarBuilder();
     builder.Append(new sp.SemanticResultKey("command", choices));
     sp.Grammar grammar = new sp.Grammar(builder);
     grammar.Name = "PauseCommands";
     return grammar;
 }
コード例 #7
0
        public sp.Grammar UpdateGrammar()
        {
            bool atLeastOnePhrase = false;
            sp.Choices choices = new sp.Choices();
            foreach (Action action in this.Actions)
            {
                foreach (string phrase in action.Phrases)
                {
                    sp.SemanticResultValue temp = new sp.SemanticResultValue(phrase, action.ActionName);

                    choices.Add(temp);
                    atLeastOnePhrase = true;
                }
            }
            if (atLeastOnePhrase)
            {
                sp.GrammarBuilder builder = new sp.GrammarBuilder();
                builder.Append(new sp.SemanticResultKey("command", choices));
                this.Grammar = new sp.Grammar(builder);
                this.Grammar.Name = this.ProfileName;
                return this.Grammar;
            }
            else
                return null;
        }
コード例 #8
0
        public sp.Grammar UpdateGrammar()
        {
            sp.GrammarBuilder commands = new sp.GrammarBuilder();
            sp.Choices choices = new sp.Choices();
            foreach (Action action in this.Actions)
            {
                foreach (string phrase in action.Phrases)
                {
                    sp.SemanticResultValue temp = new sp.SemanticResultValue(phrase, action.ActionName);
                    choices.Add(temp);
                    commands.Append(temp);
                }
            }
            commands.Append(choices);

            sp.GrammarBuilder builder = new sp.GrammarBuilder();
            builder.Append(new sp.SemanticResultKey("command", choices));
            this.Grammar = new sp.Grammar(builder);
            this.Grammar.Name = this.ProfileName;
            return this.Grammar;
        }