Search code examples
htmlhtml5-audioweb-audio-api

Using web audio api live input to control stuff


I would like to use my microphone input to control an image i have. I managed to edit this code by far and get my image affected. There was javascriptNode.onaudioprocess = function() and for some reason it disabled my microphone input checking.


Solution

  • You shouldn't need a Javascript node at all. You should just use a requestAnimationFrame handler to do the section of your code that does:

            var array =  new Uint8Array(analyser.frequencyBinCount);
            analyser.getByteFrequencyData(array);
            var average = getAverageVolume(array);
            var array2 =  new Uint8Array(analyser2.frequencyBinCount);
            analyser2.getByteFrequencyData(array2);
            var average2 = getAverageVolume2(array2);
            element.style.opacity = average/100;
            element2.style.opacity = average2/100;