Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
realtime-bpm-analyzer
Advanced tools
This dependency free library can analyze the BPM (Tempo) of an audio/video node or any stream in realtime on your browser
Welcome to Realtime BPM Analyzer, a powerful and easy-to-use TypeScript/JavaScript library for detecting the beats-per-minute (BPM) of an audio or video source in real-time.
To install this module to your project, just launch the command below:
npm install realtime-bpm-analyzer
To learn more about how to use the library, you can check out the documentation.
If you encounter issues along the way, remember I have a chat and the new discussion feature of github !
Measure or detect the BPM from a web player.
This example shows how to deal with a simple audio
node.
<audio src="./new_order-blue_monday.mp3" id="track"></audio>
createRealTimeBpmProcessor
, create and pipe the filters to the AudioWorkletNode (realtimeAnalyzerNode
).import { createRealTimeBpmProcessor, getBiquadFilter } from 'realtime-bpm-analyzer';
const realtimeAnalyzerNode = await createRealTimeBpmProcessor(audioContext);
// Set the source with the HTML Audio Node
const track = document.getElementById('track');
const source = audioContext.createMediaElementSource(track);
const lowpass = getBiquadFilter(audioContext);
// Connect nodes together
source.connect(lowpass).connect(realtimeAnalyzerNode);
source.connect(audioContext.destination);
realtimeAnalyzerNode.port.onmessage = (event) => {
if (event.data.message === 'BPM') {
console.log('BPM', event.data.data.bpm);
}
if (event.data.message === 'BPM_STABLE') {
console.log('BPM_STABLE', event.data.data.bpm);
}
};
Analyze the BPM of a source continuously. This feature is quite simple and basically get rid of all data inside the analyzer after the stabilizationTime is reached. Why ? Because we store all the "valid peaks" for each thresholds in order to find the best candidates. And we would keep all those data forever, we would have memory leaks.
Note: This approach is NOT recommended if you are using a microphone as source. Except if the microphone gets correct audio source. Typically, if the BPM is never computed using this approach, you probably capture low intensity audio with your microphone (too far from the source, too much noise, directional microphone could be reasons why it's not working).
<audio src="https://ssl1.viastreaming.net:7005/;listen.mp3" id="track"></audio>
Thank you IbizaSonica for the stream.
continuousAnalysis
flag to periodically delete collected data.import { createRealTimeBpmProcessor, getBiquadFilter } from 'realtime-bpm-analyzer';
const realtimeAnalyzerNode = await createRealTimeBpmProcessor(audioContext, {
continuousAnalysis: true,
stabilizationTime: 20_000, // Default value is 20_000ms after what the library will automatically delete all collected data and restart analyzing BPM
});
// Set the source with the HTML Audio Node
const track = document.getElementById('track');
const source = audioContext.createMediaElementSource(track);
const lowpass = getBiquadFilter(audioContext);
// Connect nodes together
source.connect(lowpass).connect(realtimeAnalyzerNode);
source.connect(audioContext.destination);
realtimeAnalyzerNode.port.onmessage = (event) => {
if (event.data.message === 'BPM') {
console.log('BPM', event.data.data.bpm);
}
if (event.data.message === 'BPM_STABLE') {
console.log('BPM_STABLE', event.data.data.bpm);
}
};
Analyze the BPM from files located on your desktop, tablet or mobile!
import * as realtimeBpm from 'realtime-bpm-analyzer';
input[type=file]
to get the files you want.<input type="file" accept="wav,mp3,flac" onChange={event => this.onFileChange(event)}/>
change
event like so, and analyze the BPM of the selected files. You don't need to be connected to the Internet for this to work.function onFileChange(event) {
const audioContext = new AudioContext();
// Get the first file from the list
const file = event.target.files[0];
const reader = new FileReader();
reader.addEventListener('load', () => {
// The file is uploaded, now we decode it
audioContext.decodeAudioData(reader.result, audioBuffer => {
// The result is passed to the analyzer
realtimeBpm.analyzeFullBuffer(audioBuffer).then(topCandidates => {
// Do something with the BPM
console.log('topCandidates', topCandidates);
});
});
});
reader.readAsArrayBuffer(file);
};
Realtime BPM Analyzer is using Web Test Runner to handle Unit tests and Web Dev Server to handle Dataset testing.
You will first need to install the project following these commands:
npm install
npm run prepare
To run the unit tests, you just have to run npm test
.
To test a whole dataset of audio files you have to drop those files into testing/datasets
and then run: npm run testing:prepare
to create a manifest that contains the file name and the BPM (typically the verified one) from the metadata.
{
"my music file.mp3": 130
}
You also need to build the library with npm run build
.
Once those steps are done you can run npm run testing
to challenge the library against your dataset. The Local/Offline strategy is used here.
If you're developing a new feature and you want to test it in another project, you can run bin/build/to-project.sh nameOfTheProject
. This command will create package with npm pack
and copy it into the target project nameOfTheProject
sitting next to this one. You will then be able to test a production-like package.
TypeDoc is used to build the technical documentation of Realtime BPM Analyzer. To build the documentation run: npm run build:docs
;
This library is distributed under the terms of the Apache License, Version 2.0. However, if you are interested in using this library in a commercial context or require a commercial license, please feel free to contact me.
For inquiries regarding commercial usage, licensing options, or any other questions, please contact me:
David Lepaux
d.lepaux@gmail.com
I am open to discussing custom licensing arrangements to meet your specific needs and ensure that you can use this library in your commercial projects with confidence.
Let me know what your most wanted feature is by opening an issue.
This library was inspired by the Tornqvist project, which was also based on Joe Sullivan's algorithm. Thank you to both of them.
FAQs
This dependency free library can analyze the BPM (Tempo) of an audio/video node or any stream in realtime on your browser
We found that realtime-bpm-analyzer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.