Wondering what’s next for npm?Check out our public roadmap! »


1.1.5 • Public • Published

RealTime BPM/Tempo Analyzer

Greenkeeper badge Build Status Coverage Status npm Join the chat at https://gitter.im/realtime-bpm-analyzer/Lobby

This tool allow to compute the BPM (Beats Per minutes) in real time, of a song on an <audio></audio> or <video></video> node thanks to the WebAudioAPI.

Please, note that the main use case for this tool, is to get the BPM during the video / audio play.


npm install realtime-bpm-analyzer -S


The WebAudioAPI provides a powerful and versatile system for controlling audio on the Web, allowing developers to choose audio sources, add effects to audio, create audio visualizations, apply spatial effects (such as panning) and much more.


You can find here a functionnal exemple of this tool with userMedia (microphone) and audioNode usage.

Usage / Requirements

  1. An AudioNode to analyze. So something like this :

    <audio src="./new_order-blue_monday.mp3" id="track"></audio>
  2. Connect the AudioNode to the AudioContext and create an AudioContext.createScriptProcessor().

    // Create new instance of AudioContext
    const audioContext = new AudioContext();
    // Set the source with the HTML Audio Node
    const source = audioContext.createMediaElementSource(document.getElementById('track'));
    // Set the scriptProcessorNode to get PCM data in real time
    const scriptProcessorNode = audioContext.createScriptProcessor(4096, 1, 1);
    // Connect everythings together
  3. Now you have just to configure the tool and attach it to the audioprocess event like this :

    import RealTimeBPMAnalyzer from 'realtime-bpm-analyzer';
    const onAudioProcess = new RealTimeBPMAnalyzer({
        scriptNode: {
            bufferSize: 4096,
            numberOfInputChannels: 1,
            numberOfOutputChannels: 1
        pushTime: 2000,
        pushCallback: (err, bpm) => {
            console.log('bpm', bpm);
    // Attach realTime function to audioprocess event.inputBuffer (AudioBuffer)
    scriptProcessorNode.onaudioprocess = (e) => {

Technical approch

This tool has been largely inspired by the Tornqvist project.

His algorithm use an AudioBuffer in input. We apply a lowpass filter to get only bass frequencies.

Now, we extract brut data (PCM, Pulse Code Modulation, each points is between 1 and -1) to detect peaks.

pcm data PCM Data are dots with value between the max/min amplitude (1/-1). Each dots have its own index

To do this job, we start with a thresold setted to 0.9 (on the amplitude axis) and we search a minimal peak number (~15) by decrementing this thresold by 0.05 through all the AudioBuffer. When we find a peak, we jump 10000 peaks index (1/4 second) to ignore the descendant phase of the peak...

This tool is designed to detect BPM by detecting all peaks for all thresolds, because we work on chunks (AudioBuffer). So we can recompute the BPM with intervals, etc.. without recompute everything with a full AudioBuffer.


This library was been inspired from Tornqvist project which also based on Joe Sullivan's algorithm. Thank you to both of them


npm i realtime-bpm-analyzer

DownloadsWeekly Downloads






Unpacked Size

28.2 kB

Total Files


Last publish


  • avatar