title: How to do SFSpeechRecognition and record audio at the same time in Swift?
body: <p>So I've been trying to do Speech Recognition in Swift using the builtin SFSpeechRecognition class while also downsampling and then recording the audio to a file, but I'm not well-versed enough in AVAudioEngine to figure it out.</p>
  
  <p>I've gotten the Speech Recognition to work by itself, and I've gotten the recording the audio to work by itself, but I can't get them to work together.</p>
  
  <p>Here's my existing code in which I try to record - the remaining code is just the standard speech recognition type stuff:</p>
  
  <pre><code>let audioFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 16000, channels: 1, interleaved: false)
  let mixer = AVAudioMixerNode()
  audioEngine.attach(mixer)
  
  
  audioEngine.connect(inputNode!, to: mixer, format: inputNode!.inputFormat(forBus: 0))
  
  // 1 Connecting Mixer
  audioEngine.connect(mixer, to: audioEngine.outputNode, format: audioFormat)
  
  // 2 Recognition
  inputNode!.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer, when) in
          print("Testing if this tap works")
          self.recognitionRequest?.append(buffer)
      }
  
  // 3 Downsampling and recording
  mixer.installTap(onBus: 0, bufferSize: 1024, format: audioFormat){ (buffer, when) in
          print(buffer)
          try? self.outputFile!.write(from: buffer)
  }
  </code></pre>
  
  <p>If I comment out 3, then the speech recognition works, but otherwise 2 doesn't even run - the tap doesn't output anything. I also can't put the recognitionRequest in 3 because then the speech recognition throws an error. I see in the docs that each bus can only have one tap - how can I get around this? Should I use an AVConnectionPoint? I don't see it well documented in the docs.</p>