-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptdotjayess.js
72 lines (52 loc) · 1.97 KB
/
scriptdotjayess.js
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
console.log("Hey kids");
var htmlCanvas = document.createElement("canvas");
htmlCanvas.width = 1280;
htmlCanvas.height = 720;
document.body.appendChild(htmlCanvas);
document.getElementsByTagName('input')[0].onclick = takePic;
document.getElementsByTagName('input')[1].onclick = listenForTen;
var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
var recognition = new SpeechRecognition();
recognition.continuous = true;
function gotMedia(mediaStream) {
mediaStreamTrack = mediaStream.getVideoTracks()[0];
imageCapture = new ImageCapture(mediaStreamTrack);
console.log(imageCapture);
}
navigator.mediaDevices.getUserMedia({video: true})
.then(gotMedia)
.catch(error => console.error('getUserMedia() error:', error));
function drawCanvas(canvas, img) {
canvas.width = getComputedStyle(canvas).width.split('px')[0];
canvas.height = getComputedStyle(canvas).height.split('px')[0];
let ratio = Math.min(canvas.width / img.width, canvas.height / img.height);
let x = (canvas.width - img.width * ratio) / 2;
let y = (canvas.height - img.height * ratio) / 2;
canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height,
x, y, img.width * ratio, img.height * ratio);
}
function takePic(){
imageCapture.grabFrame()
.then(imageBitmap => {
drawCanvas(htmlCanvas, imageBitmap);
})
.catch(error => ChromeSamples.log(error));
}
console.log("I'm a computer");
function listenForTen(){
recognition.start();
setTimeout(function () {recognition.stop();console.log("lalalala I can't hear you")}, 10000);
}
recognition.onresult = function(event) {
txt = event.results[event.resultIndex][0].transcript
console.log(txt);
commandlist = ["confirm", "deny", "yes", "no", "maybe"];
recognised = txt.split(" ")
for (word in recognised){
x = commandlist.indexOf(recognised[word]);
if (x!=-1){
console.log(commandlist.indexOf(recognised[word]));
}
}
}