2014-09-28 248 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]; 

它將如果有人能在正確的方向指向我非常感謝,謝謝。

回答