-->

AVAudioRecorder Settings did not take effect on ou

2019-09-17 19:30发布

问题:

I'm using AVAudioRecorder to record and save to an audio.m4a file with these settings:

NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
    [recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityMin] forKey:AVEncoderAudioQualityKey];
    [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
    [recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVEncoderBitRateKey];
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
    [recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
    [recordSetting setValue:[NSNumber numberWithInt:8] forKey:AVLinearPCMBitDepthKey];

But when I use a software to read the attributes of audio.m4a file, I got these:

Bitrate: 64KBps

Channels: 2

So does that mean those settings above did not affect the output file, because obviously, I set its bit rate to 16 and channels to 1. Did I miss something on these settings??

回答1:

The problem is that not every setting is legal and illegal settings fail silently. So in this case a bitrate of 16 is way too low. In a sense, the system is doing you a favor; instead of barfing, it's making the recording, but it's substituting legal settings for the ones you gave.