Пример #1
0
        /// <summary>
        /// Generates a new recognition operation from the speech recognizer, hooks up its completion handler, and
        /// updates state as needed for the duration of the recognition operation. Also checks any errors for
        /// known user-actionable steps, like accepting the privacy policy before using in-app recognition.
        /// </summary>
        private void StartListening()
        {
            try
            {
                // Start listening to the user and set up the completion handler for when the result
                this.CurrentRecognizerOperation           = this.Recognizer.RecognizeAsync();
                this.CurrentRecognizerOperation.Completed = recoCompletedAction;
                SetSearchState(SearchState.ListeningForInput);
                PlaySound("Assets/ListeningEarcon.wav");
            }
            catch (Exception recoException)
            {
                const int privacyPolicyHResult = unchecked ((int)0x80045509);

                if (recoException.HResult == privacyPolicyHResult)
                {
                    MessageBox.Show(AppResources.SpeechPrivacyPolicyError);
                }
                else
                {
                    PlaySound("Assets/CancelledEarcon.wav");
                    Debug.WriteLine(String.Format(
                                        AppResources.SpeechRecognitionErrorTemplate, recoException.HResult, recoException.Message));
                }

                recoCompletedAction.Invoke(null, AsyncStatus.Error);
            }
        }
        private void StartListening()
        {
            try
            {
                // Start listening to the user and set up the completion handler for when the result
                //*******************************************************************************************************
                //this fires when you press the button to start listening
                //*******************************************************************************************************
                this.CurrentRecognizerOperation           = this.Recognizer.RecognizeAsync();
                this.CurrentRecognizerOperation.Completed = recoCompletedAction;

                PlaySound("Assets/ListeningEarcon.wav");
                SearchTextBox.Text = "Listening...";

                EventsLst.Visibility  = System.Windows.Visibility.Collapsed;
                WaitBorder.Visibility = System.Windows.Visibility.Visible;
                WaitImg.Visibility    = System.Windows.Visibility.Visible;
                WaitTxt.Visibility    = System.Windows.Visibility.Visible;
                WaitTxt.Text          = "I await your command...";
            }
            catch (Exception recoException)
            {
                PlaySound("Assets/CancelledEarcon.wav");

                MessageBox.Show("Sorry, there was a problem with the voice system:  " +
                                recoException.Message);

                recoCompletedAction.Invoke(null, AsyncStatus.Error);
            }
        }