Choreoh.MainWindow.CreateSpeechRecognizerPreRecording C# (CSharp) Метод

CreateSpeechRecognizerPreRecording() приватный Метод

private CreateSpeechRecognizerPreRecording ( ) : SpeechRecognitionEngine
Результат SpeechRecognitionEngine
        private SpeechRecognitionEngine CreateSpeechRecognizerPreRecording()
        {
            {
                #region Initialization
                RecognizerInfo ri = GetKinectRecognizer();
                if (ri == null)
                {
                    MessageBox.Show(
                        @"There was a problem initializing Speech Recognition.
                    Ensure you have the Microsoft Speech SDK installed.",
                        "Failed to load Speech SDK",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    this.Close();
                    return null;
                }

                SpeechRecognitionEngine sre;
                try
                {
                    sre = new SpeechRecognitionEngine(ri.Id);
                }
                catch
                {
                    MessageBox.Show(
                        @"There was a problem initializing Speech Recognition.
                    Ensure you have the Microsoft Speech SDK installed and configured.",
                        "Failed to load Speech SDK",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    this.Close();
                    return null;
                }
                #endregion

                #region Build grammar

                var preRecordingChoices = new Choices(new string[] { "start" });

                var gb = new GrammarBuilder { Culture = ri.Culture };
                gb.Append(preRecordingChoices);

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

                sre.LoadGrammar(g);

                #endregion

                #region Hook up events
                sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_PreSpeechRecognized);

                #endregion

                return sre;
            }
        }