@@ -9,7 +9,7 @@ var recognition = new SpeechRecognition();
9
9
var speechRecognitionList = new SpeechGrammarList ( ) ;
10
10
speechRecognitionList . addFromString ( grammar , 1 ) ;
11
11
recognition . grammars = speechRecognitionList ;
12
- // recognition.continuous = false;
12
+ recognition . continuous = false ;
13
13
recognition . lang = 'en-US' ;
14
14
recognition . interimResults = false ;
15
15
recognition . maxAlternatives = 1 ;
@@ -34,15 +34,12 @@ recognition.onresult = function(event) {
34
34
// The SpeechRecognitionEvent results property returns a SpeechRecognitionResultList object
35
35
// The SpeechRecognitionResultList object contains SpeechRecognitionResult objects.
36
36
// It has a getter so it can be accessed like an array
37
- // The [last ] returns the SpeechRecognitionResult at the last position.
37
+ // The first [0 ] returns the SpeechRecognitionResult at the last position.
38
38
// Each SpeechRecognitionResult object contains SpeechRecognitionAlternative objects that contain individual results.
39
39
// These also have getters so they can be accessed like arrays.
40
- // The [0] returns the SpeechRecognitionAlternative at position 0.
41
- // We then return the transcript property of the SpeechRecognitionAlternative object
42
-
43
- var last = event . results . length - 1 ;
44
- var color = event . results [ last ] [ 0 ] . transcript ;
45
-
40
+ // The second [0] returns the SpeechRecognitionAlternative at position 0.
41
+ // We then return the transcript property of the SpeechRecognitionAlternative object
42
+ var color = event . results [ 0 ] [ 0 ] . transcript ;
46
43
diagnostic . textContent = 'Result received: ' + color + '.' ;
47
44
bg . style . backgroundColor = color ;
48
45
console . log ( 'Confidence: ' + event . results [ 0 ] [ 0 ] . confidence ) ;
0 commit comments