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.

Getting the Current State

To check the current input audio state:

const audioState: InputAudioState = anamClient.getInputAudioState();
// { isMuted: false } or { isMuted: true }

Mute Audio Input

To mute the input audio:

const audioState: InputAudioState = anamClient.muteInputAudio();
// { isMuted: true }

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

Unmute Audio Input

To unmute the input audio:

const audioState: InputAudioState = anamClient.unmuteInputAudio();
// { isMuted: false }

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:

anamClient.streamToVideoAndAudioElements(
  'video-element-id',
  'audio-element-id',
  userProvidedMediaStream
);

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.

This is the default behavior if you are using navigator.mediaDevices.getUserMedia().

Next Steps

Session Configuration

Understand additional configuration options for your Anam sessions