void recognizer_SaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e) { switch (e.Verb) { case SpeechRecognizer.Verbs.Pause: dtwTextOutput.Text = "Pause"; player.Pause(); break; case SpeechRecognizer.Verbs.Resume: dtwTextOutput.Text = "Play"; player.Play(); break; case SpeechRecognizer.Verbs.Reset: dtwTextOutput.Text = "Reset"; player.Stop(); break; case SpeechRecognizer.Verbs.RandomColors: dtwTextOutput.Text = "Random Colors"; break; case SpeechRecognizer.Verbs.Colorize: dtwTextOutput.Text = "Colorize"; break; case SpeechRecognizer.Verbs.Bigger: dtwTextOutput.Text = "Bigger"; break; case SpeechRecognizer.Verbs.Quit: dtwTextOutput.Text = "Quit"; this.Close(); break; case SpeechRecognizer.Verbs.HideSkeleton: dtwTextOutput.Text = "Hide Skeleton"; skeletonCanvas.Visibility = Visibility.Hidden; break; case SpeechRecognizer.Verbs.HideDepth: dtwTextOutput.Text = "Hide Depth"; depthImage.Visibility = Visibility.Hidden; break; case SpeechRecognizer.Verbs.HideVideo: dtwTextOutput.Text = "Hide Video"; videoImage.Visibility = Visibility.Hidden; break; case SpeechRecognizer.Verbs.ShowSkeleton: dtwTextOutput.Text = "Show Skeleton"; skeletonCanvas.Visibility = Visibility.Visible; break; case SpeechRecognizer.Verbs.ShowDepth: dtwTextOutput.Text = "Show Depth"; depthImage.Visibility = Visibility.Visible; break; case SpeechRecognizer.Verbs.ShowVideo: dtwTextOutput.Text = "Show Video"; videoImage.Visibility = Visibility.Visible; break; case SpeechRecognizer.Verbs.PlayWildlife: dtwTextOutput.Text = "Play Wildlife Video"; videoMedia.Visibility = Visibility.Visible; videoMedia.Play(); break; case SpeechRecognizer.Verbs.StopWildlife: dtwTextOutput.Text = "Stop Wildlife Video"; videoMedia.Pause(); break; case SpeechRecognizer.Verbs.ResetWildlife: dtwTextOutput.Text = "Reset Wildlife Video"; videoMedia.Position = TimeSpan.FromSeconds(0); break; case SpeechRecognizer.Verbs.HideWildlife: dtwTextOutput.Text = "Hide Wildlife Video"; videoMedia.Pause(); videoMedia.Visibility = Visibility.Collapsed; break; } }
void MainWindow_Loaded(object sender, RoutedEventArgs e) { InitializeButtons(); // Setup osc sender oscArgs[0] = "127.0.0.1"; oscArgs[1] = "3333"; oscWriter = new UdpWriter(oscArgs[0], Convert.ToInt32(oscArgs[1])); //Since only a color video stream is needed, RuntimeOptions.UseColor is used. _runtime.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | Microsoft.Research.Kinect.Nui.RuntimeOptions.UseColor | RuntimeOptions.UseSkeletalTracking); _runtime.SkeletonEngine.TransformSmooth = true; //Use to transform and reduce jitter _runtime.SkeletonEngine.SmoothParameters = new TransformSmoothParameters { Smoothing = 0.5f, Correction = 0.3f, Prediction = 0.4f, JitterRadius = 0.05f, MaxDeviationRadius = 0.04f }; try { _runtime.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color); _runtime.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex); } catch (InvalidOperationException) { System.Windows.MessageBox.Show( "Failed to open stream. Please make sure to specify a supported image type and resolution."); return; } _lastTime = DateTime.Now; _dtw = new DtwGestureRecognizer(18, 0.6, 2, 2, 10); _video = new ArrayList(); //// If you want to see the depth image and frames per second then include this //// I'mma turn this off 'cos my 'puter is proper slow _runtime.DepthFrameReady += NuiDepthFrameReady; _runtime.SkeletonFrameReady += NuiSkeletonFrameReady; _runtime.SkeletonFrameReady += SkeletonExtractSkeletonFrameReady; //// If you want to see the RGB stream then include this //_runtime.VideoFrameReady += NuiColorFrameReady; Skeleton3DDataExtract.Skeleton3DdataCoordReady += NuiSkeleton3DdataCoordReady; speechRecognizer = SpeechRecognizer.Create(); //returns null if problem with speech prereqs or instantiation. if (speechRecognizer != null) { speechRecognizer.Start(new KinectAudioSource()); //KinectSDK TODO: expose Runtime.AudioSource to return correct audiosource. speechRecognizer.SaidSomething += new EventHandler<SpeechRecognizer.SaidSomethingEventArgs>(recognizer_SaidSomething); } else { dtwTextOutput.Text = "No Speech"; speechRecognizer = null; } }
void MainWindow_Unloaded(object sender, RoutedEventArgs e) { _isClosing = true; _runtime.Uninitialize(); if (speechRecognizer != null) { speechRecognizer.Stop(); speechRecognizer.SaidSomething -= new EventHandler<SpeechRecognizer.SaidSomethingEventArgs>(recognizer_SaidSomething); speechRecognizer = null; } Environment.Exit(0); }
//This method exists so that it can be easily called and return safely if the speech prereqs aren't installed. //We isolate the try/catch inside this class, and don't impose the need on the caller. public static SpeechRecognizer Create() { SpeechRecognizer recognizer = null; try { recognizer = new SpeechRecognizer(); } catch (Exception) { //speech prereq isn't installed. a null recognizer will be handled properly by the app. } return recognizer; }