我正在用AVAudioRecorder录制音频,文件太大了。比如20秒,结果是1.2mb?我怎么才能把它变小呢?谢谢。
发布于 2011-11-09 10:36:05
这是我发现的最好的方法,你也可以使用它:
NSMutableDictionary *settings = [[NSMutableDictionary alloc] initWithCapacity:0];
[settings setValue :[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];//格式
[settings setValue:[NSNumber numberWithFloat:8000.0] forKey:AVSampleRateKey]; //采样8000次
[settings setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];//声道
[settings setValue :[NSNumber numberWithInt:8] forKey:AVLinearPCMBitDepthKey];//位深度
[settings setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[settings setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
//Encoder
[settings setValue :[NSNumber numberWithInt:12000] forKey:AVEncoderBitRateKey];//采样率
[settings setValue :[NSNumber numberWithInt:8] forKey:AVEncoderBitDepthHintKey];//位深度
[settings setValue :[NSNumber numberWithInt:8] forKey:AVEncoderBitRatePerChannelKey];//声道采样率
[settings setValue :AVAudioQualityMin forKey:AVEncoderAudioQualityKey];//编码质量发布于 2011-06-20 07:51:41
尝试使用不同的格式和/或质量设置。下面的代码应该是一个非常小的文件:
NSDictionary *recordSettings =
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleIMA4], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMedium],
AVEncoderAudioQualityKey,
nil];
AVAudioRecorder *newRecorder =
[[AVAudioRecorder alloc] initWithURL: myURL
settings: recordSettings
error: nil];发布于 2012-03-29 14:44:49
录制的音频文件的大小取决于以下因素。还有其他因素。但下面的内容将值得注意。
1) 采样率
A 22050Hz sample rate will produce a much smaller file than a 44000Hz sample rate2) Channels
Stereo output(2 channels) will produce twice the size of the file of that of a mono (1 channel)3) 比特率
Bits used per sample.你需要想出一个最适合你的设置,这样它就不会影响质量和大小。
https://stackoverflow.com/questions/6404376
复制相似问题