-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
99 lines (86 loc) · 2.36 KB
/
index.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mariachi</title>
<style>
body {
background-color: black;
font-family: 'Roboto', sans-serif;
text-align: center;
}
h1 {
color: white;
font-size: 8em;
}
h4 {
color: white;
line-height: 0px;
font-weight: lighter;
}
video {
position: absolute;
left: 25vw;
top: 0px;
opacity: 0;
}
input {
width: 400px;
}
.slidecontainer {
margin-top: 20em;
}
</style>
</head>
<body>
<div>
<h1>Clap</h1>
<video id="video" width="640" height="480">
<source src="mariachi.mp4" type="video/mp4">
Sorry the website doesn't work in your browser
</video>
<div class="slidecontainer">
<h4>threshold :</h4>
<input type="range" min="2" max="100" value="50" id="range">
</div>
</div>
<script>
let video = document.getElementById("video");
let slider = document.getElementById("range");
var threshold = slider.value;
slider.oninput = function() {
threshold = this.value
}
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(event) {
const input = event.inputBuffer.getChannelData(0);
let sum = 0.0;
let instant = 0.0;
let clipcount = 0;
for (let i = 0; i < input.length; ++i) {
sum += input[i] * input[i];
if (Math.abs(input[i]) > 0.99) {
clipcount += 1;
}
}
instant = Math.sqrt(sum / input.length) * 200;
if (instant > threshold && video.paused) {
video.play();
}
if (video.paused) {
video.style.opacity = "0";
} else {
video.style.opacity = "1";
}
};
};
navigator.mediaDevices.getUserMedia({ audio: true, video: false })
.then(handleSuccess);
</script>
</body>
</html>