Volume is going down while recording sound with AVAudioRecorder in IOS

avaudiorecorder, ios, volume

Solution

Ok, you need to do bit more to achieve that. First, import

 #import <AudioToolbox/AudioServices.h>

then, inside your viewDidLoad method. put this code

 [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error: nil];
 UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
 AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,
 sizeof (audioRouteOverride),&audioRouteOverride);

Problem

I am developing an app in which I am recording sound with AVAudioRecorder with .CAF format, everything is fine but my problem is that when I am playing the recorded sound then its playing in very low volume. Somehow The volume of sound is going to least level. Tried so many solution but didn't find a solution to resolution, if anybody has any idea then please tell me, its very important for me. Below is the code of snippet ``` AVAudioSession *session = [AVAudioSession sharedInstance]; [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; [session setActive:YES error:nil]; // Define the recorder setting recordSetting = [[NSMutableDictionary alloc] init]; [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey]; [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey]; NSArray *pathComponents = [NSArray arrayWithObjects: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], [NSString stringWithFormat:@"%@.caf",@"temp"], nil]; NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents]; recorder = [[AVAudioRecorder alloc]initWithURL:outputFileURL settings:recordSetting error:nil]; recorder.delegate = self; recorder.meteringEnabled = YES; [recorder recordForDuration:5]; [recorder prepareToRecord]; [recorder record]; ```

Original source