I'm having an issue while trying to use both AVAudioPlayer and AVAudioEngine in my app. I'm using AVAudioPlayer to play remote audio files and audio live streams. I'm using AVAudioEngine to capture sound of a microphone and transcribe it. However whenever I use the AVAudioEngine and go back to the player I can't play any audio as the avasset was empty. I have to setup and play it again. what is the best way to use the mic and do not interfere with audio playback
let audioEngine = AVAudioEngine()
var inputNode: AVAudioInputNode!
// view did load
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(AVAudioSession.Category.record, mode: AVAudioSession.Mode.measurement)
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
inputNode = audioEngine.inputNode
let recordingFormat = inputNode.outputFormat(forBus: 0)
inputNode.removeTap(onBus: 0)
inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in
self.recognitionRequest?.append(buffer)
}
audioEngine.prepare()
try audioEngine.start()
//viewWillDisappear
self.audioEngine.stop()
self.inputNode.removeTap(onBus: 0)