Giter Site home page Giter Site logo

bpm-detective's Introduction

bpm-detective

Detects the BPM of a song or audio sample

This module uses the Web Audio API to try and detect the BPM of a given sound. You can find more on the implementation and how it works by reading the blog post Beat Detection Using JavaScript and the Web Audio API which happens to be where I got most of the code.

Install

$ npm install --save bpm-detective

Usage

The module exports one function. The function takes an AudioBuffer as its only argument. It returns the detected BPM. If the sample was too short or if, for any other reason, the detection failed, the method throws an error.

import detect from 'bpm-detective'

const AudioContext = window.AudioContext || window.webkitAudioContext
const context = new AudioContext()

// Fetch some audio file
fetch('some/audio/file.wav').then(async function (response) {
  // Get response as ArrayBuffer
  const buffer = await response.arrayBuffer()

  // Decode audio into an AudioBuffer
  const data = await new Promise(function (resolve, reject) {
    context.decodeAudioData(buffer, resolve, reject)
  });

  // Run detection
  const bpm = detect(data)
  alert(`Detected BPM: ${bpm}`)
}).catch(console.error)

Disclaimer

The detection presumes you are working with dance(-ish) kind of music and as so looks only in the 90-180 BPM spectrum.

License

MIT

bpm-detective's People

Contributors

tornqvist avatar olessavluk avatar

Watchers

James Cloos 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.