【发布时间】:2014-09-28 10:19:34
【问题描述】:
是否可以通过麦克风录制 PCM 音频文件?我正在尝试录制一个非常短的 PCM 音频文件,但到目前为止一直很困难。
我尝试过使用 AVAudioRecorder 但这不起作用:
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryRecord error:nil];
NSDictionary* recorderSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,
[NSNumber numberWithInt:44100],AVSampleRateKey,
[NSNumber numberWithInt:1],AVNumberOfChannelsKey,
[NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
nil];
NSError* error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL* outURL = [NSURL fileURLWithPath:[documentsDirectory stringByAppendingPathComponent:@"output.pcm"]];
recorder = [[AVAudioRecorder alloc] initWithURL:outURL settings:recorderSettings error:&error];
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
如果有人能指出正确的方向,将不胜感激,谢谢。
【问题讨论】:
标签: ios objective-c audio pcm recording