I'm working on a Swift application for macOS that uses AVAudioRecorder. The initializer method of this class may consume a 'settings' dictionary. The relevant AV docs all make an URL-less, plain-text reference to where these settings key/values are defined with statements such as:
For information on the settings available for an audio recorder, see AV Foundation Audio Settings Constants.
I've searched quite a lot for this document and failed to locate it. I've actually submitted a feedback report to Apple requesting they update their API docs with links to that document as it's referred to in many places, but only by name.
I've tried googling extensively. I've used Apple's own search function on their developer site and I've searched with the API docs within Xcode itself. That effort has not located a document titled AV Foundation Audio Settings Constants, but I can find many docs that refer to it by that precise name.
Does anyone out there know where this mystical API doc actually exists?
First you need to import the AVFoundation framework into your view controller. You will need to add three properties to your view controller: a button for the user to tap to start or stop recording, an audio session to manage recording, and an audio recorder to handle the actual reading and saving of data.
A floating point value that represents the sample rate, in hertz.
I've not found any actual authoritative doc on this, here's just a running list of the parameters I've encountered thus far:
AVFormatIDKey :
kAudioFormatAppleLossless
, kAudioFormatMPEG4AAC
AVNumberOfChannelsKey :
2
AVSampleRateKey :
44100.0
AVEncoderBitRateKey:
192000
, 320000
AVEncoderAudioQualityKey :
AVAudioQuality.min.rawValue
, AVAudioQuality.max.rawValue
Here's a Swift example of creating a settings dictionary with some of these values:
let settings:[String : Any] = [ AVFormatIDKey : kAudioFormatAppleLossless,
AVEncoderAudioQualityKey : AVAudioQuality.max.rawValue,
AVEncoderBitRateKey: 320000,
AVNumberOfChannelsKey : 2,
AVSampleRateKey : 44100.0 ] as [String : Any]
I hope to keep updating this with more options as I go. Others are welcome to update this too, just please follow the format I have here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With