File tree Expand file tree Collapse file tree
18 - Adding Up Times with Reduce Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments