File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -50,16 +50,24 @@ <h2>Code for this demo:</h2>
50
50
var $curSentence = $ ( '<span> </span>' ) . appendTo ( $output ) ;
51
51
52
52
// a result is approximately equivalent to a sentence, and is the granularity that alternatives are selected on
53
- stream . on ( 'data' , function ( result ) {
53
+ stream . on ( 'data' , function ( message ) {
54
54
55
- // build up a quick HTML dropdown the wrong way...
56
- var dropdown = [ '<select>' ] . concat ( result . alternatives . map ( function ( alt ) {
57
- return '<option>' + alt . transcript + '</option>' ;
58
- } ) ) . concat ( [ '</select>' ] ) . join ( '\n' ) ;
55
+ if ( ! message . results ) {
56
+ // won't happen in this example, but would if speaker_labels is enabled
57
+ return ;
58
+ }
59
+
60
+ // build up a HTML dropdown menu with the alternatives
61
+ var dropdown = message . results . map ( function ( result ) {
62
+ var options = result . alternatives . map ( function ( alt ) {
63
+ return '<option>' + alt . transcript + '</option>' ;
64
+ } ) . join ( '\n' ) ;
65
+ return '<select>' + options + '</select>' ;
66
+ } ) . join ( '\n' ) ;
59
67
60
68
$curSentence . html ( dropdown ) ;
61
69
62
- if ( result . final ) {
70
+ if ( message . results [ 0 ] . final ) {
63
71
// if we have the final text for that sentence, start a new one
64
72
$curSentence = $ ( '<span/>' ) . appendTo ( $output ) ;
65
73
}
You can’t perform that action at this time.
0 commit comments