File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212< script >
1313 window . SpeechRecognition = window . SpeechRecognition || window . webkitSpeechRecognition ;
1414
15+ const recognition = new SpeechRecognition ( ) ;
16+ recognition . interimResults = true ;
17+ recognition . lang = 'en-US' ;
18+
19+ let p = document . createElement ( 'p' ) ;
20+ const words = document . querySelector ( '.words' ) ;
21+ words . appendChild ( p ) ;
22+
23+ recognition . addEventListener ( 'result' , e => {
24+ const transcript = Array . from ( e . results )
25+ . map ( result => result [ 0 ] )
26+ . map ( reuslt => result . transcript )
27+ . join ( '' )
28+
29+ p . textContent = transcript ;
30+ if ( e . results [ 0 ] . isFinal ) {
31+ p = document . createElement ( 'p' ) ;
32+ words . appendChild ( p ) ;
33+ }
34+ } )
35+
36+ recognition . addEventListener ( 'end' , recognition . start ) ;
37+
38+ recognition . start ( ) ;
1539
1640</ script >
1741
4064 position : relative;
4165 line-height : 3rem ;
4266 }
43-
67+
4468 p {
4569 margin : 0 0 3rem ;
4670 }
You can’t perform that action at this time.
0 commit comments