Introduction
React Voice Visualizer is a comprehensive audio recording and visualization library built on top of the Web Audio API. It provides a clean separation between state management (via hooks) and visualization (via components), making it easy to integrate audio recording capabilities into React applications.Architecture
The library follows a modular architecture with two primary parts:Hook Layer - useVoiceVisualizer
Manages all recording and playback state, handles audio processing, and provides control functions. This hook encapsulates the complex Web Audio API logic.
Separation of Concerns
- Use the hook independently for custom UIs
- Access recording state and controls programmatically
- Customize the visualization component without touching logic
Data Flow
The library processes audio through a series of Web Audio API nodes:Audio Capture
navigator.mediaDevices.getUserMedia() requests microphone access and returns a MediaStreamDual Processing
The stream is connected to two paths:
- MediaRecorder: Records audio chunks and generates a Blob when stopped
- AudioContext + AnalyserNode: Provides real-time frequency data for visualization
Real-time Visualization
The AnalyserNode continuously outputs frequency data into a
Uint8Array, which is rendered on canvas using requestAnimationFrameKey Web Audio API Concepts
AudioContext
TheAudioContext is the central object for all audio processing:
The AudioContext creates and connects various audio processing nodes. Learn more in the Web Audio API documentation.
AnalyserNode
Provides real-time frequency and time-domain analysis:MediaRecorder
Records the audio stream and produces a Blob:AudioBuffer
When recording stops, the Blob is decoded into an AudioBuffer:Canvas Rendering
All visualization is rendered on an HTML5 Canvas element:- Live Recording: Uses
drawByLiveStreamto render time-domain data from the AnalyserNode - Recorded Audio: Uses
drawByBlobto render a static waveform from the AudioBuffer
The canvas uses
devicePixelRatio for crisp rendering on high-DPI displays. The actual canvas width may be 2x or 3x the CSS width (VoiceVisualizer.tsx:352).Internal Reference Management (v2.x.x)
Starting in version 2.x.x, the library manages the audio element reference (
audioRef) internally. You no longer need to pass ref={audioRef} to components manually.useRef to maintain references to:
audioRef- HTMLAudioElement for playback (useVoiceVisualizer.tsx:53)mediaRecorderRef- MediaRecorder instance (useVoiceVisualizer.tsx:46)audioContextRef- AudioContext for processing (useVoiceVisualizer.tsx:47)analyserRef- AnalyserNode for real-time data (useVoiceVisualizer.tsx:48)canvasRef- Canvas element for rendering (VoiceVisualizer.tsx:145)
clearCanvas() is called.
Next Steps
Recording
Learn how audio recording works with MediaRecorder
Visualization
Understand canvas rendering and audio data processing
Playback
Explore audio playback and synchronized visualization
API Reference
View the complete hook API documentation

