I'm quite new to the question but I try something like this.
I know Audio api is powerfull but I'm not understand much, so I came with :
let asClap = false;
let tampon = 60;
navigator.mediaDevices.getUserMedia({
"audio": {
"mandatory": {
"googEchoCancellation": "false",
"googAutoGainControl": "false",
"googNoiseSuppression": "false",
"googHighpassFilter": "false"
},
"optional": []
},
}).then(function(stream) {
const audioContext = new AudioContext();
/* use the stream */
let gain_node = audioContext.createGain();
gain_node.connect( audioContext.destination );
let microphone_stream = audioContext.createMediaStreamSource(stream);
let analyser = audioContext.createAnalyser()
microphone_stream.connect(analyser)
analyser.fftSize = 256;
isClaping(analyser)
}).catch(function(err) {
console.log(err)
});
function isClaping(analyser){
const bufferLength = analyser.frequencyBinCount;
var data = new Uint8Array(bufferLength);
analyser.getByteFrequencyData(data);
const arraySum = data.reduce((a, value) => a + value);
if(arraySum >= 3000){
if(!asClap){
asClap = true;
clap()
}
}
requestAnimationFrame(()=>{isClaping(analyser)});
tampon--
if(tampon === 0){
tampon = 60
asClap = false
}
}
I really need to do it in Javascript, since I'm more familliar with Is that correct and how can i detect double clap ?