-
Notifications
You must be signed in to change notification settings - Fork 0
/
a.html
27 lines (27 loc) · 862 Bytes
/
a.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html>
<head>
<script>
const handleSuccess = function(stream) {
const context = new AudioContext();
const source = context.createMediaStreamSource(stream);
const processor = context.createScriptProcessor(1024, 1, 1);
source.connect(processor);
processor.connect(context.destination);
processor.onaudioprocess = function(e) {
// Do something with the data, e.g. convert it to WAV
// console.log(e.inputBuffer);
var x = e.inputBuffer.getChannelData(0);
var j = 0
for (let i = 1; i < x.length; i++) {
if (x[i-1] * x[i] < 0) j++;
}
document.getElementById('out').innerHTML = String(j/(x.length-1)*e.inputBuffer.sampleRate/2);
};
};
navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then(handleSuccess);
</script>
</head>
<body>
<div id="out"></div>
</body>
</html>