File tree Expand file tree Collapse file tree 2 files changed +4066
-0
lines changed
Expand file tree Collapse file tree 2 files changed +4066
-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+ recognition . lang = 'ru-RU' ;
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 ) . map ( r => r [ 0 ] ) . map ( r => r . transcript ) . join ( '' ) ;
25+ p . textContent = transcript ;
26+ if ( e . results [ 0 ] . isFinal ) {
27+ p = document . createElement ( "p" ) ;
28+ words . appendChild ( p ) ;
29+ }
30+ } ) ;
31+
32+ recognition . addEventListener ( 'end' , recognition . start ) ;
33+
34+ recognition . start ( ) ;
1535
1636</ script >
1737
You can’t perform that action at this time.
0 commit comments