Reputation: 361
I'm trying to get the frequency data of an audio file without having to play through the entire actual audio file. Right now I'm doing the following:
var audio = new Audio();
audio.src = 'testAudio.mp3';
audio.controls = true;
audio.autoplay = true;
document.body.appendChild(audio);
var context = new AudioContext();
var analyser = context.createAnalyser();
var source = context.createMediaElementSource(audio);
source.connect(analyser);
analyser.connect(context.destination);
var frequencyData = new Uint8Array(analyser.frequencyBinCount);
function renderFrame() {
requestAnimationFrame(renderFrame);
analyser.getByteFrequencyData(frequencyData);
}
renderFrame();
This works fine, but I need to wait for the entire audio file to play. Is there a way I can get this data immediately?
Upvotes: 1
Views: 2402