Mic
The Mic module provides functionality for managing microphone input and audio recording in the browser.
Features
- 🎤 Microphone input device management
- 🔊 Audio stream handling
- 📊 Real-time audio analysis
- 💾 Persistent device selection
Usage Example
import { Mic } from '@micdrop/client'
// Start microphone with default deviceconst stream = await Mic.start()
// Start microphone with specific deviceconst deviceStream = await Mic.start('device-id')
// Stop microphone and cleanup when doneMic.stop()
// Monitor volume changes using the audio analyser// Volume is in dB range -100 to 0Mic.analyser.on('volume', (volume: number) => { // Convert to 0-100 range for visualization if needed const normalizedVolume = Math.max(0, volume + 100) console.log('Current volume:', normalizedVolume)})API Reference
Functions
start(deviceId?: string): Promise<MediaStream>
Starts the microphone and returns the audio stream.
const stream = await Mic.start()or
const stream = await Mic.start(deviceId)stop(): void
Stops the microphone stream and cleans up resources.
Mic.stop()Variables
analyser
An instance of AudioAnalyser that can be used to analyze the microphone input.
Mic.analyser.on('volume', (volume: number) => { console.log('Current volume:', volume)})
// AnalyserNode// See https://developer.mozilla.org/docs/Web/API/AnalyserNodeconsole.log(Mic.analyser.node)Browser Support
Fully supported in Chrome, Firefox, Safari and Edge.
Requires support for:
- Web Audio API
- MediaDevices API