public void StopSpeechRecognition()
        {
            if (!_isActive)
            {
                NonBlockingConsole.WriteLine("Warn: StopSpeechRecognition() called on an inactive SpeechRecognizer.");
                return;
            }

            _isActive = false;

            if (_isRecognizing)
            {
                _isRecognizing = false;
                if (_speechRecognitionEngine != null)
                {
                    _speechRecognitionEngine.RecognizeAsyncCancel();
                }

                if (_speechRecognitionConnector != null)
                {
                    // Stop the connector
                    _speechRecognitionConnector.Stop();

                    // speech recognition connector must be detached from the flow, otherwise if the connector is rooted, it will keep the flow in memory.
                    _speechRecognitionConnector.DetachFlow();
                }

                if (_speechRecognitionStream != null)
                {
                    _speechRecognitionStream.Dispose();
                    _speechRecognitionStream = null;
                }
            }

            if ((_audioVideoFlow != null) && (_audioVideoFlow.SpeechRecognitionConnector != null))
            {
                _audioVideoFlow.SpeechRecognitionConnector.Stop();
                _audioVideoFlow.SpeechRecognitionConnector.DetachFlow();
                _audioVideoFlow.StateChanged -= AudioVideoFlow_StateChanged;
                _audioVideoFlow = null;
            }

            _waitForAudioVideoFlowStateChangedToActiveCompleted.Reset();
        }