コード例 #1
0
        private void SpeechRecognitionEngine_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)
        {
            systemLog.DebugFormat("{0} Recognize completed", prefix);
            //systemLog.DebugFormat("  Babble timeout: {0}", e.BabbleTimeout);
            //systemLog.DebugFormat("  Cancelled: {0}", e.Cancelled);
            //systemLog.DebugFormat("  Error: {0}", e.Error?.Message);
            //systemLog.DebugFormat("  Initial Silence Timeout: {0}", e.InitialSilenceTimeout);
            //systemLog.DebugFormat("  Input Stream Ended: {0}", e.InputStreamEnded);

            if (e.Error != null)
            {
                systemLog.Error(prefix + " " + e.Error.Message, e.Error);
            }

            stream = null;
        }
コード例 #2
0
        public void Start()
        {
            foreach (RecognizerInfo config in SpeechRecognitionEngine.InstalledRecognizers())
            {
                if (config.Culture.ToString() == "en-US")
                {
                    speechRecognitionEngine = new SpeechRecognitionEngine(config);
                    break;
                }
            }

            if (speechRecognitionEngine == null)
            {
            }

            stream = new SpeechStream(65536);

            //var choices = new Choices();
            //choices.Add(new string[] { "hello", "test", "one", "two", "three" });

            //var builder = new GrammarBuilder();
            //builder.Append(choices);

            speechRecognitionEngine.InitialSilenceTimeout = new TimeSpan(0, 0, 1);
            speechRecognitionEngine.LoadGrammar(new DictationGrammar());
            //speechRecognitionEngine.LoadGrammar(new Grammar(builder));
            //speechRecognitionEngine.AudioLevelUpdated          += (s, e) => { systemLog.DebugFormat("{0} Audio level updated to {1}", prefix, e.AudioLevel); };
            //speechRecognitionEngine.AudioSignalProblemOccurred += (s, e) => { systemLog.DebugFormat("{0} Audio signal problem occurred; {1}", prefix, e.AudioSignalProblem.ToString());  };
            //speechRecognitionEngine.AudioStateChanged          += (s, e) => { systemLog.DebugFormat("{0} Audio state changed to {1}", prefix, e.AudioState.ToString()); };
            speechRecognitionEngine.RecognizeCompleted += SpeechRecognitionEngine_RecognizeCompleted;
            speechRecognitionEngine.SpeechRecognized   += SpeechRecognitionEngine_SpeechRecognized;
            //speechRecognitionEngine.SpeechDetected             += (s, e) => { systemLog.DebugFormat("{0} Speech detected", prefix); };
            //speechRecognitionEngine.SpeechRecognitionRejected  += (s, e) => { systemLog.DebugFormat("{0} Speech recognition rejected", prefix); };
            //speechRecognitionEngine.SpeechHypothesized         += (s, e) => { systemLog.DebugFormat("{0} Speech hypothesized", prefix); };

            var safi = new SpeechAudioFormatInfo(EncodingFormat.ULaw, 8000, 8, 1, 8000, 1, null);

            // new SpeechAudioFormatInfo(8000, AudioBitsPerSample.Sixteen, AudioChannel.Mono);

            speechRecognitionEngine.SetInputToAudioStream(stream, safi);
            speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple);

            IsReady = true;
        }