Am using the demo code below to flesh out an audio recording app in Swift 5.x
I would like to monitor certain aspects of the AVAudioRecorder as it is recording. Such as: frequency, power, volume, etc. but in live time.
I found an example in Swift 3 where the user sets up a callback timer for 0.5 sec. I was wondering if this was still the case, or that in the latest version of Swift, there might be a callback function in the AVAudioEngine that gets called at a regular frequency?
do {
audioRecorder = try AVAudioRecorder(url: audioFilename!, settings: settings)
audioRecorder.delegate = self
audioRecorder.record()
recordButton.setTitle("Tap to Stop", for: .normal)
} catch {
finishRecording(success: false)
}
}
it is nothing to do with the version of swift but the AVKit framework. Look into the AVAudioRecorder type or the documentation and you will find what you're looking for. Use a timer and a combination of the following methods.
/* metering */
open var isMeteringEnabled: Bool /* turns level metering on or off. default is off. */
open func updateMeters() /* call to refresh meter values */
open func peakPower(forChannel channelNumber: Int) -> Float /* returns peak power in decibels for a given channel */
open func averagePower(forChannel channelNumber: Int) -> Float /* returns average power in decibels for a given channel */