29,028
社区成员
发帖
与我相关
我的任务
分享
- (IBAction)Begain:(id)sender {
//创建保存录音文件的路径
NSString *file = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"abc.caf"];
NSURL *url = [NSURL fileURLWithPath:file];
NSLog(@"%@",file);
//创建保存录音字典
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:5];//给一个大概的空间为5
//设置文件录音ID
dic[AVFormatIDKey] = @(kAudioFormatLinearPCM);
//设置采样率
dic[AVSampleRateKey] = @(44100.0);
//设置通道
dic[AVNumberOfChannelsKey] = @(2);
//初始化录音器
self.recoder = [[AVAudioRecorder alloc]initWithURL:url settings:dic error:nil];
//准备录音
[self.recoder prepareToRecord];
//开始录音
[self.recoder record];
//开始定时器
self.timer.fireDate = [NSDate distantPast];
}
//停止录音
- (IBAction)btnStop:(UIButton *)sender {
[self.recoder stop];
//停止设为空
self.timer.fireDate = [NSDate distantFuture];
self.timer = nil;
}