i would like it to be like those music videos with the waves that sync up with the beat but the volume number only is good enough
I tried modifying the 'get volume of microphone' script like this:
const Dsong=document.getElementById('the song'); //the song is jumper by waterflameand an mp3 file if that's neccessary
const stream =Dsong.captureStream();
setTimeout(function(){
const audioContext = new AudioContext();
const mediaStreamAudioSourceNode = audioContext.createMediaStreamSource(stream);
const analyserNode = audioContext.createAnalyser();
mediaStreamAudioSourceNode.connect(analyserNode);
const pcmData = new Float32Array(analyserNode.fftSize);
const onFrame = () => {
analyserNode.getFloatTimeDomainData(pcmData);
let sumSquares = 0.0;
for (const amplitude of pcmData) { sumSquares += amplitude*amplitude; }
let volume = Math.sqrt(sumSquares / pcmData.length);
console.log(volume);
window.requestAnimationFrame(onFrame);
};
window.requestAnimationFrame(onFrame);
},1100); // the audio load first
but it didn't work, only returns 0.
document.getElementById('the song').volume
will not work, only returns 1.