首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVAudioRecorder文件太大

AVAudioRecorder文件太大
EN

Stack Overflow用户
提问于 2011-06-20 02:38:14
回答 3查看 2.5K关注 0票数 1

我正在用AVAudioRecorder录制音频,文件太大了。比如20秒,结果是1.2mb?我怎么才能把它变小呢?谢谢。

EN

回答 3

Stack Overflow用户

发布于 2011-11-09 10:36:05

这是我发现的最好的方法,你也可以使用它:

代码语言:javascript
复制
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];//编码质量
票数 7
EN

Stack Overflow用户

发布于 2011-06-20 07:51:41

尝试使用不同的格式和/或质量设置。下面的代码应该是一个非常小的文件:

代码语言:javascript
复制
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];
票数 3
EN

Stack Overflow用户

发布于 2012-03-29 14:44:49

录制的音频文件的大小取决于以下因素。还有其他因素。但下面的内容将值得注意。

1) 采样率

代码语言:javascript
复制
  A 22050Hz sample rate will produce a much smaller file than a 44000Hz sample rate

2) Channels

代码语言:javascript
复制
  Stereo output(2 channels) will produce twice the size of the file of that of a mono (1 channel)

3) 比特率

代码语言:javascript
复制
Bits used per sample.

你需要想出一个最适合你的设置,这样它就不会影响质量和大小。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6404376

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档