예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MicrosoftSpeechRecognizer"/> class.
        /// </summary>
        /// <param name="pipeline">The pipeline to add the component to.</param>
        /// <param name="configuration">The component configuration.</param>
        public MicrosoftSpeechRecognizer(Pipeline pipeline, MicrosoftSpeechRecognizerConfiguration configuration)
            : base(pipeline)
        {
            this.Configuration = configuration ?? new MicrosoftSpeechRecognizerConfiguration();

            // create receiver of grammar updates
            this.ReceiveGrammars = pipeline.CreateReceiver <IEnumerable <string> >(this, this.SetGrammars, nameof(this.ReceiveGrammars), true);

            // create receiver of grammar updates by name
            this.ReceiveGrammarNames = pipeline.CreateReceiver <string[]>(this, this.EnableGrammars, nameof(this.ReceiveGrammarNames), true);

            // assign the default Out emitter to the RecognitionResults group
            this.originatingTimeConsistencyCheckGroup.Add(this.Out, EmitterGroup.RecognitionResults);

            // create the additional output streams
            this.PartialRecognitionResults = this.CreateEmitterInGroup <IStreamingSpeechRecognitionResult>(pipeline, nameof(this.PartialRecognitionResults), EmitterGroup.IntentData);
            this.IntentData = this.CreateEmitterInGroup <IntentData>(pipeline, nameof(this.IntentData), EmitterGroup.IntentData);

            // create output streams for speech event args
            this.SpeechDetected            = this.CreateEmitterInGroup <SpeechDetectedEventArgs>(pipeline, nameof(this.SpeechDetected), EmitterGroup.SpeechEvents);
            this.SpeechHypothesized        = this.CreateEmitterInGroup <SpeechHypothesizedEventArgs>(pipeline, nameof(this.SpeechHypothesized), EmitterGroup.SpeechEvents);
            this.SpeechRecognized          = this.CreateEmitterInGroup <SpeechRecognizedEventArgs>(pipeline, nameof(this.SpeechRecognized), EmitterGroup.SpeechEvents);
            this.SpeechRecognitionRejected = this.CreateEmitterInGroup <SpeechRecognitionRejectedEventArgs>(pipeline, nameof(this.SpeechRecognitionRejected), EmitterGroup.SpeechEvents);
            this.RecognizeCompleted        = this.CreateEmitterInGroup <RecognizeCompletedEventArgs>(pipeline, nameof(this.RecognizeCompleted), EmitterGroup.SpeechEvents);
            this.EmulateRecognizeCompleted = this.CreateEmitterInGroup <EmulateRecognizeCompletedEventArgs>(pipeline, nameof(this.EmulateRecognizeCompleted), EmitterGroup.SpeechEvents);

            // create output streams for audio state event args
            this.AudioSignalProblemOccurred = this.CreateEmitterInGroup <AudioSignalProblemOccurredEventArgs>(pipeline, nameof(this.AudioSignalProblemOccurred), EmitterGroup.AudioEvents);
            this.AudioStateChanged          = this.CreateEmitterInGroup <AudioStateChangedEventArgs>(pipeline, nameof(this.AudioStateChanged), EmitterGroup.AudioEvents);
            this.AudioLevelUpdated          = this.CreateEmitterInGroup <AudioLevelUpdatedEventArgs>(pipeline, nameof(this.AudioLevelUpdated), EmitterGroup.AudioEvents);

            // create output stream for the grammar event args
            this.LoadGrammarCompleted    = this.CreateEmitterInGroup <LoadGrammarCompletedEventArgs>(pipeline, nameof(this.LoadGrammarCompleted), EmitterGroup.StateUpdateEvents);
            this.RecognizerUpdateReached = this.CreateEmitterInGroup <RecognizerUpdateReachedEventArgs>(pipeline, nameof(this.RecognizerUpdateReached), EmitterGroup.StateUpdateEvents);

            // create table of last stream group originating times
            this.lastPostedOriginatingTimes = new Dictionary <EmitterGroup, DateTime>();

            // Create a BufferedAudioStream with an internal buffer large enough
            // to accommodate the specified number of milliseconds of audio data.
            this.inputAudioStream = new BufferedAudioStream(
                this.Configuration.InputFormat.AvgBytesPerSec * this.Configuration.BufferLengthInMs / 1000);

            this.recognizeCompleteManualReset = new ManualResetEvent(false);

            // create the recognition engine
            this.speechRecognitionEngine = this.CreateSpeechRecognitionEngine();
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MicrosoftSpeechRecognizer"/> class.
        /// </summary>
        /// <param name="pipeline">The pipeline to add the component to.</param>
        /// <param name="configuration">The component configuration.</param>
        public MicrosoftSpeechRecognizer(Pipeline pipeline, MicrosoftSpeechRecognizerConfiguration configuration)
            : base(pipeline)
        {
            pipeline.RegisterPipelineStartHandler(this, this.OnPipelineStart);

            this.Configuration = configuration;

            // create receiver of grammar updates
            this.ReceiveGrammars = pipeline.CreateReceiver <IEnumerable <string> >(this, this.SetGrammars, nameof(this.ReceiveGrammars), true);

            // create receiver of grammar updates by name
            this.ReceiveGrammarNames = pipeline.CreateReceiver <string[]>(this, this.EnableGrammars, nameof(this.ReceiveGrammarNames), true);

            // create the additional output streams
            this.PartialRecognitionResults = pipeline.CreateEmitter <IStreamingSpeechRecognitionResult>(this, nameof(this.PartialRecognitionResults));
            this.IntentData = pipeline.CreateEmitter <IntentData>(this, nameof(this.IntentData));

            // create output streams for all the event args
            this.SpeechDetected             = pipeline.CreateEmitter <SpeechDetectedEventArgs>(this, nameof(SpeechDetectedEventArgs));
            this.SpeechHypothesized         = pipeline.CreateEmitter <SpeechHypothesizedEventArgs>(this, nameof(SpeechHypothesizedEventArgs));
            this.SpeechRecognized           = pipeline.CreateEmitter <SpeechRecognizedEventArgs>(this, nameof(SpeechRecognizedEventArgs));
            this.SpeechRecognitionRejected  = pipeline.CreateEmitter <SpeechRecognitionRejectedEventArgs>(this, nameof(SpeechRecognitionRejectedEventArgs));
            this.AudioSignalProblemOccurred = pipeline.CreateEmitter <AudioSignalProblemOccurredEventArgs>(this, nameof(AudioSignalProblemOccurredEventArgs));
            this.AudioStateChanged          = pipeline.CreateEmitter <AudioStateChangedEventArgs>(this, nameof(AudioStateChangedEventArgs));
            this.RecognizeCompleted         = pipeline.CreateEmitter <RecognizeCompletedEventArgs>(this, nameof(RecognizeCompletedEventArgs));
            this.AudioLevelUpdated          = pipeline.CreateEmitter <AudioLevelUpdatedEventArgs>(this, nameof(AudioLevelUpdatedEventArgs));
            this.EmulateRecognizeCompleted  = pipeline.CreateEmitter <EmulateRecognizeCompletedEventArgs>(this, nameof(EmulateRecognizeCompletedEventArgs));
            this.LoadGrammarCompleted       = pipeline.CreateEmitter <LoadGrammarCompletedEventArgs>(this, nameof(LoadGrammarCompletedEventArgs));
            this.RecognizerUpdateReached    = pipeline.CreateEmitter <RecognizerUpdateReachedEventArgs>(this, nameof(RecognizerUpdateReachedEventArgs));

            // create table of last stream originating times
            this.lastPostedOriginatingTimes = new Dictionary <IEmitter, DateTime>();

            // Create a BufferedAudioStream with an internal buffer large enough
            // to accommodate the specified number of milliseconds of audio data.
            this.inputAudioStream = new BufferedAudioStream(
                this.Configuration.InputFormat.AvgBytesPerSec * this.Configuration.BufferLengthInMs / 1000);

            this.recognizeCompleteManualReset = new ManualResetEvent(false);

            // create the recognition engine
            this.speechRecognitionEngine = this.CreateSpeechRecognitionEngine();
        }