Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bpm-detective

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bpm-detective

Detects the BPM of a song or audio sample

  • 2.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22
decreased by-47.62%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 26 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc