title: AVAudioEngine inputNode installTap crash when restarting recording
body: <p>I am implementing Speech Recognition in my app. When I first present the view controller with the speech recognition logic, everything works fine. However, when I try present the view controller again, I get the following crash:</p>
  
  <pre><code>ERROR:    [0x190bf000] &gt;avae&gt; AVAudioNode.mm:568: CreateRecordingTap: required condition is false: IsFormatSampleRateAndChannelCountValid(format)
  *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
  </code></pre>
  
  <p>Here is the code used for starting and stopping recording:</p>
  
  <pre><code>@available(iOS 10.0, *)
  extension DictationViewController {
  
  fileprivate func startRecording() throws {
      guard let recognizer = speechRecognizer else {
          debugLog(className, message: "Not supported for the device's locale")
          return
      }
  
      guard recognizer.isAvailable else {
          debugLog(className, message: "Recognizer is not available right now")
          return
      }
  
      mostRecentlyProcessedSegmentDuration = 0
      guard let node = audioEngine.inputNode else {
          debugLog(className, message: "Could not get an input node")
          return
      }
  
      let recordingFormat = node.outputFormat(forBus: 0)
      node.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { [weak self] (buffer, _) in
          self?.request.append(buffer)
      }
  
      audioEngine.prepare()
      try audioEngine.start()
  
      recognitionTask = recognizer.recognitionTask(with: request, resultHandler: {/***/})
  }
  
  fileprivate func stopRecording() {
      audioEngine.stop()
      audioEngine.inputNode?.removeTap(onBus: 0)
      request.endAudio()
      recognitionTask?.cancel()
  }
  
  }
  </code></pre>
  
  <p><code>startRecording()</code> is called in viewDidLoad once we have requested authorization. <code>stopRecording()</code> is called when the view controller is dismissed.</p>
  
  <p>Please assist. I'm struggling to find a solution to this crash</p>