I am not a programmer, I'm just trying to make a project for my work. I tried to learn some Javascript 10 years ago, but I haven't been working with programming since that time. The question is simple for real programmers.
I've found some code that shows the level of audio from microphone input. What do I need to do:
Thank you.
navigator.mediaDevices.getUserMedia({ audio: true }).then(function(stream) {
audioContext = new AudioContext();
analyser = audioContext.createAnalyser();
microphone = audioContext.createMediaStreamSource(stream);
javascriptNode = audioContext.createScriptProcessor(2048, 1, 1);
analyser.smoothingTimeConstant = 0.8;
analyser.fftSize = 1024;
microphone.connect(analyser);
analyser.connect(javascriptNode);
javascriptNode.connect(audioContext.destination);
javascriptNode.onaudioprocess = function() {
var array = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(array);
var values = 0;
var length = array.length;
for (var i = 0; i < length; i++) {
values += (array[i]);
}
var average = values / length;
if(Math.round(average)>15)
{
console.log(Math.round(average));
document.getElementById("lvl").innerHTML = Math.round(average)-10;
}
}
})
.catch(function(err) {
/* handle the error */
});