File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed 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+
18+ let p = document . createElement ( 'p' ) ;
19+ const words = document . querySelector ( '.words' ) ;
20+ words . appendChild ( p ) ;
21+
22+ recognition . addEventListener ( 'result' , e => {
23+ const transcript = Array . from ( e . results )
24+ . map ( result => result [ 0 ] )
25+ . map ( result => result . transcript )
26+ . join ( '' ) ;
27+ p . textContent = transcript ;
28+ if ( e . results [ 0 ] . isFinal ) {
29+ p = document . createElement ( 'p' ) ;
30+ words . appendChild ( p ) ;
31+ }
32+ } ) ;
33+
34+ recognition . addEventListener ( 'end' , recognition . start ) ;
35+ recognition . start ( ) ;
36+
1537
1638</ script >
1739
You can’t perform that action at this time.
0 commit comments