音频录制

// 比特率 音频的传输速度
// 有 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];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ldl_csdn_ios

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值