Skip to content

Commit 7f4a1bf

Browse files
Merge pull request #40 from luka-zitnik/scc-fixes
Small fixes to speech color changer
2 parents ed4a11d + e4a7d0f commit 7f4a1bf

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

speech-color-changer/script.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var recognition = new SpeechRecognition();
99
var speechRecognitionList = new SpeechGrammarList();
1010
speechRecognitionList.addFromString(grammar, 1);
1111
recognition.grammars = speechRecognitionList;
12-
//recognition.continuous = false;
12+
recognition.continuous = false;
1313
recognition.lang = 'en-US';
1414
recognition.interimResults = false;
1515
recognition.maxAlternatives = 1;
@@ -34,15 +34,12 @@ recognition.onresult = function(event) {
3434
// The SpeechRecognitionEvent results property returns a SpeechRecognitionResultList object
3535
// The SpeechRecognitionResultList object contains SpeechRecognitionResult objects.
3636
// 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.
3838
// Each SpeechRecognitionResult object contains SpeechRecognitionAlternative objects that contain individual results.
3939
// 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;
4643
diagnostic.textContent = 'Result received: ' + color + '.';
4744
bg.style.backgroundColor = color;
4845
console.log('Confidence: ' + event.results[0][0].confidence);

0 commit comments

Comments
 (0)