2

I am using Twilio client voice call service for calling.

Here I am facing issue in spearke ON/OFF feature.I am able to Mute/Unmute call but not able to turn On/OFF speaker. I have a same instance for both functionality. I have also checked their demo project basic phone in that this speaker ON/OFF is working and I am doing same thing in my project bur not able to do the same.

Here is my code:

if(isSpeaker == NO)
{
     isSpeaker=YES;
     [self.phone setSpeakerEnabled:YES];
}
else{
     isSpeaker=NO;
     [self.phone setSpeakerEnabled:NO];
}

self.phone is the sharedInstance of BasicPhone (their call manager class) and I am testing application in > iOS 9 both demo and my project.

Megan Speir
  • 3,745
  • 1
  • 15
  • 25
Ajay Gabani
  • 1,168
  • 22
  • 38

2 Answers2

3

I've used this code on iOS to successfully enable/disable speakerphone. It doesn't use the Twilio device, and is somewhat specific to React Native, but the core of each function should work:

RCT_EXPORT_METHOD(setSpeakerPhoneOn) {
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *error;

[session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
}

RCT_EXPORT_METHOD(setSpeakerPhoneOff) {
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *error;

[session overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&error];
}
virty4
  • 129
  • 4
0

Swift 5, use below code snippet

// Change the audio route after connecting to a Room.

func moveToMic() {

    audioDevice.block = {
        DefaultAudioDevice.DefaultAVAudioSessionConfigurationBlock()
        do {
            try AVAudioSession.sharedInstance().setMode(.voiceChat)
            try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
        } catch {
            print(error)
        }
    }

    audioDevice.block();

}

func moveToSpeaker() {

    audioDevice.block = {
        DefaultAudioDevice.DefaultAVAudioSessionConfigurationBlock()
        do {
            try AVAudioSession.sharedInstance().setMode(.videoChat)
            try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
        } catch {
            print(error)
        }
    }

    audioDevice.block();

}