> ## Documentation Index
> Fetch the complete documentation index at: https://anam.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Audio Control

> Control audio input and streaming behavior

## Audio Input State

By default, the Anam client starts capturing input audio from the user's microphone when a session starts and stops capturing when the session ends. For certain use cases, you may wish to control the input audio state programmatically.

### The InputAudioState Type

The `InputAudioState` interface contains two properties:

```typescript theme={"system"}
interface InputAudioState {
  isMuted: boolean;
  permissionState: AudioPermissionState;
}

enum AudioPermissionState {
  PENDING = 'pending',
  GRANTED = 'granted',
  DENIED = 'denied',
  NOT_REQUESTED = 'not_requested',
}
```

### Getting the Current State

To check the current input audio state:

```typescript theme={"system"}
import { InputAudioState, AudioPermissionState } from '@anam-ai/js-sdk';

const audioState: InputAudioState = anamClient.getInputAudioState();
// { isMuted: false, permissionState: 'granted' }

// Check if microphone permission was granted
if (audioState.permissionState === AudioPermissionState.DENIED) {
  console.log('Microphone access was denied');
}
```

### Mute Audio Input

To mute the input audio:

```typescript theme={"system"}
const audioState: InputAudioState = anamClient.muteInputAudio();
// { isMuted: true, permissionState: 'granted' }
```

<Note>
  If you mute the input audio before starting a stream, the session will start with microphone input disabled.
</Note>

### Unmute Audio Input

To unmute the input audio:

```typescript theme={"system"}
const audioState: InputAudioState = anamClient.unmuteInputAudio();
// { isMuted: false, permissionState: 'granted' }
```

## Changing Audio Input Device

To switch to a different microphone during an active session:

```typescript theme={"system"}
// Get available audio input devices
const devices = await navigator.mediaDevices.enumerateDevices();
const audioInputs = devices.filter(device => device.kind === 'audioinput');

// Switch to a specific device by its ID
await anamClient.changeAudioInputDevice(audioInputs[1].deviceId);
```

<Note>
  You must be actively streaming to change the audio input device. This method throws an error if called before `streamToVideoElement()`.
</Note>

## Configuration Options

### Disabling Audio Input

To completely disable microphone input (useful for text-only interactions or when using custom input streams):

```typescript theme={"system"}
import { createClient } from '@anam-ai/js-sdk';

const anamClient = createClient(sessionToken, {
  disableInputAudio: true,
});
```

When `disableInputAudio` is `true`:

* The SDK will not request microphone permissions
* `muteInputAudio()` and `unmuteInputAudio()` will have no effect
* Any user-provided audio stream will be ignored

### Specifying an Audio Device

To use a specific microphone at initialization:

```typescript theme={"system"}
const anamClient = createClient(sessionToken, {
  audioDeviceId: 'specific-device-id',
});
```

## Custom Input Streams

If you wish to control the microphone input audio capture yourself, you can pass your own `MediaStream` object when starting a stream:

```typescript theme={"system"}
// Get your own media stream
const userProvidedMediaStream = await navigator.mediaDevices.getUserMedia({
  audio: true,
  video: false,
});

anamClient.streamToVideoElement(
  'video-element-id',
  userProvidedMediaStream
);
```

<Note>
  The `userProvidedMediaStream` object must be an instance of `MediaStream` and the user input audio should be the first audio track returned from the `MediaStream.getAudioTracks()` method.
</Note>

<Tip>
  This is the default behavior if you are using `navigator.mediaDevices.getUserMedia()`.
</Tip>
