2014-09-28 42 views
1

是否可以通过麦克风录制PCM音频文件?我正在尝试录制一个非常短的PCM音频文件,但迄今为止还处于挣扎状态。如何在iOS上录制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]; 

它将如果有人能在正确的方向指向我非常感谢,谢谢。

回答