---
title: "MicRecorder | Micdrop"
description: "The MicRecorder class provides functionality for recording audio from a microphone with voice activity detection (VAD)."
url: "https://micdrop.dev/docs/client/utility-classes/mic-recorder"
---

*   [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)

# MicRecorder

The `MicRecorder` class provides functionality for recording audio from a microphone with voice activity detection (VAD). It uses the browser’s MediaRecorder API and integrates with a VAD (Voice Activity Detection) system for speech detection.

## Overview

The `MicRecorder` class is a core component that can be used in two ways:

1.  **As part of MicdropClient**: The `MicRecorder` is automatically managed by `MicdropClient` when using it for voice conversations. `MicdropClient` creates an instance internally and handles all the microphone setup, speech detection, and audio streaming.
    
2.  **As a standalone component**: You can use `MicRecorder` directly if you only need microphone recording and speech detection functionality without the WebSocket communication and conversation management provided by `MicdropClient`.
    

This flexibility allows you to either use the full voice conversation capabilities through `MicdropClient`, or implement your own custom audio handling using just the microphone recording features of `MicRecorder`.

## Features

*   Voice activity detection (VAD)
*   Multiple audio format support (ogg, webm, mp4, wav)
*   Event-based architecture
*   State management

## Usage Example

```
import { MicRecorder } from '@micdrop/client'
// Create a new recorder instance with VAD config (string, VAD instance, or array)const recorder = new MicRecorder('volume')
// Get microphone streamconst stream = await navigator.mediaDevices.getUserMedia({ audio: true })
// Start recordingawait recorder.start(stream)
// Listen for eventsrecorder.on('StartSpeaking', () => {  console.log('User started speaking')})
recorder.on('StopSpeaking', () => {  console.log('User stopped speaking')})
recorder.on('Chunk', (blob: Blob) => {  // Handle audio chunk  console.log('Received audio chunk:', blob)})
```

## State

The recorder maintains a state object with the following properties:

```
interface MicRecorderState {  isStarting: boolean // Whether the recorder is in the process of starting  isStarted: boolean // Whether the recorder is currently active  isSpeaking: boolean // Whether speech is currently detected}
```

## Events

The recorder emits the following events:

*   `Chunk`: Emitted when a new audio chunk is available (with Blob data)
*   `StartSpeaking`: Emitted when speech is detected
*   `StopSpeaking`: Emitted when speech ends
*   `StateChange`: Emitted when the recorder’s state changes

## Methods

### `constructor(vadConfig?: VADConfig)`

Creates a new MicRecorder instance with the provided VAD config. The config can be:

*   A string (`'volume'` or `'silero'`)
*   A VAD instance
*   An array of VAD configs for multiple VADs

### `start(stream: MediaStream): Promise<void>`

Starts the recorder with the provided audio stream.

### `stop(): void`

Stops the recorder and cleans up resources.

## VAD

The `MicRecorder` class uses a VAD (Voice Activity Detection) system to detect speech. You can access the internal VAD instance via `recorder.vad` to update options or listen to VAD-specific events.

See [VAD documentation](/docs/client/vad) for more information and available options.

## Technical Details

*   Uses a delayed stream to avoid cutting off speech at the beginning of detection
*   Audio is recorded in chunks of 100ms when speech is detected
*   Default audio settings: 128kbps bitrate
*   Supports multiple audio formats with fallback options

[Previous← MicdropClient](/docs/client/utility-classes/micdrop-client)[NextSpeaker →](/docs/client/utility-classes/speaker)

On this page

*   [Overview](#overview)
*   [Features](#features)
*   [Usage Example](#usage-example)
*   [State](#state)
*   [Events](#events)
*   [Methods](#methods)
*   [constructor(vadConfig?: VADConfig)](#constructorvadconfig-vadconfig)
*   [start(stream: MediaStream): Promise<void>](#startstream-mediastream-promisevoid)
*   [stop(): void](#stop-void)
*   [VAD](#vad)
*   [Technical Details](#technical-details)
