您的位置:首页 > 其它

音频录制

2015-09-13 15:26 197 查看
// 比特率 音频的传输速度

// 有 8 16 32 64 值越大 传输速度越快 音质越高

//

// AVAudioQualityMin = 0,

// AVAudioQualityLow = 0x20,

// AVAudioQualityMedium = 0x40,

// AVAudioQualityHigh = 0x60,

// AVAudioQualityMax = 0x7F

// AVEncoderAudioQualityKey

NSString *path = [NSTemporaryDirectory()stringByAppendingPathComponent:@"rec.caf"];
NSLog(@"路径是:%@",path);


NSDictionary *setting=@{AVSampleRateKey:@(40000),
AVNumberOfChannelsKey:@(2),
AVEncoderAudioQualityKey:@(AVAudioQualityMedium),
AVLinearPCMBitDepthKey:@(32),
AVEncoderBitRateKey:@(32)};


//    settings 录音的音频设置 采样率 通道 质量。。。。
avAudioRecorder = [[ AVAudioRecorder alloc]initWithURL:[NSURL fileURLWithPath:path] settings:setting error:nil];
//    挂上代理
avAudioRecorder.delegate =self;

//    录音的当前时间
[avAudioRecorder currentTime];

//    预录制
[avAudioRecorder prepareToRecord];

//    录制
[avAudioRecorder record];

NSLog(@"录音设置%@",avAudioRecorder.settings);

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 100, 100, 100);
button.backgroundColor = [UIColor orangeColor];
[button addTarget:self action:@selector(stopRec) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];


#pragma mark-------AVAudioRecorderDelegate 代理的方法
//录音结束调用
- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{

NSLog(@"……");

//    文件管理类
//    管理文件 创建文件 移动  复制 删除
//    判断文件 是否可以扩展目录
//    是否可以读取 写入

//    subpathsAtPath  得到指定目录下得 子文件

NSFileManager *manage = [NSFileManager defaultManager];
//    createFileAtPath指定文件要创建的目录
//    contents指定文件创建的内容
//    attributes文件的属性
NSString *path = [NSTemporaryDirectory()stringByAppendingPathComponent:@"gg"];
BOOL success = [manage createFileAtPath:path contents:nil attributes:nil];

if (success) {
NSLog(@"xxxxx----%@",path);

//        移动文件
//        目标目录

NSString *newPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject]stringByAppendingPathComponent:@"gg.jpg"];

//        移动  剪切文件

[manage moveItemAtPath:path toPath:newPath error:nil];
NSLog(@"%@",newPath);

//        拷贝 新旧文件都在
//        [manage copyItemAtPath:path toPath:newPath error:nil];

//        删除文件
//        [manage removeItemAtPath:path error:nil];

//        判断文件是否存在
//
//        if ([manage fileExistsAtPath:newPath]==YES) {
//            NSLog(@"文件  已经存在");
//        }

//        获得目录、里面的子文件

//     NSArray *all =   [manage subpathsAtPath:newPath];

}

}


-(void)stopRec
{
[avAudioRecorder stop];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: