---
title: "MicdropClient"
description: "The MicdropClient class manages real-time audio communication between a client and server, handling microphone input, WebSocket connections, and audio playback."
url: "https://micdrop.dev/docs/client/utility-classes/micdrop-client"
---

*   [Getting Started](/docs/getting-started)
*   [Client (Browser)](/docs/client)
    
    *   [Installation](/docs/client/installation)
    *   [React Hooks](/docs/client/react-hooks)
    *   [Start/Stop Call](/docs/client/start-stop-call)
    *   [Pause/Resume Call](/docs/client/pause-resume-call)
    *   [Mute/Unmute Call](/docs/client/mute-unmute-call)
    *   [Call State](/docs/client/call-state)
    *   [Display Conversation Messages](/docs/client/display-conversation-messages)
    *   [Handling Tool Calls](/docs/client/handling-tool-calls)
    *   [Device Management](/docs/client/devices-management)
    *   [Voice Activity Detection (VAD)](/docs/client/vad)
    *   [Error Handling](/docs/client/error-handling)
    *   Utility Classes
        
        *   [Mic](/docs/client/utility-classes/mic)
        *   [MicdropClient](/docs/client/utility-classes/micdrop-client)
        *   [MicRecorder](/docs/client/utility-classes/mic-recorder)
        *   [Speaker](/docs/client/utility-classes/speaker)
        
    
*   [Server (Node.js)](/docs/server)
    
    *   [Installation](/docs/server/installation)
    *   [With Fastify](/docs/server/with-fastify)
    *   [With NestJS](/docs/server/with-nestjs)
    *   [Auth and Parameters](/docs/server/auth-and-parameters)
    *   [First Message](/docs/server/first-message)
    *   [Save Messages](/docs/server/save-messages)
    *   [Resume a Conversation](/docs/server/resume-conversation)
    *   [Recording Audio](/docs/server/recording-audio)
    *   [Error Handling](/docs/server/error-handling)
    *   [Tools](/docs/server/tools)
    *   [Extract Value from Answer](/docs/server/extract)
    *   [Auto End Call](/docs/server/auto-end-call)
    *   [Semantic Turn Detection](/docs/server/semantic-turn-detection)
    *   [Noise Filtering](/docs/server/noise-filtering)
    *   [Micdrop Protocol](/docs/server/protocol)
    
*   [AI Integrations](/docs/ai-integration)
    
    *   Provided Integrations
        
        *   [AI SDK](/docs/ai-integration/provided-integrations/ai-sdk)
        *   [Cartesia](/docs/ai-integration/provided-integrations/cartesia)
        *   [ElevenLabs](/docs/ai-integration/provided-integrations/elevenlabs)
        *   [Gladia](/docs/ai-integration/provided-integrations/gladia)
        *   [Gradium](/docs/ai-integration/provided-integrations/gradium)
        *   [Mistral](/docs/ai-integration/provided-integrations/mistral)
        *   [OpenAI](/docs/ai-integration/provided-integrations/openai)
        
    *   Custom Integrations
        
        *   [Agent (LLM)](/docs/ai-integration/custom-integrations/custom-agent)
        *   [Speech-to-Text (STT)](/docs/ai-integration/custom-integrations/custom-stt)
        *   [Text-to-Speech (TTS)](/docs/ai-integration/custom-integrations/custom-tts)
        
    *   Fallback Strategies
        
        *   [FallbackAgent](/docs/ai-integration/fallback-strategies/agent-fallback)
        *   [FallbackSTT](/docs/ai-integration/fallback-strategies/stt-fallback)
        *   [FallbackTTS](/docs/ai-integration/fallback-strategies/tts-fallback)
        
    *   [IA Vocale Souveraine 🇫🇷🇪🇺](/docs/ai-integration/sovereign-voice-ai)
    

[Micdrop](/) › [Documentation](/docs/getting-started)

# MicdropClient

The `MicdropClient` class manages real-time audio communication between a client and server, handling microphone input, WebSocket connections, and audio playback. It’s designed to facilitate interactive voice conversations with support for bi-directional audio streaming.

For server implementation, see [@micdrop/server](/docs/server) package.

## Usage Example

⚠️ In most cases, you should not use the constructor directly, but use the `Micdrop.start()` method instead (see [Start/Stop Call](/docs/client/start-stop-call)). An instance is already created and available as `Micdrop` object.

```
import { MicdropClient } from '@micdrop/client'
// Start a callconst micdrop = new MicdropClient({  // URL of the WebSocket server (using @micdrop/server)  url: 'wss://your-server.com/ws',  // Parameters (optional) to check auth or provide other data  params: {    authorization: '1234',    lang: navigator.language,  },  // Voice Activity Detection (see docs)  vad: ['volume', 'silero'],  // Disable ability for the user to interrupt the assistant when it is speaking  disableInterruption: true,  // Enable debug logging  debugLog: true,})
// Start the call// You can also pass options instead or in addition to the constructorawait micdrop.start()
// Pause/resumemicdrop.pause()micdrop.resume()
// Stop the callawait micdrop.stop()
// Listen for state changesmicdrop.on('StateChange', (state) => {  console.log('State:', state) // See below for state properties})
// Listen for end of call// Can be triggered via prompting (see server docs)micdrop.on('EndCall', () => {  console.log('Call ended by assistant')})
// Listen for errorsmicdrop.on('Error', (error) => {  console.error('Error occurred:', error)})
```

## Options

You can pass options to `MicdropClient` constructor or to the `start` method:

*   `url`: URL of the WebSocket server (using @micdrop/server)
*   `params`: Parameters (optional) to check auth or provide other data
*   `vad`: VAD configuration (see [VAD](/docs/client/vad) section)
*   `disableInterruption`: If true, disables automatic mic muting when the assistant is speaking (default: false)
*   `debugLog`: Boolean flag to enable/disable debug logging
*   `reconnect`: Automatic reconnection configuration
    *   `maxAttempts`: Maximum number of reconnection attempts (default: Infinity)
    *   `delayMs`: Delay between reconnection attempts in milliseconds (default: 1000)
    *   `connectionTimeout`: Timeout for WebSocket connection in milliseconds (default: 5000)

## Events

The `MicdropClient` emits the following events:

*   `EndCall`: Emitted when the call ends
*   `Error`: Emitted when an error occurs, provides a `MicdropClientError` object
*   `StateChange`: Emitted when any state change occurs in the handler, provides a `MicdropState` object

## Properties

Accessible properties that must not be changed:

*   `vad`: The VAD instance in use
*   `micRecorder`: Instance of `MicRecorder` for handling microphone input
*   `micDevices`: Array of available microphone devices
*   `speakerDevices`: Array of available speaker devices

## State

You can get state in multiple ways:

```
// Get a specific state propertyconsole.log('Is started', Micdrop.isStarted)
// Get the whole stateconsole.log('State', Micdrop.state)console.log('Is started', Micdrop.state.isStarted)
// Listen to state changesMicdrop.on('StateChange', (state) => {  console.log('State:', state)})
```

### State Properties

```
interface MicdropState {  // True if either WebSocket or microphone are in starting state  isStarting: boolean
  // True if both WebSocket and microphone recording are active  isStarted: boolean
  // True if the client is attempting to reconnect after a connection loss  isReconnecting: boolean
  // True if the microphone is paused (muted by user)  isPaused: boolean
  // True if the client is actively listening for user speech (not paused, not processing, not muted, not speaking)  isListening: boolean
  // True if the call is processing (i.e. waiting for answer and audio generation)  isProcessing: boolean
  // True if the user is currently speaking  isUserSpeaking: boolean
  // True if the assistant is currently speaking  isAssistantSpeaking: boolean
  // True if microphone stream is active  isMicStarted: boolean
  // True if the microphone is muted  isMicMuted: boolean
  // The ID of the microphone device in use  micDeviceId: string | undefined
  // The ID of the speaker device in use  speakerDeviceId: string | undefined
  // Array of available microphone devices  micDevices: MediaDeviceInfo[]
  // Array of available speaker devices  speakerDevices: MediaDeviceInfo[]
  // Array storing the conversation history  conversation: MicdropConversation
  // The error object if an error occurred  error: MicdropClientError | undefined}
```

See [Call State](/docs/client/call-state) for more details.

## Methods

### Core Methods

Start the call (starts the microphone and WebSocket connection):

```
async start(options?: MicdropOptions): Promise<void>
```

Stop the call (stops the microphone and WebSocket connection):

```
async stop(): Promise<void>
```

Pause the call (pauses the microphone and speaker):

```
pause(): void
```

Resume the call (resumes the microphone):

```
resume(): void
```

### Microphone Control

```
async startMic(params: {  vad?: VADConfig  deviceId?: string}): Promise<void>
```

Starts the microphone with optional device selection and recording control.

It can by usefull if you want to start the microphone before the call starts.

*   `vad`: VAD configuration (see [VAD](/docs/client/vad) section)
*   `deviceId`: Device ID to use for the microphone

### Devices Control

Select microphone device:

```
async changeMicDevice(deviceId: string): Promise<void>
```

Select speaker device:

```
async changeSpeakerDevice(deviceId: string): Promise<void>
```

Example:

```
const micDeviceId = micdrop.micDevices[0].deviceIdconst speakerDeviceId = micdrop.speakerDevices[0].deviceIdawait micdrop.changeMicDevice(micDeviceId)await micdrop.changeSpeakerDevice(speakerDeviceId)
```

See more complete example in demo [DevicesSettings](https://github.com/Godefroy/micdrop/blob/main/examples/demo-client/src/DevicesSettings.tsx) component.

## Voice Activity Detection (VAD)

Micdrop uses a VAD (Voice Activity Detection) to detect speech and silence and send chunks of audio to server only when speech is detected. For detailed information about the VAD implementations and configuration options, please refer to the [VAD documentation](/docs/client/vad).

## Error Handling

The handler uses `MicdropClientError` for error management. Each error instance contains a specific error code that helps identify the type of error that occurred.

Example handling different error types:

```
Micdrop.on('Error', (error) => {  switch (error.code) {    case MicdropClientErrorCode.Mic:      console.error('Microphone error - check permissions or hardware')      break    case MicdropClientErrorCode.MissingUrl:      console.error('Missing URL - check url in Micdrop options')      break    case MicdropClientErrorCode.BadRequest:      console.error('Bad request - check params in Micdrop options')      break    case MicdropClientErrorCode.NotFound:      console.error('Not found - check server implementation')      break    case MicdropClientErrorCode.Connection:      console.error('Connection error - check server implementation')      break    case MicdropClientErrorCode.InternalServer:      console.error('Internal server error - check server logs')      break    case MicdropClientErrorCode.Unauthorized:      console.error('Authentication failed - check credentials')      break    case MicdropClientErrorCode.Error:      console.error('General error occurred')      break  }})
```

[Previous← Mic](/docs/client/utility-classes/mic)[NextMicRecorder →](/docs/client/utility-classes/mic-recorder)

On this page

*   [Usage Example](#usage-example)
*   [Options](#options)
*   [Events](#events)
*   [Properties](#properties)
*   [State](#state)
*   [State Properties](#state-properties)
*   [Methods](#methods)
*   [Core Methods](#core-methods)
*   [Microphone Control](#microphone-control)
*   [Devices Control](#devices-control)
*   [Voice Activity Detection (VAD)](#voice-activity-detection-vad)
*   [Error Handling](#error-handling)
