I am learning/playing with Web Audio API and it is awesome. I have some code, that analyses FFT of audio stream and do some calculations in realtime. It runs in browser.
But now I need to do the same thing, but process the whole audiofile and get array of data, instead playing it and analyze in realtime, and best case do it in Phantomjs. If it is not possible, browser is ok also..
Sample code:
var audioElement = document.getElementById("player");
var audioContext = new AudioContext();
var source = audioContext.createMediaElementSource(audioElement);
analyserNode = audioContext.createAnalyser();
analyserNode.fftSize = 2048;
source.connect(analyserNode);
source.connect(audioContext.destination);
analyserNode.connect(audioContext.destination);
and looping function:
var freqByteData = new Uint8Array(analyserNode.frequencyBinCount);
analyserNode.getByteFrequencyData(freqByteData);
//do processing FFT data
Now I need load an mp3 file, and process a looping function to it to get some array of result data. So not wait while it play, but process it immediately.
The problem is, I never tried phantomjs. I need exact results as browser does, also I am using analyserNode.smoothingTimeConstant in my calculations. The requirement is get data 30 times per second.
If it is possible, how to rewrite this code and run it like ./phantomapp file.mp3 which saves data to some txt file or stdout?
If it is not possible with phantomjs, how to adopt this code to run in browser?
Thanks