总体内容
1、录音实现
2、录音的编辑 (拼接音频:可以设置多段,音频的剪切:按照时间段剪切)
3、lame静态库进行压缩转码
一、录音实现
1.1、导入 AVFoundation 框架,多媒体的处理, 基本上都使用这个框架
#import <AVFoundation/AVFoundation.h>
1.2、使用 AVAudioRecorder 进行录音,定义一个JKAudioTool 管理录音的类
(1)、定义一个录音对象,懒加载
@property (nonatomic, strong) AVAudioRecorder *audioRecorder;
-(AVAudioRecorder *)audioRecorder
{
if (!_audioRecorder) {
// 0. 设置录音会话
/**
AVAudioSessionCategoryPlayAndRecord: 可以边播放边录音(也就是平时看到的背景音乐)
*/
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
// 启动会话
[[AVAudioSession sharedInstance] setActive:YES error:nil];
// 1. 确定录音存放的位置
NSURL *url = [NSURL URLWithString:self.recordPath];
// 2. 设置录音参数
NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] init];
// 设置编码格式
/**
kAudioFormatLinearPCM: 无损压缩,内容非常大
kAudioFormatMPEG4AAC
*/
[recordSettings setValue :[NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey];
// 采样率(通过测试的数据,根据公司的要求可以再去调整),必须保证和转码设置的相同
[recordSettings setValue :[NSNumber numberWithFloat:11025.0] forKey: AVSampleRateKey];
// 通道数(必须设置为双声道, 不然转码生成的 MP3 会声音尖锐变声.)
[recordSettings setValue :[NSNumber numberWithInt:2] forKey: AVNumberOfChannelsKey];
//音频质量,采样质量(音频质量越高,文件的大小也就越大)
[recordSettings setValue:[NSNumber numberWithInt:AVAudioQualityMin] forKey:AVEncoderAudioQualityKey];
// 3. 创建录音对象
_audioRecorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:nil];
_audioRecorder.meteringEnabled = YES;
}
return _audioRecorder;
}
提示:设置 AVAudioSessionCategoryPlayAndRecord: 可以边播放边录音(也就是平时看到的背景音乐)
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
AVSampleRateKey 必须保证和转码设置的相同.
AVNumberOfChannelsKey 必须设置为双声道, 不然转码生成的 MP3 会声音尖锐变声.
(2)、开始录音
- (void)beginRecordWithRecordPath: (NSString *)recordPath {
// 记录录音地址
_recordPath = recordPath;
// 准备录音
[self.audioRecorder prepareToRecord];
// 开始录音
[self.audioRecorder record];
}
(3)、结束录音
- (void)endRecord {
[self.audioRecorder stop];
}
(4)、暂停录音
- (void)pauseRecord {
[self.audioRecorder pause];
}
(5)、删除录音
- (void)deleteRecord {
[self.audioRecorder