2014-09-28 2 views
1

Можно ли записать аудиофайл PCM через микрофон? Я пытаюсь записать очень короткий аудиофайл PCM, но до сих пор боролся.Как записать аудиофайл PCM на iOS?

Я попытался с помощью 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]; 

Было бы весьма признателен, если кто-то может мне точку в правильном направлении, спасибо.

ответ

3

вы знаете о Audio Queue Services? Если вы знаете, вы можете легко. В других случаях вы можете сделать это с помощью AVAoudioRecord. Пожалуйста, проверьте приведенный ниже адрес: How do I record audio on iPhone with AVAudioRecorder? Спасибо.

Смежные вопросы