title: How to Auto stop speech recognition if user stop speaking
body: <p>I am working on Bot app and here I have 2 features </p>
  
  <ul>
  <li>Speech to Text</li>
  <li>Text to Speech</li>
  </ul>
  
  <p>Both are working as expected but I want to detect that when user stop speaking at that time I want to stop detection and send that data to server.</p>
  
  <p>Is there any way to get that user is not speaking ?</p>
  
  <p>I am using below code for speech detection :</p>
  
  <pre><code>// Starts an AVAudio Session
      NSError *error;
      AVAudioSession *audioSession = [AVAudioSession sharedInstance];
      [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&amp;error];
      [audioSession setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&amp;error];
  
      // Starts a recognition process, in the block it logs the input or stops the audio
      // process if there's an error.
      recognitionRequest = [[SFSpeechAudioBufferRecognitionRequest alloc] init];
      AVAudioInputNode *inputNode = audioEngine.inputNode;
      recognitionRequest.shouldReportPartialResults = YES;
      recognitionTask = [speechRecognizer recognitionTaskWithRequest:recognitionRequest resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
          BOOL isFinal = NO;
          if (result) {
              // Whatever you say in the microphone after pressing the button should be being logged
              // in the console.
              NSLog(@"RESULT:%@",result.bestTranscription.formattedString);
              self.inputToolbar.contentView.textView.text = result.bestTranscription.formattedString;
              self.inputToolbar.contentView.rightBarButtonItem.enabled = YES;
              isFinal = !result.isFinal;
          }
          if (error) {
              if (audioEngine != NULL) {
                  [audioEngine stop];
                  [inputNode removeTapOnBus:0];
                  recognitionRequest = nil;
                  recognitionTask = nil;
              }
          }
      }];
  
      // Sets the recording format
      AVAudioFormat *recordingFormat = [inputNode outputFormatForBus:0]; //[[AVAudioFormat alloc] initStandardFormatWithSampleRate:44100 channels:1];
      [inputNode installTapOnBus:0 bufferSize:1024 format:recordingFormat block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
          [recognitionRequest appendAudioPCMBuffer:buffer];
      }];
  
      // Starts the audio engine, i.e. it starts listening.
      [audioEngine prepare];
      [audioEngine startAndReturnError:&amp;error];
      NSLog(@"Say Something, I'm listening");
  </code></pre>
  
  <p>Let me know if any one required more detail on this.</p>
  
  <p>Thanks in Advance.</p>