您的位置:首页 > 移动开发 > IOS开发

iOS开发(OC)——录音

2016-07-08 13:38 302 查看
//录音需要的字典
NSMutableDictionary *settings = [NSMutableDictionary dictionary];

[settings setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[settings setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[settings setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
[settings setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[settings setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[settings setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];

recoder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:[self recordFilePath]] settings:settings error:nil];

//开始准备录音,使用此方法可以减少录音的延迟时间
[recoder prepareToRecord];

[recoder record];


//录音存放地址

-(NSString *)recordFilePath{

NSString *recordFile = @"record.wav";//wav格式iOS和android通用

NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *recordFlod = [documentPath stringByAppendingPathComponent:@"RecordFlod"];
if (![[NSFileManager defaultManager] fileExistsAtPath:recordFlod]) {
[[NSFileManager defaultManager] createDirectoryAtPath:recordFlod withIntermediateDirectories:YES attributes:nil error:nil];
}

recordFile = [recordFlod stringByAppendingPathComponent:recordFile];

return recordFile;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  录音