您的位置:首页 > 其它

音频处理(录音二)

2014-07-09 14:19 127 查看
录音设置

NSMutableDictionary *recordSetting = [[[NSMutableDictionary alloc]init] autorelease];

录音格式

[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];

录音采样率(影响音频质量)

[recordSetting setValue:[NSNumber numberWithFloat:44100] forKey:AVSampleRateKey];

录音通道数

[recordSetting setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];

线性采样数8、16、24、32

[recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];

录音质量

[recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey];

NSDictionary *recordSetting = [[NSDictionary alloc] initWithObjectsAndKeys:

[NSNumber numberWithFloat: 44100.0],AVSampleRateKey, //采样率

[NSNumber numberWithInt: kAudioFormatLinearPCM],AVFormatIDKey,

[NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,//采样位数
默认 16

[NSNumber numberWithInt: 2], AVNumberOfChannelsKey,//通道的数目

[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,//大端还是小端
是内存的组织方式

[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,nil];//采样信号是整数还是浮点数

NSURL *recordedTmpFile = [NSURL fileURLWithPath:[NSTemporaryDirectory()stringByAppendingPathComponent: [NSString stringWithFormat: @"%.0f.%@",
[NSDatetimeIntervalSinceReferenceDate] * 1000.0, @"wav"]]]; //文件名的设置

//Setup the recorder to use this file and record to it.

AVAudioRecorder *recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFilesettings:recordSetting error:&error];

[recorder prepareToRecord];

[recorder record];

下面代码应该是当前.m文件加载时候就设置

AVAudioSession * audioSession = [AVAudioSession sharedInstance];

[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error]; //设置音频类别,这里表示当应用启动,停掉后台其他音频

[audioSession setActive:YES error: &error];//设置当前应用音频活跃性
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: