Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tornqvist/bpm-detective
Detects the BPM of a song or audio sample
https://github.com/tornqvist/bpm-detective
bpm javascript music
Last synced: 25 days ago
JSON representation
Detects the BPM of a song or audio sample
- Host: GitHub
- URL: https://github.com/tornqvist/bpm-detective
- Owner: tornqvist
- Created: 2015-08-29T18:27:32.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-07-26T10:50:41.000Z (over 3 years ago)
- Last Synced: 2024-11-06T10:02:24.112Z (about 1 month ago)
- Topics: bpm, javascript, music
- Language: JavaScript
- Size: 13.7 MB
- Stars: 137
- Watchers: 4
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-webaudio - bpm-detective
README
# bpm-detective
> Detects the BPM of a song or audio sample
This module uses the [Web Audio API](https://developer.mozilla.org/en-US/docs/Web/API/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](http://joesul.li/van/beat-detection-using-web-audio/) which happens to be where I got most of the code.
## Install
```bash
$ npm install --save bpm-detective
```## Usage
The module exports one function. The function takes an [AudioBuffer](https://developer.mozilla.org/en-US/docs/Web/API/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*.
```javascript
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