A for Alpha
A for Alpha

Reputation: 2912

poor sound quality while trying to record Audio in iPhone

I'm using AVAudioRecorder class for recording users input voice in my app. I am able to record and playback the sound. But, the quality of output is very low. I'm getting a lot of noise in the background while trying to playback the recorded audio. What should i do to get a rich quality audio output. I am using the following settings(code)to get the sound recorded.

NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
    [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatAppleLossless] forKey:AVFormatIDKey];
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; // previously i'v used 8400
    [recordSetting setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];

and the below code for playing the audio back

[[AVAudioSession sharedInstance] setCategory:
 AVAudioSessionCategoryPlayback error:NULL];

NSURL *fileTobePlayed = [NSURL fileURLWithPath:[[[[UIApplication sharedApplication]delegate] applicationDocumentsDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",currentPage]]];
//AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordedTmpFile error:&error];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileTobePlayed error:&error];

NSLog(@"The file being played is %@",fileTobePlayed);
[audioPlayer prepareToPlay];
[audioPlayer play];
audioPlayer.volume = 4.0;

Thanks..

Upvotes: 1

Views: 892

Answers (1)

CNSivakumar
CNSivakumar

Reputation: 1043

Using this code to added it.

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;     

            AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,          
                                     sizeof (audioRouteOverride),&audioRouteOverride);

Upvotes: 2

Related Questions