I use audiounit to record the voice and use audioqueue to play the audio data. When I set:
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
The volume of played audio will be very low. But when I set:
[session setCategory:AVAudioSessionCategoryMultiRoute error:&error];
Though the volume will be normal. But the audio data output from the iOS microphone will not be the same long. With the former setting, the audiodata length will be 4096, but the latter will output the length in 3760 and 3764. This will cause crash when I encode the audiodata.
I find the solution said that I should open the audio player before open the audio recorder, and then the problem will be solved. Unfortunately, I must open the audio recorder first. So I don't know how to set the audiosession can I get a loud volume and the audiodata in the same length.