Exemplo n.º 1
0
        private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e)
        {
            Program.UI.StartForm.labelSpeechCommand.Text = e.Matched;
            //FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), e.Matched);
            switch (e.Verb)
            {
                case SpeechRecognizer.Verbs.Faster:
                    if (frmDrive.RobotSpeed >= 0)
                    {
                        Program.UI.DriveForm.HandleKeys(Keys.Up);
                    }
                    else
                    {
                        Program.UI.DriveForm.HandleKeys(Keys.Down);
                    }
                    break;
                case SpeechRecognizer.Verbs.Slower:
                    if (frmDrive.RobotSpeed >= 0)
                    {
                        Program.UI.DriveForm.HandleKeys(Keys.Down);
                    }
                    else
                    {
                        Program.UI.DriveForm.HandleKeys(Keys.Up);
                    }
                    break;
                case SpeechRecognizer.Verbs.Left:
                    Program.UI.DriveForm.HandleKeys(Keys.Left);
                    break;
                case SpeechRecognizer.Verbs.Right:
                    Program.UI.DriveForm.HandleKeys(Keys.Right);
                    break;
                case SpeechRecognizer.Verbs.Forwards:
                case SpeechRecognizer.Verbs.Start:
                case SpeechRecognizer.Verbs.Go:
                    Program.UI.DriveForm.HandleKeys(Keys.Up);
                    break;
                case SpeechRecognizer.Verbs.Back:
                case SpeechRecognizer.Verbs.Backwards:
                case SpeechRecognizer.Verbs.Reverse:
                     Program.UI.DriveForm.HandleKeys(Keys.Down);
                   break;
                case SpeechRecognizer.Verbs.Stop:
                case SpeechRecognizer.Verbs.Halt:
                case SpeechRecognizer.Verbs.End:
                case SpeechRecognizer.Verbs.Reset:
                   Program.UI.DriveForm.HandleKeys(Keys.Space);
                   break;

                case SpeechRecognizer.Verbs.Pause:
                   SpeechRecognizer.paused = true;
                   MainForm.CRMainForm.checkBoxSpeech.Checked = false;
                   break;

                case SpeechRecognizer.Verbs.Resume:
                   SpeechRecognizer.paused = false;
                   MainForm.CRMainForm.checkBoxSpeech.Checked = true;
                   break;

                //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;
            }
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        private void start()
        {
            if (!this.DesignMode)
            {

                if (sensor == null)
                {
                    // 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 (See components in Toolkit Browser).
                    foreach (var potentialSensor in KinectSensor.KinectSensors)
                    {
                        this.textBox_sensorStatus.Text = "Searching...";
                        if (potentialSensor.Status == KinectStatus.Connected)
                        {
                            this.sensor = potentialSensor;
                            break;
                        }
                    }

                    if (null != this.sensor)
                    {
                        TransformSmoothParameters smoothingParam = new TransformSmoothParameters();

                        if (radioButton_smoothDefault.Checked)
                        {
                            // Some smoothing with little latency (defaults).
                            // Only filters out small jitters.
                            // Good for gesture recognition in games.
                            smoothingParam = new TransformSmoothParameters();
                            {
                                smoothingParam.Smoothing = 0.5f;
                                smoothingParam.Correction = 0.5f;
                                smoothingParam.Prediction = 0.5f;
                                smoothingParam.JitterRadius = 0.05f;
                                smoothingParam.MaxDeviationRadius = 0.04f;
                            };
                        }
                        else if (radioButton_smoothModerate.Checked)
                        {

                            // Smoothed with some latency.
                            // Filters out medium jitters.
                            // Good for a menu system that needs to be smooth but
                            // doesn't need the reduced latency as much as gesture recognition does.
                            smoothingParam = new TransformSmoothParameters();
                            {
                                smoothingParam.Smoothing = 0.5f;
                                smoothingParam.Correction = 0.1f;
                                smoothingParam.Prediction = 0.5f;
                                smoothingParam.JitterRadius = 0.1f;
                                smoothingParam.MaxDeviationRadius = 0.1f;
                            };
                        }
                        else if (radioButton_smoothIntense.Checked)
                        {
                            // Very smooth, but with a lot of latency.
                            // Filters out large jitters.
                            // Good for situations where smooth data is absolutely required
                            // and latency is not an issue.
                            smoothingParam = new TransformSmoothParameters();
                            {
                                smoothingParam.Smoothing = 0.7f;
                                smoothingParam.Correction = 0.3f;
                                smoothingParam.Prediction = 1.0f;
                                smoothingParam.JitterRadius = 1.0f;
                                smoothingParam.MaxDeviationRadius = 1.0f;
                            };
                        }
                        groupBox_smooth.Enabled = false;

                        // Turn on the stream to receive frames
                        this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                        this.sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                        this.sensor.SkeletonStream.Enable(smoothingParam);
                        this.sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Default; // SkeletonTrackingMode.Seated; // SkeletonTrackingMode.Default standing
                        this.sensor.SkeletonStream.EnableTrackingInNearRange = true;

                        // event handler to be called whenever there is new frame data
                        this.sensor.AllFramesReady += sensor_allFramesReady;

                        // Start the sensor!
                        try
                        {
                            this.sensor.Start();
                            this.textBox_sensorStatus.Text = "Stream started";

                            // 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);
                            }

                            _gestureController = new GestureController(GestureType.All);
                            _gestureController.GestureRecognized += GestureController_GestureRecognized;

                        }
                        catch (Exception)
                        {
                            this.sensor = null;
                            this.textBox_sensorStatus.Text = "Stream not started";
                        }
                    }
                    else
                    {
                        this.textBox_sensorStatus.Text = "Kinect not found";
                    }
                }
            }
        }