private void ExecuteEmulator() { try { var speechEngine = new SpeechEngine(); speechEngine.InitializeEmulator(CommandMode); if (String.IsNullOrEmpty(CommandText)) return; speechEngine.StartEmulatorRecognition(CommandText); speechEngine.SpeechProcessed += SpeechEngine_SpeechProcessed; } catch (Exception ex) { Log.ErrorLog(ex); ShowMessageBoxDetails(ex.Message, "Error", Visibility.Collapsed, MessageBoxIcon.Error); throw; } }
private void InitializeSpeechRecognizer() { try { var result = ""; SpeechRecognizerEngine = new SpeechEngine().CreateSpeechEngine("en-GB", out result); SpeechRecognizerEngine.LoadGrammar(new DictationGrammar()); SpeechRecognizerEngine.LoadGrammar(new SpeechEngine().GetSpellingGrammar()); SpeechRecognizerEngine.LoadGrammar(new SpeechEngine().GetWebSiteNamesGrammar()); SpeechRecognizerEngine.AudioLevelUpdated += SpeechRecognizerEngine_AudioLevelUpdated; SpeechRecognizerEngine.SpeechRecognized += SpeechRecognizerEngine_SpeechRecognized; // use the system's default microphone SpeechRecognizerEngine.SetInputToDefaultAudioDevice(); // start listening SpeechRecognizerEngine.RecognizeAsync(RecognizeMode.Multiple); } catch (Exception ex) { Log.ErrorLog(ex); ShowMessageBoxDetails(ex.Message, "Error", Visibility.Collapsed, MessageBoxIcon.Error); throw; } }
private void SpeechRecognizerEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { try { if (e.Result.Confidence >= 0.7) { var resultDictionary = new SpeechEngine().InitializeSpeechProcessing(e.Result.Text); StartCommandExecution(resultDictionary); } else { ShowMessageBoxDetails("Your words cannot be recognized properly!", "Information", Visibility.Visible, MessageBoxIcon.Information); } } catch (Exception ex) { Log.ErrorLog(ex); ShowMessageBoxDetails(ex.Message, "Error", Visibility.Collapsed, MessageBoxIcon.Error); throw; } }