Introduction
Wavesurfer.js renders navigable audio waveforms directly in the browser using the Web Audio API for decoding and HTML5 Canvas for drawing. It lets users see the shape of audio content, click to seek, zoom in for detail, and add region markers or annotations, making it popular in podcast editors, music apps, and transcription tools.
What Wavesurfer.js Does
- Renders audio waveforms from any browser-supported audio format
- Provides click-to-seek and drag-to-scroll navigation on the waveform
- Supports zoom and responsive resizing of the waveform display
- Offers a plugin system for regions, timeline, spectrogram, and minimap
- Handles pre-computed peaks data for server-rendered waveforms
Architecture Overview
Wavesurfer.js decodes audio using the Web Audio API's AudioContext.decodeAudioData method, extracting PCM sample data for waveform rendering. The peaks are downsampled to match the canvas width and drawn as vertical bars or continuous lines. Playback progress is tracked via requestAnimationFrame, updating the progress overlay in real time. The plugin architecture uses an event emitter pattern, allowing extensions like Regions and Timeline to hook into lifecycle events without modifying the core.
Self-Hosting & Configuration
- Install via npm and import, or load from a CDN
- Set
containerto a CSS selector or DOM element for the waveform target - Customize colors with
waveColor,progressColor, andcursorColor - Pass
peaksanddurationto skip client-side audio decoding for large files - Use the Regions plugin for annotating and looping specific audio segments
Key Features
- Real-time waveform rendering with Web Audio API decoding
- Interactive seeking, scrolling, and zooming
- Region markers for annotation, looping, and segment editing
- Spectrogram and minimap visualization plugins
- Server-side peak pre-computation for instant rendering of large files
Comparison with Similar Tools
- Peaks.js — BBC-maintained with similar features; Wavesurfer.js has broader plugin ecosystem
- Howler.js — audio playback library without visualization; Wavesurfer.js combines both
- Tone.js — synthesis and effects framework; Wavesurfer.js focuses on visualization and playback
- Amplitude.js — playlist management with UI; Wavesurfer.js provides detailed waveform control
FAQ
Q: Can I render waveforms without playing the audio? A: Yes. Pass pre-computed peaks data and the waveform renders instantly without decoding the audio file.
Q: Does it support live audio or streaming? A: Wavesurfer.js supports the MediaElement backend for streaming audio and live microphone input via plugins.
Q: How do I add loop regions?
A: Import the Regions plugin, call wavesurfer.registerPlugin(RegionsPlugin.create()), then add regions with start and end times.
Q: What audio formats are supported? A: Any format the browser's Web Audio API can decode, typically MP3, WAV, OGG, FLAC, and AAC.