Skip to content

Commit a0615b2

Browse files
squishykidgav0
authored andcommitted
Platform Abstraction (#87)
* Yee haw * unrap.exe * added manifest * added script, extension works for file:// domain * committed the wrong file pls ignore * takes and displays webcam input * uses the button already there instead of injecting it's own * Hey wiretap, what's the weather like tomorrow? * not sure if i've done anything but committing anyway * wew * bing bing * Update web/static/js/scriptdotjayess.js I'm all up in your repo now * Update web/static/js/scriptdotjayess.js less spaghet * wew * Update web/static/js/pa.js +wiretap +spycam -spaghet * wow! spaghet * wew * Update web/static/js/pa.js we out here * wew * Update web/static/js/pa.js properly handles no input * meme * Revert TRASH "Update web/static/js/pa.js" This reverts commit 4551e44. # Conflicts: # web/static/js/pa.js * run_the_code.zip * chown bingo:bongo CODEOWNERS * Update web/static/js/pa.js hidden easter egg dataURL * Update web/static/js/pa.js less console more callback * wew * delet this * wew
1 parent 408eeab commit a0615b2

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* @flamily/code-monkeys @flamily/qa
2+
/web/static/js/pa.js @gav0 @squishykid @palarax

web/static/js/pa.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
var irs = (function() {
2+
function js_speak(phrase) {
3+
var msg = new SpeechSynthesisUtterance(phrase);
4+
window.speechSynthesis.speak(msg);
5+
}
6+
function chrome() {
7+
/* do some magical checking that chrome is available */
8+
if (typeof (window.SpeechRecognition || window.webkitSpeechRecognition) === "undefined") {
9+
return null;
10+
}
11+
12+
//Voice Recognition
13+
function listen(words, timeout, callback) {
14+
var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
15+
var recognition = new SpeechRecognition();
16+
17+
recognition.continuous = true;
18+
recognition.onresult = function(event) {
19+
txt = event.results[event.resultIndex][0].transcript;
20+
console.log(txt);
21+
recognised = txt.split(" ");
22+
for (word in recognised){
23+
x = words.indexOf(recognised[word]);
24+
if (x!=-1){
25+
if (callback){
26+
callback(words.indexOf(recognised[word]));
27+
}
28+
callback = null;
29+
}
30+
}
31+
if (x == -1){
32+
if (callback){callback(x);}
33+
callback = null;
34+
}
35+
recognition.stop();
36+
}
37+
38+
recognition.start();
39+
setTimeout(function () {
40+
recognition.stop();
41+
if (callback){
42+
callback(-1);
43+
callback = null;
44+
}
45+
}, timeout);
46+
}
47+
48+
//Image Capture Code
49+
function gotMedia(mediaStream) {
50+
mediaStreamTrack = mediaStream.getVideoTracks()[0];
51+
imageCapture = new ImageCapture(mediaStreamTrack);
52+
console.log(imageCapture);
53+
}
54+
55+
function drawCanvas(canvas, img) {
56+
canvas.width = getComputedStyle(canvas).width.split('px')[0];
57+
canvas.height = getComputedStyle(canvas).height.split('px')[0];
58+
let ratio = Math.min(canvas.width / img.width, canvas.height / img.height);
59+
let x = (canvas.width - img.width * ratio) / 2;
60+
let y = (canvas.height - img.height * ratio) / 2;
61+
canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
62+
canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height,
63+
x, y, img.width * ratio, img.height * ratio);
64+
}
65+
66+
67+
68+
function takePhoto(callback){
69+
console.log("Say cheese")
70+
71+
var htmlCanvas = document.createElement("canvas");
72+
htmlCanvas.width = 1280;
73+
htmlCanvas.height = 720;
74+
htmlCanvas.style.visibility = "hidden";
75+
document.body.appendChild(htmlCanvas);
76+
imageCapture.grabFrame()
77+
.then(imageBitmap => {
78+
drawCanvas(htmlCanvas, imageBitmap);
79+
callback(htmlCanvas.toDataURL())
80+
})
81+
.catch(error => console.log(error));
82+
}
83+
84+
navigator.mediaDevices.getUserMedia({video: true})
85+
.then(gotMedia)
86+
.catch(error => console.error('getUserMedia() error:', error));
87+
88+
return {
89+
photo: takePhoto,
90+
listen: listen,
91+
say: js_speak,
92+
identify: function() {
93+
return 2;
94+
}
95+
}
96+
}
97+
98+
function robot() {
99+
//check if we are running on the robot
100+
if(typeof irs_raw === "undefined") {
101+
return null;
102+
}
103+
/* setup the robot callback handlers */
104+
irs_raw.phraseSuccess = function(res) {
105+
console.log(res);
106+
}
107+
108+
/* make the irs thingo */
109+
return {
110+
identify: function() {return 1}
111+
}
112+
}
113+
114+
function basic() {
115+
return {
116+
identify: function() {
117+
return 0;
118+
},
119+
say: js_speak,
120+
listen: function(_, _, cb) {
121+
console.error('irs.listen is not available on this platform. use chrome');
122+
cb(-3);
123+
},
124+
photo: function(cb) {
125+
console.error('irs.photo is not available on this platform. use chrome');
126+
cb(null);
127+
}
128+
}
129+
}
130+
return robot() || chrome() || basic();
131+
})()

web/templates/footer.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<!-- Bootstrap core JavaScript-->
2+
<script src="{{ url_for('static', filename='js/pa.js') }}"></script>
23
<script src="{{ url_for('static', filename='vendor/jquery/jquery.min.js') }}"></script>
34
<script src="{{ url_for('static', filename='vendor/bootstrap/js/bootstrap.bundle.min.js') }}"></script>
45

0 commit comments

Comments
 (0)