private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e) { FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), e.Matched); switch (e.Verb) { case SpeechRecognizer.Verbs.Pause: this.myFallingThings.SetDropRate(0); this.myFallingThings.SetGravity(0); break; case SpeechRecognizer.Verbs.Resume: this.myFallingThings.SetDropRate(this.dropRate); this.myFallingThings.SetGravity(this.dropGravity); break; case SpeechRecognizer.Verbs.Reset: this.dropRate = DefaultDropRate; this.dropSize = DefaultDropSize; this.dropGravity = DefaultDropGravity; this.myFallingThings.SetPolies(PolyType.All); this.myFallingThings.SetDropRate(this.dropRate); this.myFallingThings.SetGravity(this.dropGravity); this.myFallingThings.SetSize(this.dropSize); this.myFallingThings.SetShapesColor(System.Windows.Media.Color.FromRgb(0, 0, 0), true); this.myFallingThings.Reset(); break; case SpeechRecognizer.Verbs.DoShapes: this.myFallingThings.SetPolies(e.Shape); break; case SpeechRecognizer.Verbs.RandomColors: this.myFallingThings.SetShapesColor(System.Windows.Media.Color.FromRgb(0, 0, 0), true); break; case SpeechRecognizer.Verbs.Colorize: this.myFallingThings.SetShapesColor(e.RgbColor, false); break; case SpeechRecognizer.Verbs.ShapesAndColors: this.myFallingThings.SetPolies(e.Shape); this.myFallingThings.SetShapesColor(e.RgbColor, false); break; case SpeechRecognizer.Verbs.More: this.dropRate *= 1.5; this.myFallingThings.SetDropRate(this.dropRate); break; case SpeechRecognizer.Verbs.Fewer: this.dropRate /= 1.5; this.myFallingThings.SetDropRate(this.dropRate); break; case SpeechRecognizer.Verbs.Bigger: this.dropSize *= 1.5; if (this.dropSize > MaxShapeSize) { this.dropSize = MaxShapeSize; } this.myFallingThings.SetSize(this.dropSize); break; case SpeechRecognizer.Verbs.Biggest: this.dropSize = MaxShapeSize; this.myFallingThings.SetSize(this.dropSize); break; case SpeechRecognizer.Verbs.Smaller: this.dropSize /= 1.5; if (this.dropSize < MinShapeSize) { this.dropSize = MinShapeSize; } this.myFallingThings.SetSize(this.dropSize); break; case SpeechRecognizer.Verbs.Smallest: this.dropSize = MinShapeSize; this.myFallingThings.SetSize(this.dropSize); break; case SpeechRecognizer.Verbs.Faster: this.dropGravity *= 1.25; if (this.dropGravity > 4.0) { this.dropGravity = 4.0; } this.myFallingThings.SetGravity(this.dropGravity); break; case SpeechRecognizer.Verbs.Slower: this.dropGravity /= 1.25; if (this.dropGravity < 0.25) { this.dropGravity = 0.25; } this.myFallingThings.SetGravity(this.dropGravity); break; } }
// Kinect enabled apps should customize which Kinect services it initializes here. private void InitializeKinectServices(KinectSensorManager kinectSensorManager, KinectSensor sensor) { // Application should enable all streams first. kinectSensorManager.ColorFormat = ColorImageFormat.RgbResolution640x480Fps30; kinectSensorManager.ColorStreamEnabled = true; sensor.SkeletonFrameReady += this.SkeletonsReady; kinectSensorManager.TransformSmoothParameters = new TransformSmoothParameters { Smoothing = 0.5f, Correction = 0.5f, Prediction = 0.5f, JitterRadius = 0.05f, MaxDeviationRadius = 0.04f }; kinectSensorManager.SkeletonStreamEnabled = true; kinectSensorManager.KinectSensorEnabled = true; if (!kinectSensorManager.KinectSensorAppConflict) { // Start speech recognizer after KinectSensor started successfully. this.mySpeechRecognizer = SpeechRecognizer.Create(); if (null != this.mySpeechRecognizer) { this.mySpeechRecognizer.SaidSomething += this.RecognizerSaidSomething; this.mySpeechRecognizer.Start(sensor.AudioSource); } enableAec.Visibility = Visibility.Visible; this.UpdateEchoCancellation(this.enableAec); } }
// Kinect enabled apps should uninitialize all Kinect services that were initialized in InitializeKinectServices() here. private void UninitializeKinectServices(KinectSensor sensor) { sensor.SkeletonFrameReady -= this.SkeletonsReady; if (null != this.mySpeechRecognizer) { this.mySpeechRecognizer.Stop(); this.mySpeechRecognizer.SaidSomething -= this.RecognizerSaidSomething; this.mySpeechRecognizer.Dispose(); this.mySpeechRecognizer = null; } enableAec.Visibility = Visibility.Collapsed; }
void recognizer_SaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e) { FlyingText.NewFlyingText(screenRect.Width / 30, new Point(screenRect.Width / 2, screenRect.Height / 2), e.Matched); switch (e.Verb) { case SpeechRecognizer.Verbs.Pause: fallingThings.SetDropRate(0); fallingThings.SetGravity(0); break; case SpeechRecognizer.Verbs.Resume: fallingThings.SetDropRate(dropRate); fallingThings.SetGravity(dropGravity); break; case SpeechRecognizer.Verbs.Reset: dropRate = DefaultDropRate; dropSize = DefaultDropSize; dropGravity = DefaultDropGravity; fallingThings.SetPolies(PolyType.All); fallingThings.SetDropRate(dropRate); fallingThings.SetGravity(dropGravity); fallingThings.SetSize(dropSize); fallingThings.SetShapesColor(Color.FromRgb(0, 0, 0), true); fallingThings.Reset(); break; case SpeechRecognizer.Verbs.DoShapes: fallingThings.SetPolies(e.Shape); break; case SpeechRecognizer.Verbs.RandomColors: fallingThings.SetShapesColor(Color.FromRgb(0, 0, 0), true); break; case SpeechRecognizer.Verbs.Colorize: fallingThings.SetShapesColor(e.RGBColor, false); break; case SpeechRecognizer.Verbs.ShapesAndColors: fallingThings.SetPolies(e.Shape); fallingThings.SetShapesColor(e.RGBColor, false); break; case SpeechRecognizer.Verbs.More: dropRate *= 1.5; fallingThings.SetDropRate(dropRate); break; case SpeechRecognizer.Verbs.Fewer: dropRate /= 1.5; fallingThings.SetDropRate(dropRate); break; case SpeechRecognizer.Verbs.Bigger: dropSize *= 1.5; if (dropSize > MaxShapeSize) dropSize = MaxShapeSize; fallingThings.SetSize(dropSize); break; case SpeechRecognizer.Verbs.Biggest: dropSize = MaxShapeSize; fallingThings.SetSize(dropSize); break; case SpeechRecognizer.Verbs.Smaller: dropSize /= 1.5; if (dropSize < MinShapeSize) dropSize = MinShapeSize; fallingThings.SetSize(dropSize); break; case SpeechRecognizer.Verbs.Smallest: dropSize = MinShapeSize; fallingThings.SetSize(dropSize); break; case SpeechRecognizer.Verbs.Faster: dropGravity *= 1.25; if (dropGravity > 4.0) dropGravity = 4.0; fallingThings.SetGravity(dropGravity); break; case SpeechRecognizer.Verbs.Slower: dropGravity /= 1.25; if (dropGravity < 0.25) dropGravity = 0.25; fallingThings.SetGravity(dropGravity); break; } }
// 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; }
//Kinect enabled apps should customize which Kinect services it initializes here. private void InitializeKinectServices(Runtime runtime) { runtimeOptions = RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor; //KinectSDK TODO: should be able to understand a Kinect used by another app without having to try/catch. try { Kinect.Initialize(runtimeOptions); } catch (COMException comException) { //TODO: make CONST if (comException.ErrorCode == -2147220947) //Runtime is being used by another app. { Kinect = null; ShowStatus(ErrorCondition.KinectAppConflict); return; } else { throw comException; } } kinectViewer.RuntimeOptions = runtimeOptions; kinectViewer.Kinect = Kinect; Kinect.SkeletonEngine.TransformSmooth = true; Kinect.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(SkeletonsReady); 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 { ShowStatus(ErrorCondition.NoSpeech); speechRecognizer = null; } }
//Kinect enabled apps should uninitialize all Kinect services that were initialized in InitializeKinectServices() here. private void UninitializeKinectServices(Runtime runtime) { Kinect.Uninitialize(); kinectViewer.Kinect = null; Kinect.SkeletonFrameReady -= new EventHandler<SkeletonFrameReadyEventArgs>(SkeletonsReady); if (speechRecognizer != null) { speechRecognizer.Stop(); speechRecognizer.SaidSomething -= new EventHandler<SpeechRecognizer.SaidSomethingEventArgs>(recognizer_SaidSomething); speechRecognizer = null; } }
private void StopKinect(KinectSensor sensor) { if (sensor != null) { if (sensor.IsRunning) { //stop sensor sensor.Stop(); //stop audio if not null if (sensor.AudioSource != null) { sensor.AudioSource.Stop(); } if (this.mySpeechRecognizer != null) { this.mySpeechRecognizer.Stop(); this.mySpeechRecognizer.SaidSomething -= this.RecognizerSaidSomething; this.mySpeechRecognizer.Dispose(); this.mySpeechRecognizer = null; } } } }
private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e) { }
private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e) { //should this be moved to allframesready? if (serve == false) { switch (e.Verb) { case SpeechRecognizer.Verbs.Serve: ellipse1.Height = 45; ellipse1.Width = 45; ellipse1.Opacity = 1; firsthit = true; serve = true; break; case SpeechRecognizer.Verbs.OneLeft: if (p1righty == true) { p1racket.RenderTransform = rotatetransform1; } p1righty = false; break; case SpeechRecognizer.Verbs.OneRight: if (p1righty == false) { p1racket.RenderTransform = rotatetransform2; } p1righty = true; break; case SpeechRecognizer.Verbs.TwoLeft: if (p2righty == true) { p2racket.RenderTransform = rotatetransform1; } p2righty = false; break; case SpeechRecognizer.Verbs.TwoRight: if (p2righty == false) { p2racket.RenderTransform = rotatetransform2; } p2righty = true; break; } } }
void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e) { KinectSensor old = (KinectSensor)e.OldValue; StopKinect(old); KinectSensor sensor = (KinectSensor)e.NewValue; if (sensor == null) { return; } var parameters = new TransformSmoothParameters { Smoothing = 0.3f, Correction = 0.0f, Prediction = 0.0f, JitterRadius = 1.0f, MaxDeviationRadius = 0.5f }; sensor.SkeletonStream.Enable(parameters); sensor.SkeletonStream.Enable(); sensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(sensor_AllFramesReady); sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30); sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); try { sensor.Start(); } catch (System.IO.IOException) { kinectSensorChooser1.AppConflictOccurred(); } this.mySpeechRecognizer = SpeechRecognizer.Create(); this.mySpeechRecognizer.SaidSomething += this.RecognizerSaidSomething; this.mySpeechRecognizer.Start(sensor.AudioSource); }
// Kinect enabled apps should customize which Kinect services it initializes here. private KinectSensor InitializeKinectServices(KinectSensor sensor) { // Application should enable all streams first. sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); sensor.SkeletonFrameReady += this.SkeletonsReady; sensor.SkeletonStream.Enable(new TransformSmoothParameters() { Smoothing = 0.5f, Correction = 0.5f, Prediction = 0.5f, JitterRadius = 0.05f, MaxDeviationRadius = 0.04f }); try { sensor.Start(); } catch (IOException) { SensorChooser.AppConflictOccurred(); return null; } // Start speech recognizer after KinectSensor.Start() is called // returns null if problem with speech prereqs or instantiation. this.mySpeechRecognizer = SpeechRecognizer.Create(); this.mySpeechRecognizer.SaidSomething += this.RecognizerSaidSomething; this.mySpeechRecognizer.Start(sensor.AudioSource); enableAec.Visibility = Visibility.Visible; this.UpdateEchoCancellation(this.enableAec); return sensor; }
void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e) { KinectSensor oldSensor = (KinectSensor)e.OldValue; StopKinect(oldSensor); KinectSensor newSensor = (KinectSensor)e.NewValue; if (newSensor == null) { noticeBox.Text = "sensor is null?"; return; } var parameters = new TransformSmoothParameters { Smoothing = 0.3f, Correction = 0.0f, Prediction = 0.0f, JitterRadius = 1.0f, MaxDeviationRadius = 0.5f }; newSensor.SkeletonStream.Enable(parameters); // sensor.SkeletonStream.Enable(); newSensor.ColorStream.Enable(); newSensor.DepthStream.Enable(); // newSensor.SkeletonStream.Enable(); newSensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(newSensor_AllFramesReady); try { newSensor.Start(); } catch (System.IO.IOException) { kinectSensorChooser1.AppConflictOccurred(); } // Start speech recognizer after KinectSensor.Start() is called // returns null if problem with speech prereqs or instantiation. this.mySpeechRecognizer = SpeechRecognizer.Create(); this.mySpeechRecognizer.SaidSomething += this.RecognizerSaidSomething; this.mySpeechRecognizer.Start(newSensor.AudioSource); }
private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e) { switch (e.Verb) { // Tell the app what to do when it gets the verb case SpeechRecognizer.Verbs.Next: //Example, just shows a picture when you say "next" if (curPage == pageName.videoAndPractice) { playListTransition(transitionCode.normal); } break; case SpeechRecognizer.Verbs.Back: if (curPage == pageName.videoAndPractice && positionInPlaylist != -1) { playListTransition(transitionCode.back); } else { transition(transitionCode.back); } break; case SpeechRecognizer.Verbs.Stop: if (curPage == pageName.videoAndPractice) { poseVideoPlayer.Stop(); } break; case SpeechRecognizer.Verbs.Play: if (curPage == pageName.videoAndPractice) { poseVideoPlayer.Play(); } break; case SpeechRecognizer.Verbs.Restart: if (curPage == pageName.videoAndPractice) { poseVideoPlayer.Stop(); poseVideoPlayer.Play(); } break; case SpeechRecognizer.Verbs.Help: displayHelp(curPage); break; case SpeechRecognizer.Verbs.Quit: StopKinect(kinectSensorChooser1.Kinect); this.Close(); break; case SpeechRecognizer.Verbs.Pause: if (curPage == pageName.videoAndPractice) { poseVideoPlayer.Pause(); } break; case SpeechRecognizer.Verbs.Analyze: if (curPage == pageName.videoAndPractice) { poseFeedBack(); } break; default: break; } }