• Stars
    star
    254
  • Rank 160,264 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

music-beat-detector is a library that analyzes a music stream and detects any beat. It can be used to control lights or any magic effect by the music wave.

music-beat-detector

music-beat-detector is a library that analyzes a music stream and detects any beat. It can be used to control lights or any magic effect by the music wave.

npm Downloads Donate

Bundled with this library there are three components:

  • MusicBeatDetector is able to analyze any PCM 16bit Little Endian audio stream. It detects music peaks and realtime bpm.
  • MusicBeatScheduler is able to sync any detected peak with the listened audio. It's useful to control some lights or any other effect.
  • MusicGraph generates an SVG graph that displays every detected peak. It's useful to tune the peak detection.

music-beat-detector

Example

const fs = require('fs')
const Speaker = require('speaker')
const createMusicStream = require('create-music-stream') //read this https://github.com/chrvadala/create-music-stream#faq
const {MusicBeatDetector, MusicBeatScheduler, MusicGraph} = require('music-beat-detector')

const musicSource = process.argv[2] //get the first argument on cli

const musicGraph = new MusicGraph()

const musicBeatScheduler = new MusicBeatScheduler(pos => {
  console.log(`peak at ${pos}ms`) // your music effect goes here
})

const musicBeatDetector = new MusicBeatDetector({
  plotter: musicGraph.getPlotter(),
  scheduler: musicBeatScheduler.getScheduler(),
})

createMusicStream(musicSource)
  .pipe(musicBeatDetector.getAnalyzer())
  .on('peak-detected', (pos, bpm) => console.log(`peak-detected at ${pos}ms, detected bpm ${bpm}`))
  .on('end', () => {
    fs.writeFileSync('graph.svg', musicGraph.getSVG())
    console.log('end')
  })

  .pipe(new Speaker())
  .on('open', () => musicBeatScheduler.start())

Usage

You can play any music sound supported by the library create-music-stream. Note: The beat detection performs better on mp3 files than YouTube video.

node example.js ./track.mp3
node example.js https://www.youtube.com/watch?v=qeMFqkcPYcg
node example.js https://www.youtube.com/watch?v=Zi_XLOBDo_Y
node example.js https://www.youtube.com/watch?v=n_GFN3a0yj0
node example.js https://www.youtube.com/watch?v=59Q_lhgGANc

Reference

new MusicBeatDetector(options)

Param Default Description
options.sensitivity 0.6 Response to the music wave (value from 0.5 to 1)
options.plotter - Instance of MusicGraph
options.scheduler - Instance of MusicBeatScheduler
options.minThreashold 1638 Peaks under this level are ignored (usually they're noise)
options.debugFilter false Stream the filtered music throught the lowpass filter (for debug purpose)
  • getAnalyzer() - Returns a transformer stream that analyze the music

new MusicBeatScheduler(effectCallback)

  • getScheduler() - returns an instance used by MusicBeatDetector
  • start() - start effects (usually controlled by speaker events)

new MusicGraph(secondWidth, secondHeight)

  • getPlotter() - returns an instance used by MusicBeatDetector
  • getSVG() - returns a string with the SVG that displays the analyzed music

Contributors

More Repositories

1

react-svg-pan-zoom

👀 A React component that adds pan and zoom features to SVG
JavaScript
677
star
2

transformation-matrix

Javascript isomorphic 2D affine transformations written in ES6 syntax. Manipulate transformation matrices with this totally tested library!
JavaScript
360
star
3

node-ble

Bluetooth Low Energy (BLE) library written with pure Node.js (no bindings) - baked by Bluez via DBus
JavaScript
308
star
4

awesome-protocols

Curated list of awesome technology protocols with a reference to official RFCs
28
star
5

create-music-stream

Creates a PCM 16 bit Little Endian Stream from a mp3 file or youtube video
JavaScript
24
star
6

potree-converter-docker

Potree Converter utility packed as Docker Container
Dockerfile
19
star
7

react-refactor

🔧 Convert your React Class Component to Functional Component and vice-versa
JavaScript
16
star
8

neopixel

Node.js library to control Adafruit NeoPixel based on ws2812 led family
C++
15
star
9

docker-compose-examples

💻 This project intends to collect common docker-compose use cases. Each example can be used as a boilerplate.
PHP
13
star
10

kafka-test-helper

Utility library that simplify testing of Node.js components that interacts with Kafka broker.
JavaScript
8
star
11

weather-station

Connector able to download weather data from an Oregon Scientific EMR211X station, leveraging on Bluetooth Low Energy connection
JavaScript
6
star
12

mqtt-dispatcher

MQTT dispatcher is a library that extends MQTT.js and allows to route incoming messages on a specific handler, according to defined routing rules.
JavaScript
6
star
13

biconnected-components

Find biconnected component in a graph using algorithm by John Hopcroft and Robert Tarjan
JavaScript
3
star
14

aggregate-fn

Aggregate fn is a tiny Javascript utility that groups together multiple async operations.
JavaScript
3
star
15

const-version

✨ A tiny command line tool that extract `package.json` version and generate `export const VERSION='...'` file. Useful when you want to package your software version.
JavaScript
3
star
16

tableauSolver

Prolog algorithm that applies the method of analytic tableaux and creates a graphical representation of a propositional tableau
Prolog
2
star
17

github-actions

Github actions that automates some common scenarios.
2
star
18

react-redux-boilerplate

😋 A suggested React + Redux projects structure.
JavaScript
2
star
19

aws-cloud-stacks

AWS CloudFormation stacks that speed-up projects development.
Shell
2
star
20

cisco-decrypt-docker

🙈 Docker container with Decoder for password encoding of Cisco VPN client
C
2
star
21

chrvadala.github.io

Hello, this is Christian Vadalà's website. Here you can find a list of open source projects, backed by React, Node.JS and AWS technologies.
JavaScript
1
star
22

react-stylerify

A browserify wrapper around react-styling
JavaScript
1
star
23

sudoku.go

🎲 Sudoku solver written in golang
Go
1
star
24

sliding-window-max

Given a stream of data, this algorithm returns (for every added value) the current max value.
JavaScript
1
star
25

setup-my-pc

setup-my-pc.sh is a simple script that configures personal computers, virtual machines and servers with some common tools. It fastify the setup of a new development environment.
Shell
1
star