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

# Audio Controls

Control audio during an active call session. These methods allow you to mute/unmute the local microphone and change the audio output device.

## Prerequisites

* An active [call session](/calls/flutter/join-session)
* Access to the `CallSession` instance

## Get CallSession Instance

All audio control methods are called on the `CallSession` singleton:

```dart theme={null}
CallSession? callSession = CallSession.getInstance();
```

<Note>
  `CallSession.getInstance()` returns `null` if no active session exists. Always use the null-aware `?.` operator when calling methods.
</Note>

***

## Mute Audio

Mute the local microphone. Other participants will no longer hear you.

```dart theme={null}
await CallSession.getInstance()?.muteAudio();
```

<Note>
  When you mute your audio, the `onAudioMuted()` callback is triggered on your `MediaEventsListener`.
</Note>

***

## Unmute Audio

Unmute the local microphone to resume transmitting audio.

```dart theme={null}
await CallSession.getInstance()?.unMuteAudio();
```

<Note>
  When you unmute your audio, the `onAudioUnMuted()` callback is triggered on your `MediaEventsListener`.
</Note>

***

## Toggle Mute Audio

Convenience method that toggles between muted and unmuted audio. It checks the current state and calls the appropriate action automatically.

```dart theme={null}
await CallSession.getInstance()?.toggleMuteAudio();
```

***

## Set Audio Mode

Change the audio output device during a call. This allows users to switch between speaker, earpiece, or Bluetooth.

```dart theme={null}
// Switch to speaker
await CallSession.getInstance()?.setAudioModeType(AudioMode.speaker);

// Switch to earpiece
await CallSession.getInstance()?.setAudioModeType(AudioMode.earpiece);

// Switch to Bluetooth
await CallSession.getInstance()?.setAudioModeType(AudioMode.bluetooth);
```

### AudioMode Enum

| Value                 | Description                                      |
| --------------------- | ------------------------------------------------ |
| `AudioMode.speaker`   | Route audio through the device speaker           |
| `AudioMode.earpiece`  | Route audio through the phone earpiece           |
| `AudioMode.bluetooth` | Route audio through a connected Bluetooth device |

<Note>
  When the audio mode changes, the `onAudioModeChanged(AudioMode)` callback is triggered on your `MediaEventsListener`.
</Note>

***

## Check Audio Mute State

Use the `isAudioMuted` state getter to check whether the local microphone is currently muted.

```dart theme={null}
bool? muted = CallSession.getInstance()?.isAudioMuted;
```

| Return Type | Description                                                              |
| ----------- | ------------------------------------------------------------------------ |
| `bool?`     | `true` if audio is muted, `false` otherwise, `null` if no active session |

***

## Listen for Audio Events

Register a `MediaEventsListener` to receive callbacks when audio state changes:

```dart theme={null}
CallSession.getInstance()?.addMediaEventsListener(MediaEventsListener(
  onAudioMuted: () {
    debugPrint("Audio muted");
    // Update UI to show muted state
  },
  onAudioUnMuted: () {
    debugPrint("Audio unmuted");
    // Update UI to show unmuted state
  },
  onAudioModeChanged: (AudioMode audioMode) {
    debugPrint("Audio mode changed to: $audioMode");
    // Update UI to reflect new audio mode
  },
));
```

<Note>
  Flutter listeners are not lifecycle-aware. You must manually remove listeners in your widget's `dispose()` method to prevent memory leaks.
</Note>

***

## Initial Audio Settings

You can configure the initial audio state when joining a session using `SessionSettings`:

```dart theme={null}
SessionSettings sessionSettings = CometChatCalls.SessionSettingsBuilder()
    .startAudioMuted(true)                 // Start with microphone muted
    .setAudioMode(AudioMode.speaker)       // Start with speaker output
    .build();
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Video Controls" icon="video" href="/calls/flutter/video-controls">
    Control video during calls
  </Card>

  <Card title="Media Events Listener" icon="bell" href="/calls/flutter/media-events-listener">
    Handle all media events
  </Card>
</CardGroup>
