Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do realtime audio analysis with playback in NodeJs?

So here is my problem. I want to play audio from nodejs running on a raspberry Pi and then adjust the brightness of an LED strip also connected to the same PI based on the frequency readings from the audio file. However I can't seem to find anything in node that gives the same functionality as the WebAudio API AnalyserNode.

I found a few libraries (https://www.npmjs.com/package/audio-render) that come close and are based on Web Audio API but the frequency values it produces are completely incorrect. I verified this by comparing it to a browser version I created using the Web Audio API.

I need the audio to play from node while also being analyzed to affect the brightness levels.

Any help would be appreciated. I really thought this would be simpler to handle in node but 6 hours later and I'm still without a solution.

like image 797
shekit Avatar asked Oct 18 '22 03:10

shekit


1 Answers

Victor Dibiya at IBM has an excellent example that illustrates how to use the web-audio-api module to decode an audio file into a buffer array of PCM data from which one can extract amplitude data from sound files and infer beats:

https://github.com/victordibia/beats

I have this working on a Raspberry Pi with LEDs controlled via Fadecandy.

like image 165
nurikabe Avatar answered Oct 20 '22 23:10

nurikabe