示例#1
0
        public void Start()
        {
            var _commands = Commands;

            //if (IncludeCommonWords)
            //{
            //    if (string.IsNullOrEmpty(_commands)) _commands = Extensions.GetStringFromResource(typeof(MSSpeechPlugin), "commands.txt");
            //    if (!string.IsNullOrEmpty(_commands)) _commands += "\n" + Extensions.GetStringFromResource(typeof(MSSpeechPlugin), "commands.txt");
            //}
            if (!string.IsNullOrEmpty(_commands) || IncludeCommonWords)
            {
                var gBuilder = new System.Speech.Recognition.GrammarBuilder();
                //if (IncludeCommonWords)
                //{
                //    gBuilder.AppendDictation();
                //}
                if (!string.IsNullOrEmpty(_commands))
                {
                    var commands = new System.Speech.Recognition.Choices();
                    var array    = _commands.Split(new char[] { '\n', '\r' }).Where(x => !string.IsNullOrEmpty(x)).ToArray();
                    commands.Add(array);
                    gBuilder.Append(commands);
                }
                if (IncludeCommonWords)
                {
                    gBuilder.AppendDictation();
                }
                var grammer = new System.Speech.Recognition.Grammar(gBuilder);
                recEngine.UnloadAllGrammars();
                recEngine.LoadGrammarAsync(grammer);
                recEngine.RecognizeAsync(System.Speech.Recognition.RecognizeMode.Multiple);
            }
        }
示例#2
0
        public static void Test()
        {
            System.Speech.Recognition.SpeechRecognitionEngine recEngine = new System.Speech.Recognition.SpeechRecognitionEngine();
            recEngine.SetInputToDefaultAudioDevice();

            System.Speech.Recognition.Choices commands = new System.Speech.Recognition.Choices();
            commands.Add(new string[] { "say Hi", "say Hello" });
            System.Speech.Recognition.GrammarBuilder gb = new System.Speech.Recognition.GrammarBuilder();
            gb.Append(commands);
            System.Speech.Recognition.Grammar g = new System.Speech.Recognition.Grammar(gb);

            recEngine.LoadGrammarAsync(g);
            recEngine.RecognizeAsync(System.Speech.Recognition.RecognizeMode.Multiple);

            recEngine.SpeechRecognized += OnSpeechRecognized;
        } // End Sub Test