parent
e75a3b82d9
commit
655ea6aeb0
@ -0,0 +1,5 @@
|
|||||||
|
# Mic Measurement
|
||||||
|
|
||||||
|
## Help
|
||||||
|
|
||||||
|
- https://stackoverflow.com/questions/33322681/checking-microphone-volume-in-javascript
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
navigator.mediaDevices.getUserMedia({
|
||||||
|
audio: true,
|
||||||
|
video: true
|
||||||
|
})
|
||||||
|
.then(function(stream) {
|
||||||
|
const audioContext = new AudioContext();
|
||||||
|
const analyser = audioContext.createAnalyser();
|
||||||
|
const microphone = audioContext.createMediaStreamSource(stream);
|
||||||
|
const scriptProcessor = audioContext.createScriptProcessor(2048, 1, 1);
|
||||||
|
|
||||||
|
analyser.smoothingTimeConstant = 0.8;
|
||||||
|
analyser.fftSize = 1024;
|
||||||
|
|
||||||
|
microphone.connect(analyser);
|
||||||
|
analyser.connect(scriptProcessor);
|
||||||
|
scriptProcessor.connect(audioContext.destination);
|
||||||
|
scriptProcessor.onaudioprocess = function() {
|
||||||
|
const array = new Uint8Array(analyser.frequencyBinCount);
|
||||||
|
analyser.getByteFrequencyData(array);
|
||||||
|
const arraySum = array.reduce((a, value) => a + value, 0);
|
||||||
|
const average = arraySum / array.length;
|
||||||
|
console.log(Math.round(average));
|
||||||
|
// colorPids(average);
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
/* handle the error */
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title></title>
|
||||||
|
<script src="app.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in new issue