Code Monkey home page Code Monkey logo

web-audio-beat-detector's Introduction

logo

web-audio-beat-detector

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

tests dependencies 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 is a very easy algorithm which retrieves the beats as BPM of a given AudioBuffer.

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 }) => {
        // the bpm and offset could be guessed
    })
    .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 basically the same as described in the documentation of the AudioBufferSourceNode.start() method.

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.

web-audio-beat-detector's People

Contributors

chrisguttandin avatar greenkeeper[bot] avatar greenkeeperio-bot avatar kant avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.