My guess is you would have to use an AVCaptureSession to do this.
You can grab input from AVCaptureDeviceInput.
And then you can use AVCaptureOutputAudioDataOutput, which provides access to audio sample buffers as they are recorded.
extension RecordingViewController: AVCaptureAudioDataOutputSampleBufferDelegate {
func captureOutput(_ output: AVCaptureOutput,
didOutput sampleBuffer: CMSampleBuffer,
from connection: AVCaptureConnection) {
output.connection(with: AVMediaType(rawValue: AVAudioSessionPortBuiltInSpeaker))
}
}
Edit: It might be simpler and cleaner to implement this with AudioKit, however. Code would be something like this:
let microphone = AKMicrophone()
let mixer = AKMixer(microphone)
let booster = AKBooster(mixer, gain: 0)
AudioKit.output = booster
microphone.start()
do {
try AudioKit.start()
} catch {
print("AudioKit boot failed.")
}