I have a beeping signal and I am trying to get that translated to 0 and 1. And it works, but then it comes to really fast beeping it can't found out the 0 (no bip).
Here is a sample of the signal ( Lower your volume before testing it!! ): https://www.dropbox.com/s/fqxxirg9y8gc4t2/test_sound.m4a?dl=0
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({
audio: true
},
function(stream) {
audioContext = new AudioContext();
analyser = audioContext.createAnalyser();
microphone = audioContext.createMediaStreamSource(stream);
javascriptNode = audioContext.createScriptProcessor(2048, 1, 1);
analyser.smoothingTimeConstant = 0;
analyser.fftSize = 256;
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]);
}
onOff = (values / length) > 30 ? 1 : 0; // <----------- Here
console.log(onOff);
}
},
function(err) {});
}