码迷,mamicode.com
首页 > 其他好文 > 详细

xcode中用AVAudioRecorder录音到指定的caf文件

时间:2014-08-13 14:46:26      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:des   使用   os   io   文件   for   ar   art   

-(void) StartRecord:(NSURL *) recordedFile

{

session = [AVAudioSession sharedInstance];

session.delegate = self;

NSError *sessionError;

[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&sessionError];

 

if(session == nil)

NSLog(@"Error creating session: %@", [sessionError description]);

else

[session setActive:YES error:nil];

/*

 NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:

 [NSNumber numberWithFloat:44100.0], AVSampleRateKey,

 [NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey,

 [NSNumber numberWithInt:2], AVNumberOfChannelsKey,

 nil];

 */

//录音设置

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

//录音格式 无法使用

[settings setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey: AVFormatIDKey];

//采样率

[settings setValue :[NSNumber numberWithFloat:11025.0] forKey: AVSampleRateKey];//44100.0

//通道数

[settings setValue :[NSNumber numberWithInt:2] forKey: AVNumberOfChannelsKey];

//线性采样位数

//[recordSettings setValue :[NSNumber numberWithInt:16] forKey: AVLinearPCMBitDepthKey];

//音频质量,采样质量

[settings setValue:[NSNumber numberWithInt:AVAudioQualityMin] forKey:AVEncoderAudioQualityKey];

 

 

recorder = [[AVAudioRecorder alloc] initWithURL:recordedFile settings:settings error:nil];

[recorder prepareToRecord];

[recorder record];

}

 

-(void) StopRecord

{

    [recorder stop];

    

    if(recorder)

    {

        recorder = nil;

    }

}

xcode中用AVAudioRecorder录音到指定的caf文件,布布扣,bubuko.com

xcode中用AVAudioRecorder录音到指定的caf文件

标签:des   使用   os   io   文件   for   ar   art   

原文地址:http://www.cnblogs.com/HuiLove/p/3909862.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!