title: How to stop Speech Recognition Engine listening its own speech
body: <p>I have written a speech recognition engine in C# using </p>
  
  <pre><code>    public partial class MainWindow : Window
      {
  
          SpeechRecognitionEngine _recognizer;
          SpeechSynthesizer sre = new SpeechSynthesizer();
          int count = 1;
  
      public MainWindow()
      {
          InitializeComponent();
          Initialize();
      }
  
      private void Initialize()
      {
          try
          {
              var culture = new CultureInfo("en-US");
              _recognizer = new SpeechRecognitionEngine(culture);
              _recognizer.SetInputToDefaultAudioDevice();
              _recognizer.LoadGrammar(GetGrammer());
              _recognizer.SpeechRecognized += new EventHandler&lt;SpeechRecognizedEventArgs&gt;(_recognizer_SpeechRecognized);
  
              _recognizer.RecognizeAsync(RecognizeMode.Multiple);
  
              sre.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Child);
              sre.Rate = -2;
  
          }
          catch (Exception ex)
          {
              System.Windows.MessageBox.Show(ex.InnerException.Message);
          }
      }
  
      private static Grammar GetGrammer()
      {
  
          var choices = new Choices();
          //add custom commands
          choices.Add(File.ReadAllLines(@"Commands.txt"));
          //to add the letters to the dictionary
          choices.Add(Enum.GetNames(typeof(Keys)).ToArray());
  
          var grammer = new Grammar(new GrammarBuilder(choices));
  
          return grammer;
      }
  
      void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
      {
  
          string speech = e.Result.Text; 
  
      //to type letters in open application like notepad
     if (Enum.GetNames(typeof(Keys)).Contains(speech))
      {
          try
          {   //send the string to the application
              SendKeys.SendWait("{" + speech + "}");
          }
          catch (ArgumentException)
          {
  
          }            
      }  
  
      //handle custom commands
          switch (speech)
          {
               case "day":
                  sre.Speak("Friday");
                  break;
          }
      }       
  }
  // where speech receives the text which the user speaks and also present in the loaded grammar (text file)
  </code></pre>
  
  <p>My code produces a speech recognition engine where if a user asks "day" it replies "Friday" which in turn has a "day" in it. So it goes on a loop and keeps on replying "Friday". What is the best way to stop the engine listening while it is speaking.</p>
  
  <p><strong>Note</strong>: I know the grammar can be changed to a convincing way like "What day it is" but I need it as "day" itself.</p>
  
  <p>Also I am not providing reproducible code as this issue might be I am missing something basic. And I have tried using <code>bool bAbleToListen=true;</code> as suggested in some StackOverflow question. But, was unable to find it useful</p>