Does not seem possible using AVAudioRecorder
by itself.
An alternative would be to use AVCaptureSession
with an AVCaptureAudioDataOutput
which provides access to the raw audio buffer, from which the wave form can be read.
Most of the processing would be done in the delegate:
func captureOutput(AVCaptureOutput!, didOutputSampleBuffer: CMSampleBuffer!, from: AVCaptureConnection!)
You would probably need to implement some sort of throttling to only process every Nth sample so that your visualiser code doesn't interfere with the audio.
AVCaptureSession
is far more rudimentary compared to AVAudioRecorder
- it does not provide any recording facilities by itself for example, and so if you wanted to also record the audio you would need to use an AVAssetWriter
to save the samples.
This SO question shows how to access the sample buffers. It uses AVAssetReader
to load a file, but the delegate is exactly the same as would be used for realtime processing:
Reading audio samples via AVAssetReader