创建录音对象
// 1.创建沙盒路径
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
// 2.拼接音频文件
NSString *filePath = [path stringByAppendingPathComponent:@"录音文件.caf"];
// 3.转化成url file://
NSURL *url = [NSURL fileURLWithPath:filePath];
// 4.设置录音的参数
NSDictionary *settingRecorder = @{
AVEncoderAudioQualityKey : [NSNumber numberWithInteger:AVAudioQualityLow],
AVEncoderBitRateKey : [NSNumber numberWithInteger:16],
AVSampleRateKey : [NSNumber numberWithFloat:8000],
AVNumberOfChannelsKey : [NSNumber numberWithInteger:2]
};
// 5.创建录音对象
self.recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settingRecorder error:nil];
开始录音
[self.recorder record];
结束录音
[self.recorder stop];
网友评论