File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed 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 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
+ } ) ;
34
+
35
+ recognition . addEventListener ( 'end' , recognition . start ) ;
36
+ recognition . start ( ) ;
37
+
15
38
16
39
</ script >
17
40
You can’t perform that action at this time.
0 commit comments