Real-Time Analysis
Analyze BPM while audio or video is playing, with instant feedback and continuous monitoring capabilities.
A powerful, dependency-free TypeScript library for analyzing beats-per-minute (BPM) of audio and video sources directly in your browser
Install via npm:
npm install realtime-bpm-analyzerAnalyze BPM in real-time:
import { createRealtimeBpmAnalyzer, getBiquadFilter } from 'realtime-bpm-analyzer';
// Create audio context
const audioContext = new AudioContext();
// Create the BPM analyzer processor
const bpmAnalyzer = await createRealtimeBpmAnalyzer(audioContext);
// Set up audio source
const track = document.getElementById('audio') as HTMLAudioElement;
const source = audioContext.createMediaElementSource(track);
const lowpass = getBiquadFilter(audioContext);
// Connect nodes
source.connect(lowpass).connect(bpmAnalyzer.node);
source.connect(audioContext.destination);
// Listen for BPM events
const handleBpm = (data) => console.log('Current BPM:', data.bpm);
const handleStable = (data) => console.log('Stable BPM detected:', data.bpm);
bpmAnalyzer.on('bpm', handleBpm);
bpmAnalyzer.on('bpmStable', handleStable);
// Cleanup when done
// bpmAnalyzer.removeEventListener('bpm', handleBpm);
// bpmAnalyzer.removeEventListener('bpmStable', handleStable);🎵 Perfect for: