private void StartSpeechRecognition() { if (speechRecognition == null) { return; } try { string grammarsFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Grammars", "SRGS"); speechRecognition.LoadGrammar(new FileStream(Path.Combine(grammarsFolder, "TrackingCam_en.xml"), FileMode.Open), "TrackingCam"); speechRecognition.Recognized += SpeechRecognition_Recognized; speechRecognition.NotRecognized += SpeechRecognition_NotRecognized; /* * //For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model. * //This will prevent recognition accuracy from degrading over time. * speechRecognition.AcousticModelAdaptation = false; */ speechRecognition.Start(); } catch (Exception e) { speechRecognitionKinect = null; speechRecognition = null; MessageBox.Show(e.Message); } }
/// <summary> /// Execute initialization tasks. /// </summary> protected void Init() { ShowPenColor(); // This requires that a Kinect is connected at the time of app startup. // To make the app robust against plug/unplug, // Microsoft recommends using KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser). if (KinectV1Utils.StartKinectSensor() == null) { statusBarText.Text = Properties.Resources.NoKinectReady; imgKinect.Visibility = Visibility.Hidden; } else { statusBarText.Text = Properties.Resources.KinectReady; imgKinect.Visibility = Visibility.Visible; } speechSynthesis = new SpeechSynthesis(); speechRecognition = new SpeechRecognitionKinectV1(); //will fallback to same engine used by SpeechRecognition class automatically if it can't find Kinect V1 sensor speechRecognition.LoadGrammar(Properties.Resources.SpeechGrammar_en, "Main"); //could use SpeechGrammar_en.Create() to generate the grammar programmatically instead of loading it from an XML (resource) file speechRecognition.LoadGrammar(SpeechRecognitionUtils.CreateGrammarFromNames(ColorUtils.GetKnownColorNames(), "en", "Colors")); //setup recognition event handlers speechRecognition.Recognized += SpeechRecognition_Recognized; speechRecognition.NotRecognized += SpeechRecognition_NotRecognized; // For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model. // This will prevent recognition accuracy from degrading over time. //// speechRecognition.AcousticModelAdaptation = false; speechRecognition.Start(); //start speech recognition (set to keep on firing speech recognition events, not just once) }
/// <summary> /// Starts the speech recognition. /// </summary> protected void StartSpeechRecognition() //called by LoadSpeechRecognitionPlugin { if (speechRecognition == null) { return; } try { LoadSpeechRecognitionGrammarsForUI(); LoadSpeechRecognitionGrammarForGestureCollection(); GestureCollectionLoaded += MainWindow_GestureCollectionLoaded; speechRecognition.Recognized += SpeechRecognition_Recognized; speechRecognition.NotRecognized += SpeechRecognition_NotRecognized; /* * //For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model. * //This will prevent recognition accuracy from degrading over time. * speechRecognition.AcousticModelAdaptation = false; */ speechRecognition.Start(); } catch (Exception e) { speechRecognition = null; MessageBox.Show(e.Message); } }