ios 录音生成.aac录音文件

 ios 录音并生成.aac文件

-(void)creatRecordSubject

{

    NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc]init] ;

    //设置录音格式  AVFormatIDKey==kAudioFormatLinearPCM

    [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];

    //设置录音采样率(Hz) 如:AVSampleRateKey==8000/44100/96000(影响音频的质量)

    [recordSetting setValue:[NSNumber numberWithFloat:8000] forKey:AVSampleRateKey];

    //录音通道数  1 或 2

    [recordSetting setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];

    //线性采样位数  8、16、24、32

    [recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];

    //录音的质量

    [recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityLow] forKey:AVEncoderAudioQualityKey];

    

    NSString *strUrl = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

    //    .wave 只有这种格式 容云才能发出去

    NSString *pathStr=[NSString stringWithFormat:@"%@/%@record.aac", strUrl,voiceKey];

    playUrl = [NSURL fileURLWithPath:pathStr];


    NSError *error;

    //初始化

    

    //设置外音

    [[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback error:&error];

    [[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];

    

    

    recorder = [[AVAudioRecorder alloc]initWithURL:playUrl settings:recordSetting error:&error];

    

    //        录音前的节奏

    if(recorder)

    {

        [recorder prepareToRecord];

        [recorder record];  

        recorder.meteringEnabled=YES;

    }

}


关闭录音

if(recorder)

    {

        [recorder stop];

        recorder=nil;

    }


    

你可能感兴趣的:(ios 录音生成.aac录音文件)