Esempio n. 1
0
        private void SreSpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            //This first release of the Kinect language pack doesn't have a reliable confidence model, so
            //we don't use e.Result.Confidence here.


            ProgessResponse pr = new ProgessResponse()
            {
                Confidence = e.Result.Confidence,
                Message    = e.Result.Text
            };

            //if (e.Result.Confidence > minimumConfidence)
            //{
            //    //backgroundWorker1.ReportProgress(0, String.Format("Speech Recognized: {0} confidence:{1}", e.Result.Text, e.Result.Confidence));



            if (!testingMode)
            {
                backgroundWorker1.ReportProgress(0, pr);
            }

            //}
            //else
            //{
            //    //backgroundWorker1.ReportProgress(0, String.Format("Speech NOT Recognized: {0} confidence:{1}", e.Result.Text, e.Result.Confidence));

            //}
        }
Esempio n. 2
0
        public void CallTestingMessage(string message)
        {// fake a particular message coming int, to facilitate testing
            testingMode = true;
            ProgessResponse pr = new ProgessResponse()
            {
                Confidence = 1,
                Message    = message
            };

            backgroundWorker1.ReportProgress(0, pr);
        }
Esempio n. 3
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            List <string>   words    = (List <string>)e.Argument;
            ProgessResponse response = new ProgessResponse()
            {
            };

            using (var source = new KinectAudioSource())
            {
                source.FeatureMode          = true;
                source.AutomaticGainControl = false;                        //Important to turn this off for speech recognition
                source.SystemMode           = SystemMode.OptibeamArrayOnly; //No AEC for this sample

                RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();

                if (ri == null)
                {
                    response.Message = "Could not find speech recognizer: {0}. Please refer to the sample requirements." + RecognizerId;
                    backgroundWorker1.ReportProgress(0, response);
                    return;
                }

                response.Message = "Using: {0}" + ri.Name;
                backgroundWorker1.ReportProgress(0, response);

                using (var sre = new SpeechRecognitionEngine(ri.Id))
                {
                    var wordChoices = new Choices();

                    foreach (string word in words)
                    {
                        wordChoices.Add(word);
                        //backgroundWorker1.ReportProgress(0, "added: " + word);
                    }


                    response.Message = "speech listener started";
                    backgroundWorker1.ReportProgress(0, response);



                    var gb = new GrammarBuilder();
                    //Specify the culture to match the recognizer in case we are running in a different culture.
                    gb.Culture = ri.Culture;
                    gb.Append(wordChoices);

                    // Create the actual Grammar instance, and then load it into the speech recognizer.
                    var g = new Grammar(gb);

                    sre.LoadGrammar(g);
                    sre.SpeechRecognized          += SreSpeechRecognized;
                    sre.SpeechHypothesized        += SreSpeechHypothesized;
                    sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected;

                    using (Stream s = source.Start())
                    {
                        sre.SetInputToAudioStream(s, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                        sre.RecognizeAsync(RecognizeMode.Multiple);

                        bool cancel = false;
                        while (cancel == false)
                        {
                            if (backgroundWorker1.CancellationPending)
                            {
                                // Set the e.Cancel flag so that the WorkerCompleted event
                                // knows that the process was cancelled.
                                e.Cancel = true;
                                cancel   = true;
                                break;
                            }

                            Thread.Sleep(10);
                        }
                        sre.RecognizeAsyncStop();
                    }
                }
            }
        }
Esempio n. 4
0
        public void MessageReceived(object sender, EventArgs e)
        {
            ProgessResponse response = kl.Message;



            if (response.Message == "move")
            {
                if (rightOn || testMode)
                {
                    txtMode.Background       = Brushes.Green;
                    modeIndicator.Background = Brushes.Green;
                    ListenMode   = response.Message;
                    txtMode.Text = ListenMode;
                }
                else
                {
                    txtMode.Background       = Brushes.Red;
                    modeIndicator.Background = Brushes.Red;
                    txtMode.Text             = "must have right hands up to move image";
                }
            }
            else if (response.Message == "scale")
            {
                if ((rightOn && leftOn) || testMode)
                {
                    txtMode.Background       = Brushes.Green;
                    ListenMode               = response.Message;
                    txtMode.Text             = ListenMode;
                    modeIndicator.Background = Brushes.Green;
                }
                else
                {
                    txtMode.Text             = "must have both hands up to scale";
                    txtMode.Background       = Brushes.Red;
                    modeIndicator.Background = Brushes.Red;
                }
            }
            else if (response.Message == "rotate")
            {
                if ((rightOn && leftOn) || testMode)
                {
                    txtMode.Background       = Brushes.Green;
                    modeIndicator.Background = Brushes.Green;
                    ListenMode   = response.Message;
                    txtMode.Text = ListenMode;
                }
                else
                {
                    txtMode.Text             = "must have both hands up to rotate";
                    txtMode.Background       = Brushes.Red;
                    modeIndicator.Background = Brushes.Red;
                }
            }

            else if (response.Message == "picture")
            {
                isVideo                  = false;
                image.Source             = video.Source;
                txtMode.Text             = "waiting on instructions: (" + response.Confidence + ")";
                ListenMode               = "stop";
                txtMode.Background       = Brushes.Blue;
                modeIndicator.Background = Brushes.Blue;
            }


            else if (response.Message == "video")
            {
                //image.Source = video.Source;
                txtMode.Text             = "waiting on instructions: (" + response.Confidence + ")";
                ListenMode               = "stop";
                txtMode.Background       = Brushes.Blue;
                isVideo                  = true;
                modeIndicator.Background = Brushes.Blue;
            }



            else
            {
                txtMode.Text             = "waiting on instructions: (" + response.Confidence + ")";
                ListenMode               = "stop";
                txtMode.Background       = Brushes.Blue;
                modeIndicator.Background = Brushes.Blue;
            }
        }