/// <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) }
Gesture InitGesture = new Gesture(); // Needed for Editor's data bindings to come alive #endregion #region --- Initialization --- public MainWindow() { // Holla Kinect //note: must do before LoadPlugins, since the SpeechRecognition plugin's ISpeechRecognitionKinect implementation tries to start recognition feeding it with audio stream from Kinect kinect = KinectV1Utils.StartKinectSensor(); //GetKinectSensor(); //Kinect is also used for speech recognition if available, so starting at launch and stopping at end of app LoadPlugins(); RegisterCommands(); GestureCollection = new ObservableCollection <Gesture>(); InitializeComponent(); InitLocalization(); //must be called after "InitializeComponent" DependencyPropertyDescriptor.FromProperty(ItemsControl.ItemsSourceProperty, typeof(Controls.HotspotGrid)). AddValueChanged(FVGrid, (s, e) => { if (SVGrid.ItemsSource != null && FVGrid.ItemsSource != null) { SyncEditorGrids(); } }); DependencyPropertyDescriptor.FromProperty(ItemsControl.ItemsSourceProperty, typeof(Controls.HotspotGrid)). AddValueChanged(SVGrid, (s, e) => { if (SVGrid.ItemsSource != null && FVGrid.ItemsSource != null) { SyncEditorGrids(); } }); //EditorTipsOverlay.Visibility = Visibility.Visible; EditorOverlay.Visibility = Visibility.Visible; // KinectErrorStackPanel that displays errors & warnings is shown if Kinect isn't connected KinectErrorStackPanel.Visibility = (kinect == null)? Visibility.Visible : Visibility.Hidden; // Speak out about missing Kinect sensor if (kinect == null) { speechSynthesis?.Speak(GlblRes.ResourceManager.GetString("KinectNotDetected", speechSynthesis.Culture)); //speech culture may not be the same as UI culture if for example only en-US voices are available } LoadDefaultGestureCollection(); }