File tree Expand file tree Collapse file tree 2 files changed +4039
-0
lines changed Expand file tree Collapse file tree 2 files changed +4039
-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+
28+ p . textContent = transcript ;
29+ if ( e . results [ 0 ] . isFinal ) {
30+ p = document . createElement ( 'p' ) ;
31+ words . appendChild ( p ) ;
32+ }
33+ if ( transcript . includes ( 'computer' ) ) {
34+ console . log ( 'Are you talking to me?' ) ;
35+ }
36+ } ) ;
37+
38+ recognition . addEventListener ( 'end' , recognition . start ) ;
39+
40+ recognition . start ( ) ;
1541
1642</ script >
1743
You can’t perform that action at this time.
0 commit comments