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

            // create receiver of grammar updates
            this.ReceiveGrammars = pipeline.CreateReceiver <IEnumerable <string> >(this, this.SetGrammars, nameof(this.ReceiveGrammars), 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.RecognitionResults);
            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.recognizeComplete = new ManualResetEvent(false);

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

            this.Configuration = configuration ?? new SystemSpeechRecognizerConfiguration();

            // create receiver of grammar updates
            this.ReceiveGrammars = pipeline.CreateReceiver <IEnumerable <string> >(this, this.SetGrammars, nameof(this.ReceiveGrammars), 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(this.SpeechDetected));
            this.SpeechHypothesized         = pipeline.CreateEmitter <SpeechHypothesizedEventArgs>(this, nameof(this.SpeechHypothesized));
            this.SpeechRecognized           = pipeline.CreateEmitter <SpeechRecognizedEventArgs>(this, nameof(this.SpeechRecognized));
            this.SpeechRecognitionRejected  = pipeline.CreateEmitter <SpeechRecognitionRejectedEventArgs>(this, nameof(this.SpeechRecognitionRejected));
            this.AudioSignalProblemOccurred = pipeline.CreateEmitter <AudioSignalProblemOccurredEventArgs>(this, nameof(this.AudioSignalProblemOccurred));
            this.AudioStateChanged          = pipeline.CreateEmitter <AudioStateChangedEventArgs>(this, nameof(this.AudioStateChanged));
            this.RecognizeCompleted         = pipeline.CreateEmitter <RecognizeCompletedEventArgs>(this, nameof(this.RecognizeCompleted));
            this.AudioLevelUpdated          = pipeline.CreateEmitter <AudioLevelUpdatedEventArgs>(this, nameof(this.AudioLevelUpdated));
            this.EmulateRecognizeCompleted  = pipeline.CreateEmitter <EmulateRecognizeCompletedEventArgs>(this, nameof(this.EmulateRecognizeCompleted));
            this.LoadGrammarCompleted       = pipeline.CreateEmitter <LoadGrammarCompletedEventArgs>(this, nameof(this.LoadGrammarCompleted));
            this.RecognizerUpdateReached    = pipeline.CreateEmitter <RecognizerUpdateReachedEventArgs>(this, nameof(this.RecognizerUpdateReached));

            // 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.recognizeComplete = new ManualResetEvent(false);

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