npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

web-audio-beat-detector

v8.2.19

Published

A beat detection utility which is using the Web Audio API.

Downloads

2,557

Readme

logo

web-audio-beat-detector

A beat detection utility which is using the Web Audio API.

version

This module is based on the technique explained by Joe Sullivan in his article Beat Detection Using JavaScript and the Web Audio API. It retrieves the beats as BPM of a given AudioBuffer. The algorithm used is not as complex (and expensive to compute) as many others. But it yields surprisingly good results especially for electronic music.

Usage

The web-audio-beat-detector module is available on npm and can be installed as usual.

npm install web-audio-beat-detector

You can then import its public function analyze() like this:

import { analyze } from 'web-audio-beat-detector';

The analyze() function expects an AudioBuffer as its first parameter and it returns a Promise which eventually resolves with the tempo of that buffer as a number. An example usage might look like this:

analyze(audioBuffer)
    .then((tempo) => {
        // the tempo could be analyzed
    })
    .catch((err) => {
        // something went wrong
    });

Additionally you can also import the guess() function like this:

import { guess } from 'web-audio-beat-detector';

The guess() function expects an AudioBuffer as well and also returns a Promise. The Promise will resolve with an object containing the estimated BPM (the rounded tempo) and the offset of the first beat in seconds.

guess(audioBuffer)
    .then(({ bpm, offset, tempo }) => {
        // the bpm and offset could be guessed
        // the tempo is the same as the one returned by analyze()
    })
    .catch((err) => {
        // something went wrong
    });

analyze() and guess() do both support offset and duration as optional arguments. When specified these two values are used to select only a part of the given AudioBuffer. There usage is the same as described in the documentation of the AudioBufferSourceNode.start() method.

By default the bpm are expected to be between 90 and 180 bpm. This can be changed by specifying the tempoSettings. These can be passed as the last argument to analyze() or guess().

// with an offset and duration
analyze(audioBuffer, 1, 10, { maxTempo: 120, minTempo: 60 });
// with no other arguments
analyze(audioBuffer, { maxTempo: 120, minTempo: 60 });

Acknowledgement

A more comprehensive implementation has been done by José M. Pérez. It comes with an UI to search for tracks on Spotify which can then be analyzed. He also wrote a blog post (Detecting tempo of a song using browser's Audio API) about it.