Skip to content

Commit bb96403

Browse files
committed
fix alternatives example
1 parent 460401c commit bb96403

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

examples/static/microphone-alternatives.html

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,24 @@ <h2>Code for this demo:</h2>
5050
var $curSentence = $('<span>&nbsp;</span>').appendTo($output);
5151

5252
// 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) {
5454

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');
5967

6068
$curSentence.html(dropdown);
6169

62-
if (result.final) {
70+
if (message.results[0].final) {
6371
// if we have the final text for that sentence, start a new one
6472
$curSentence = $('<span/>').appendTo($output);
6573
}

0 commit comments

Comments
 (0)