I am trying to play microphone audio input using swift3 without recording. I can record the audio with the following code:
let session = AVAudioSession.sharedInstance()
try! session.setCategory(AVAudioSessionCategoryPlayAndRecord, with:AVAudioSessionCategoryOptions.defaultToSpeaker)
try! audioRecorder = AVAudioRecorder(url: filePath!, settings: [:])
audioRecorder.delegate = self
audioRecorder.isMeteringEnabled = true
audioRecorder.prepareToRecord()
audioRecorder.record()
and then play it back ultimately after picking up the recorded file with:
audioPlayerNode.play()
But I would like to skip the recording step and play directly from the microphone input to the audio out (in this case the player node). It then functions like an actual microphone. Can I do this directly or does an interim file need to exist? I combed the AVFoundation documentation but I can't seem to get a handle on the direct route. Any ideas or suggestions are appreciated. Thank you!
You can do this with
AVAudioEngine
, although you will hear feedback: