File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
18 - Adding Up Times with Reduce Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 182
182
</ li >
183
183
</ ul >
184
184
< 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 } ` ) ;
185
198
</ script >
186
199
</ body >
187
200
</ html >
Original file line number Diff line number Diff line change 12
12
< script >
13
13
window . SpeechRecognition = window . SpeechRecognition || window . webkitSpeechRecognition ;
14
14
15
+ const speach = new SpeechRecognition ( ) ;
16
+ speach . interimResults = true ;
17
+ speach . lang = 'en-US' ;
15
18
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 ( ) ;
16
42
</ script >
17
43
18
44
You can’t perform that action at this time.
0 commit comments