-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
120 lines (98 loc) · 3.4 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Flabber</title>
<link rel="manifest" href="/manifest.json">
<style>
body {
transform: scaleX(-1)
}
.rect {
position: absolute;
border-radius: 40%;
animation: blink 2s ease-out;
box-shadow: inset 0 0 50px white;
}
@keyframes blink {
from {
transform: scale(0.8);
opacity: 0.2;
}
to {
transform: scale(1.7);
opacity: 0;
}
}
</style>
</head>
<body>
<video id="video" muted></video>
<canvas style="display: none;" id="c1" width="427" height="240"></canvas>
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io();
const utter = new SpeechSynthesisUtterance('');
const colors = ['blue', 'green', 'red', 'pink'];
// Prefer camera resolution nearest to 1280x720.
const constraints = {audio: true, video: {width: 1280, height: 720}};
const video = document.getElementById('video');
const canvas = document.getElementById('c1');
const ctx = canvas.getContext('2d');
const computeFrame = () => {
ctx.drawImage(video, 0, 0, 427, 240);
return canvas.toDataURL('image/jpeg', 0.7);
};
const videoToCanvas = mediaStream => {
video.srcObject = mediaStream;
video.onloadedmetadata = () => {
video.play();
socket.emit('ready');
let first = true;
socket.on('rect', (data) => {
data.forEach((rect, i) => {
if (first) {
first = false;
utter.onend = () => {
const recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.lang = 'ru-RU';
recognition.interimResults = true;
recognition.onresult = function(event) {
interim_transcript += event.results[0][0].transcript;
};
recognition.start();
recognition.onerror = () => {
//setTimeout(recognition.start, 500);
};
};
speechSynthesis.speak(utter);
}
const div = document.createElement('div');
div.classList.add('rect');
document.body.appendChild(div);
div.addEventListener('animationend', () => {
div.remove();
});
div.style.top = rect.y * 3 + 'px';
div.style.left = rect.x * 3 + 'px';
div.style.width = rect.width * 3 + 'px';
div.style.height = rect.height * 3 + 'px';
div.style.borderColor = colors[i];
});
});
};
document.body.addEventListener('click', document.body.requestFullscreen);
};
navigator.mediaDevices
.getUserMedia(constraints)
.then(videoToCanvas);
socket.on('getScreenshot', () => {
socket.emit('screenshot', computeFrame());
});
</script>
</body>
</html>