AVAudioRecorder does not sound

I have a problem with AVAudioPlayer in some state . at first my sound recorder works fine at all. but after calling and playing VOIP from built_in_Speaker and a lot with a sound session after you hung up, I can’t record sound with sound first! but the second time everything works great. Problem

provided that I mentioned that my sound was recorded but has no voice!

I want to know in what situation can happen?

  self.audioSession = [AVAudioSession sharedInstance]; NSError *err = nil; [self.audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err]; if(err){ NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]); return; } BOOL preparedToRecord = [self.audioRecorder prepareToRecord]; __block BOOL recordStarted = NO; err = nil; [self.audioSession setActive:YES error:&err]; if(err){ NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]); return; } if (preparedToRecord){ recordStarted = [self.audioRecorder record]; } 
+6
source share
2 answers

solvable

I found the cause of this problem. I have addObserve my own to catch an AVAudioSession notification and check AudioSession interrupt / RoutChanging! The problem is that after my call I try to change the audio route to the speaker, but the class that AudioRoutChanging adds for notification tries to prevent this. so the route of the audio session changes every second and cannot record sound.

Conclusion you should do this to record sound:

1) sure in resolution

 2)[self.audioSession setActive:YES error:&err]; 3)[self.audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err]; 

4) make sure your route does not change during recording.

4) confident about your target patch

+4
source

Sound recording requires explicit user permission. The first time your application audio session tries to use the audio input route using a category that allows you to record, the system automatically asks the user for permission. You can directly ask by calling requestRecordPermission :. Until the user grants you permission to record, your application can record only silence.

see here: https://developer.apple.com/library/prerelease/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/index.html

-1
source

All Articles