Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the valid 'settings' key/values for AVAudioRecorder?

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?

like image 275
James T Snell Avatar asked Jan 04 '18 08:01

James T Snell


People also ask

How do I record audio with Avaudiorecorder?

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.

What is Avsampleratekey?

A floating point value that represents the sample rate, in hertz.


1 Answers

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.

like image 113
James T Snell Avatar answered Nov 15 '22 03:11

James T Snell