Skip to content

Commit 7635e07

Browse files
author
Sergey Gromskiy
committed
1 parent 9eb45d2 commit 7635e07

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

18 - Adding Up Times with Reduce/index-START.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,19 @@
182182
</li>
183183
</ul>
184184
<script>
185+
const vids = Array.from(document.querySelectorAll('[data-time]'));
186+
187+
let seconds = vids.reduce((total, vid) => {
188+
let [min, sec] = vid.dataset.time.split(':');
189+
return total + (+min * 60 + +sec);
190+
}, 0);
191+
192+
let hours = Math.floor(seconds / 3600);
193+
seconds = seconds % 3600;
194+
let mins = Math.floor(seconds / 60);
195+
seconds = seconds % 60;
196+
197+
console.log(`Total time is: ${hours}:${mins}:${seconds}`);
185198
</script>
186199
</body>
187200
</html>

20 - Speech Detection/index-START.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,33 @@
1212
<script>
1313
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
1414

15+
const speach = new SpeechRecognition();
16+
speach.interimResults = true;
17+
speach.lang = 'en-US';
1518

19+
let p = document.createElement('p');
20+
const words = document.querySelector('.words');
21+
words.appendChild(p);
22+
23+
speach.addEventListener('result', e => {
24+
const transcript = [... e.results]
25+
.map(result => result[0])
26+
.map(result => result.transcript)
27+
.join();
28+
console.log(transcript);
29+
p.textContent = transcript;
30+
31+
if(e.results[0].isFinal) {
32+
p = document.createElement('p');
33+
words.appendChild(p);
34+
}
35+
});
36+
37+
function putAndRestart(){
38+
speach.start();
39+
}
40+
speach.addEventListener('end', putAndRestart)
41+
speach.start();
1642
</script>
1743

1844

0 commit comments

Comments
 (0)