/// <summary> /// Execute initialization tasks. /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void WindowLoaded(object sender, RoutedEventArgs e) { // Look through all sensors and start the first connected one. // This requires that a Kinect is connected at the time of app startup. // To make your app robust against plug/unplug, // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (null != this.sensor) { try { // Start the sensor! this.sensor.Start(); leftHandUp = new LeftHandUp(); rightHandUp = new RightHandUp(); swipeLeftSeg1 = new SwipeLeftSegment1(); swipeLeftSeg2 = new SwipeLeftSegment2(); swipeRightSeg1 = new SwipeRightSegment1(); swipeRightSeg2 = new SwipeRightSegment2(); leftHandForward = new LeftHandForward(); rightHandForward = new RightHandForward(); swipeDown = new SwipeDown(); viewModel = new SkeletonViewModel(); viewModel.GestureRecognized += new EventHandler<GestureEventArgs>(this.GestureRecognized); sensor.SkeletonStream.Enable(); } catch (IOException) { // Some other application is streaming from the same Kinect sensor this.sensor = null; } } if (null == this.sensor) { this.statusBarText.Text = Properties.Resources.NoKinectReady; return; } RecognizerInfo ri = GetKinectRecognizer(); if (null != ri) { recognitionSpans = new List<Span> { mercurySpan, venusSpan, earthSpan, marsSpan, jupiterSpan, saturnSpan, uranusSpan, neptuneSpan, plutoSpan, sunSpan }; this.speechEngine = new SpeechRecognitionEngine(ri.Id); /**************************************************************** * * Use this code to create grammar programmatically rather than from * a grammar file. * * var directions = new Choices(); * directions.Add(new SemanticResultValue("forward", "FORWARD")); * directions.Add(new SemanticResultValue("forwards", "FORWARD")); * directions.Add(new SemanticResultValue("straight", "FORWARD")); * directions.Add(new SemanticResultValue("backward", "BACKWARD")); * directions.Add(new SemanticResultValue("backwards", "BACKWARD")); * directions.Add(new SemanticResultValue("back", "BACKWARD")); * directions.Add(new SemanticResultValue("turn left", "LEFT")); * directions.Add(new SemanticResultValue("turn right", "RIGHT")); * * var gb = new GrammarBuilder { Culture = ri.Culture }; * gb.Append(directions); * * var g = new Grammar(gb); * ****************************************************************/ // Create a grammar from grammar definition XML file. using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Properties.Resources.SpeechGrammar))) { var g = new Grammar(memoryStream); speechEngine.LoadGrammar(g); } speechEngine.SpeechRecognized += SpeechRecognized; speechEngine.SpeechRecognitionRejected += SpeechRejected; speechEngine.SetInputToAudioStream( sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null)); speechEngine.RecognizeAsync(RecognizeMode.Multiple); } else { this.statusBarText.Text = Properties.Resources.NoSpeechRecognizer; } sensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(sensor_AllFramesReady); }
private void DefineGestures() { //swipe right IRelativeGestureSegment[] swipeRightSegments = new IRelativeGestureSegment[4]; SwipeRightSegment1 swipeRightSegment1 = new SwipeRightSegment1(); SwipeRightSegment2 swipeRightSegment2 = new SwipeRightSegment2(); RightHandUp rightHandUp = new RightHandUp(); swipeRightSegments[0] = rightHandUp; swipeRightSegments[1] = swipeRightSegment1; swipeRightSegments[2] = rightHandUp; swipeRightSegments[3] = swipeRightSegment2; this.gestures.AddGesture(GestureType.RightSwipe, swipeRightSegments); //swipe left IRelativeGestureSegment[] swipeLeftSegments = new IRelativeGestureSegment[4]; SwipeLeftSegment1 swipeLeftSegment1 = new SwipeLeftSegment1(); SwipeLeftSegment2 swipeLeftSegment2 = new SwipeLeftSegment2(); LeftHandUp leftHandUp = new LeftHandUp(); swipeLeftSegments[0] = leftHandUp; swipeLeftSegments[1] = swipeLeftSegment1; swipeLeftSegments[2] = leftHandUp; swipeLeftSegments[3] = swipeLeftSegment2; this.gestures.AddGesture(GestureType.LeftSwipe, swipeLeftSegments); //swipe down IRelativeGestureSegment[] swipeDownSegments = new IRelativeGestureSegment[1]; SwipeDown swipeDown = new SwipeDown(); swipeDownSegments[0] = swipeDown; this.gestures.AddGesture(GestureType.SwipeDown, swipeDownSegments); //Right up IRelativeGestureSegment[] rightUpSegments = new IRelativeGestureSegment[1]; RightHandUp rightUp = new RightHandUp(); rightUpSegments[0] = rightUp; this.gestures.AddGesture(GestureType.RightUp, rightUpSegments); }