---
title: "Recording Audio | Micdrop"
description: "The MicdropRecorder class enables recording of audio messages during voice calls, capturing both user and assistant audio with their corresponding conversation…"
url: "https://micdrop.dev/docs/server/recording-audio"
---

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

# Recording Audio

The `MicdropRecorder` class enables recording of audio messages during voice calls, capturing both user and assistant audio with their corresponding conversation messages.

## Basic Usage

```
import { MicdropServer, MicdropRecorder, Logger } from '@micdrop/server'
const server = new MicdropServer(socket, { agent, stt, tts })
// Create recorderconst recorder = new MicdropRecorder(server)recorder.logger = new Logger('MicdropRecorder')
// Listen for audio messagesrecorder.on('AudioMessage', (audioMessage) => {  console.log('Audio recorded:', {    role: audioMessage.role,    messageIndex: audioMessage.messageIndex,    bufferSize: audioMessage.buffer.length,  })})
// Get all recordings when call endsrecorder.on('Complete', (audioMessages) => {  console.log(`Call complete with ${audioMessages.length} audio messages`)})
```

## AudioMessage Structure

Each `AudioMessage` contains:

```
interface AudioMessage {  buffer: Buffer // Raw audio data  messageIndex: number // Index in agent.conversation  message: string // The message content  role: 'user' | 'assistant' // Speaker role}
```

## Saving to File

Save audio messages incrementally as they arrive:

```
import { writeFileSync } from 'fs'
const audioMessages: object[] = []
recorder.on('AudioMessage', (audioMessage) => {  const data = {    messageIndex: audioMessage.messageIndex,    message: audioMessage.message,    role: audioMessage.role,    buffer: audioMessage.buffer.toString('base64'),    timestamp: new Date().toISOString(),  }  audioMessages.push(data)  writeFileSync('recording.json', JSON.stringify(audioMessages, null, 2))})
```

## Recorder Events

The recorder emits the following events:

Event

Payload

Description

`AudioMessage`

`AudioMessage`

Emitted when an audio message is complete

`Complete`

`AudioMessage[]`

Emitted when the call ends with all recordings

## Server Events

`MicdropRecorder` relies on events from `MicdropServer`:

Event

Payload

Description

`UserAudio`

`Buffer`

Raw audio chunk from user

`AssistantAudio`

`Buffer`

Raw audio chunk from TTS

`End`

`MicdropCallSummary`

Call ended

You can also listen to these events directly on `MicdropServer`:

```
server.on('UserAudio', (chunk) => {  console.log('User audio chunk:', chunk.length, 'bytes')})
server.on('AssistantAudio', (chunk) => {  console.log('Assistant audio chunk:', chunk.length, 'bytes')})
server.on('End', (summary) => {  console.log('Call ended:', summary)})
```

## Cleanup

Call `destroy()` to clean up listeners when done:

```
recorder.destroy()
```

## Technical Notes

*   User audio chunks arrive **before** the user message is added to the conversation
*   The recorder buffers chunks and associates them with messages when available
*   Assistant audio is finalized when the next user speech begins or when the call ends
*   Audio is stored as raw PCM buffers (16kHz, 16-bit, mono)

[Previous← Resume a Conversation](/docs/server/resume-conversation)[NextError Handling →](/docs/server/error-handling)

On this page

*   [Basic Usage](#basic-usage)
*   [AudioMessage Structure](#audiomessage-structure)
*   [Saving to File](#saving-to-file)
*   [Recorder Events](#recorder-events)
*   [Server Events](#server-events)
*   [Cleanup](#cleanup)
*   [Technical Notes](#technical-notes)
