1

When setting the preferred sample rate to 16000 it is working fine. However, when I want to play the sound from the speaker and print the sample rate I find it 48000.

I tried to set the sample rate again after playing from the speaker, but it is not working.

NSError    *err = nil;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:NO error:&err];
BOOL successfullySatSampleRate = [session setPreferredSampleRate:SAMPLING_FREQUENCY error:&err];
if(err != nil)
{
    NSLog(@"Error in setting up audio: %@", err);
}
if(!successfullySatSampleRate)
{
    NSLog(@"Error in setting up sample rate");
}
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error: nil];
[session setActive:YES error:&err];

NSLog(@"initialize Session preferredSampleRate = %f, hardware sampleRate = %f",[session preferredSampleRate],[session sampleRate]);

What should I do to keep the sample rate 16000?

mahdi
  • 149
  • 12
  • Did you ever figure out a solution? I saw that in my app on iPhone 11 and move devices, calling `setPreferredSampleRate` does nothing, while on lower devices it works, and I don't know why. – Lucas P. May 25 '20 at 16:12
  • Did you find solution to this? I am facing similar issue. – Bhagyesh Jul 22 '20 at 16:34

0 Answers0