File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 6
6
</ head >
7
7
< body >
8
8
9
+
9
10
< div class ="words " contenteditable >
10
11
</ div >
11
12
12
13
< script >
13
14
window . SpeechRecognition = window . SpeechRecognition || window . webkitSpeechRecognition ;
14
15
16
+ const recognition = new SpeechRecognition ( ) ;
17
+ recognition . interimResults = true ;
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 ( result => 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
+ console . log ( transcript ) ;
35
+
36
+ } ) ;
37
+
38
+ recognition . addEventListener ( 'end' , recognition . start ) ;
39
+ recognition . start ( ) ;
40
+
15
41
16
42
</ script >
17
43
You can’t perform that action at this time.
0 commit comments