> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-angular-v5-docs-update.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Audio Modes

> Configure CometChat Calls SDK v5 audio modes on iOS for speakers, earpiece, Bluetooth, routing, and call audio behavior.

Control audio output routing during calls. Switch between speaker, earpiece, Bluetooth, and wired headphones based on user preference or device availability.

## Available Audio Modes

| Mode          | Description                                                 |
| ------------- | ----------------------------------------------------------- |
| `.speaker`    | Routes audio through the device loudspeaker                 |
| `.earpiece`   | Routes audio through the phone earpiece (for private calls) |
| `.bluetooth`  | Routes audio through a connected Bluetooth device           |
| `.headphones` | Routes audio through wired headphones                       |

## Set Initial Audio Mode

Configure the audio mode when joining a session:

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let sessionSettings = CometChatCalls.sessionSettingsBuilder
        .setAudioMode(.speaker)
        .build()

    CometChatCalls.joinSession(
        sessionID: sessionId,
        callSetting: sessionSettings,
        container: callViewContainer,
        onSuccess: { message in
            print("Joined with speaker mode")
        },
        onError: { error in
            print("Failed: \(error?.errorDescription ?? "")")
        }
    )
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objectivec theme={null}
    SessionSettings *sessionSettings = [[[CometChatCalls sessionSettingsBuilder]
        setAudioMode:AudioModeTypeSpeaker]
        build];

    [CometChatCalls joinSessionWithSessionID:sessionId
                                 callSetting:sessionSettings
                                   container:self.callViewContainer
                                   onSuccess:^(NSString * message) {
        NSLog(@"Joined with speaker mode");
    } onError:^(CometChatCallException * error) {
        NSLog(@"Failed: %@", error.errorDescription);
    }];
    ```
  </Tab>
</Tabs>

## Change Audio Mode During Call

Switch audio modes dynamically during an active call:

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    // Switch to speaker
    CallSession.shared.setAudioMode("SPEAKER")

    // Switch to earpiece
    CallSession.shared.setAudioMode("EARPIECE")

    // Switch to Bluetooth
    CallSession.shared.setAudioMode("BLUETOOTH")

    // Switch to wired headphones
    CallSession.shared.setAudioMode("HEADPHONES")
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objectivec theme={null}
    // Switch to speaker
    [[CallSession shared] setAudioMode:@"SPEAKER"];

    // Switch to earpiece
    [[CallSession shared] setAudioMode:@"EARPIECE"];

    // Switch to Bluetooth
    [[CallSession shared] setAudioMode:@"BLUETOOTH"];

    // Switch to wired headphones
    [[CallSession shared] setAudioMode:@"HEADPHONES"];
    ```
  </Tab>
</Tabs>

## Listen for Audio Mode Changes

Monitor audio mode changes using `MediaEventsListener`:

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    class CallViewController: UIViewController, MediaEventsListener {
        
        override func viewDidLoad() {
            super.viewDidLoad()
            CallSession.shared.addMediaEventsListener(self)
        }
        
        deinit {
            CallSession.shared.removeMediaEventsListener(self)
        }
        
        func onAudioModeChanged(audioModeType: AudioModeType) {
            switch audioModeType {
            case .speaker:
                print("Switched to speaker")
            case .earpiece:
                print("Switched to earpiece")
            case .bluetooth:
                print("Switched to Bluetooth")
            case .headphones:
                print("Switched to headphones")
            default:
                break
            }
            // Update audio mode button icon
            updateAudioModeIcon(audioModeType)
        }

        // Other callbacks...
        func onAudioMuted() {}
        func onAudioUnMuted() {}
        func onVideoPaused() {}
        func onVideoResumed() {}
        func onRecordingStarted() {}
        func onRecordingStopped() {}
        func onScreenShareStarted() {}
        func onScreenShareStopped() {}
        func onCameraFacingChanged(cameraFacing: CameraFacing) {}
    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objectivec theme={null}
    @interface CallViewController () <MediaEventsListener>
    @end

    @implementation CallViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        [[CallSession shared] addMediaEventsListener:self];
    }

    - (void)dealloc {
        [[CallSession shared] removeMediaEventsListener:self];
    }

    - (void)onAudioModeChangedWithAudioModeType:(AudioModeType)audioModeType {
        // Update audio mode button icon
        [self updateAudioModeIcon:audioModeType];
    }

    // Other callbacks...

    @end
    ```
  </Tab>
</Tabs>

## Hide Audio Mode Button

To prevent users from changing the audio mode, hide the button in the call UI:

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let sessionSettings = CometChatCalls.sessionSettingsBuilder
        .setAudioMode(.speaker)      // Fixed audio mode
        .hideAudioModeButton(true)   // Hide toggle button
        .build()
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objectivec theme={null}
    SessionSettings *sessionSettings = [[[[CometChatCalls sessionSettingsBuilder]
        setAudioMode:AudioModeTypeSpeaker]
        hideAudioModeButton:YES]
        build];
    ```
  </Tab>
</Tabs>

<Note>
  The SDK automatically detects connected audio devices. If Bluetooth or wired headphones are connected, they become available as audio mode options.
</Note>
