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); } }
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
public DesktopSpeechRecognizer() { _recognizers = System.Speech.Recognition.SpeechRecognitionEngine.InstalledRecognizers().ToList(); var percentileChoices = new System.Speech.Recognition.Choices(); for (var i = 0; i <= 100; i++) { percentileChoices.Add(i.ToString()); } _choicesDictionary.Add("Percent", percentileChoices); _choicesDictionary.Add("Number", percentileChoices); var digitChoices = new System.Speech.Recognition.Choices(); for (var i = 0; i <= 10; i++) { digitChoices.Add(i.ToString()); } _choicesDictionary.Add("Digit", digitChoices); }
private void bVoice_Click(object sender, EventArgs e) { if (MonoCompat.IsMono) { Logger.Log(LogType.Warning, "Voice commands are for windows operating systems only"); return; } //if button was already clicked, cancel if (listening) { listening = false; bVoice.ForeColor = System.Drawing.Color.Black; return; } System.Speech.Recognition.SpeechRecognitionEngine engine = new System.Speech.Recognition.SpeechRecognitionEngine(); bVoice.ForeColor = System.Drawing.Color.Aqua; System.Speech.Recognition.Choices commands = new System.Speech.Recognition.Choices(); commands.Add(new string[] { "restart", "shutdown", "status report", "players", "help" }); System.Speech.Recognition.Grammar gr = new System.Speech.Recognition.Grammar(new System.Speech.Recognition.GrammarBuilder(commands)); try { listening = true; engine.RequestRecognizerUpdate(); engine.LoadGrammar(gr); engine.SpeechRecognized += engine_SpeechRecognized; engine.SetInputToDefaultAudioDevice(); engine.RecognizeAsync(System.Speech.Recognition.RecognizeMode.Multiple); engine.Recognize(); } catch { return; } }