npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

music-beat-detector

v0.1.1

Published

**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.

Downloads

15

Readme

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')
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 then YouTube videos.

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