Search code examples
iosavaudiosessionvoice-recording

SpeakHere Voice recorder app Speakers not working -iOS


I am using SpeakHere example code provided by Apple in my project.

How can I enable speakers If earphones or headphones are not plugged in?

I know I can overwrite the route using the following code..

OSStatus error;
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; 
error = AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
if (error) printf("couldn't set audio speaker!");

But I don't want that because if earphones are plugged in, the sound should be coming out of them..


Solution

  • Most likely this is what you are looking for:

        UInt32 overrideValue = 1;
        AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(overrideValue), &overrideValue);
    

    From the docs: Specifies whether or not to route audio to the speaker (instead of to the receiver) when no other audio route, such as a headset, is connected.