-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
227 lines (115 loc) · 5.84 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Browser speech recognition</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body style = "
">
<link rel="shortcut icon" type="image/png" href="./logo.png"/>
<img src = "name_logo.PNG" width = "800" height = "200" >
<ul id="nav" style ="
gap:2vh;
display: grid;
grid-template-columns: repeat(7, auto);
">
<li><a href="practice.html">Practice</a></li>
<li><a href="compete.html">Competition</a></li>
<li><a href="curriculum.html">Curriculum</a></li>
<li><a href="about.html">About</a></li>
<li><a href="https://youtu.be/HiKbo7iNdEo">DemoTutorial Video</a></li>
<li><a href="https://www.youtube.com/watch?v=eC63tOA4cUU">Benefits of Alienmaths</a></li>
</ul>
<main>
<h1>Solve Math Problems Verbally!</h1>
Press on the button and allow access to your microphone to start transcribing math! <br><br>
<button id="button">Press to Start</button>
<p id="message" hidden aria-hidden="true">
Your browser doesn't support Speech Recognition. We recommend Chrome for Desktop or Android and Safari for Apple devices.
</p>
<div id="math"></div>
<div id="interface"></div>
<div id="result" hidden></div>
</main>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script"
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>
<input type="text">
<script src="isNumber.js" type="text/javascript"></script>
<script src="resultToMath.js" type="text/javascript"></script>
<script>
window.addEventListener("DOMContentLoaded", () => {
const button = document.getElementById("button");
const math = document.getElementById("math");
const result = document.getElementById("result");
const main = document.getElementsByTagName("main")[0];
let listening = false;
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
if (typeof SpeechRecognition !== "undefined") {
const recognition = new SpeechRecognition();
const stop = () => {
main.classList.remove("speaking");
recognition.stop();
button.textContent = "Press to Start";
};
const start = () => {
main.classList.add("speaking");
recognition.start();
button.textContent = "Say some math!";
};
const onResult = event => {
math.innerHTML = "";
result.innerHTML = "";
for (const res of event.results) {
const text = document.createTextNode(res[0].transcript);
console.log(res[0].transcript);
const p = document.createElement("p");
if (res.isFinal) {
p.classList.add("final");
}
p.appendChild(text);
result.appendChild(p);
}
// turns speech to math
resultToMath (document.getElementById("result").textContent, "math");
};
recognition.continuous = true;
recognition.interimResults = true;
recognition.addEventListener("math", onResult);
recognition.addEventListener("result", onResult);
button.addEventListener("click", event => {
listening ? stop() : start();
listening = !listening;
});
}
else {
button.remove();
const message = document.getElementById("message");
message.removeAttribute("hidden");
message.setAttribute("aria-hidden", "false");
var text = document.querySelector("input");
text.addEventListener("input", function() {
// turns contents to math
resultToMath(text.value, "math");
});
}
});
function startGame() {
myGameArea.start();
}
var myGameArea = {
canvas : document.createElement("canvas"),
start : function() {
this.canvas.width = 480;
this.canvas.height = 270;
this.context = this.canvas.getContext("2d");
document.body.insertBefore(this.canvas, document.body.childNodes[0]);
}
}
</script>
</body>
</html>