Skip to content

Commit

Permalink
Merge pull request #40 from luka-zitnik/scc-fixes
Browse files Browse the repository at this point in the history
Small fixes to speech color changer
  • Loading branch information
chrisdavidmills authored Feb 26, 2020
2 parents ed4a11d + e4a7d0f commit 7f4a1bf
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions speech-color-changer/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var recognition = new SpeechRecognition();
var speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
//recognition.continuous = false;
recognition.continuous = false;
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
Expand All @@ -34,15 +34,12 @@ recognition.onresult = function(event) {
// The SpeechRecognitionEvent results property returns a SpeechRecognitionResultList object
// The SpeechRecognitionResultList object contains SpeechRecognitionResult objects.
// It has a getter so it can be accessed like an array
// The [last] returns the SpeechRecognitionResult at the last position.
// The first [0] returns the SpeechRecognitionResult at the last position.
// Each SpeechRecognitionResult object contains SpeechRecognitionAlternative objects that contain individual results.
// These also have getters so they can be accessed like arrays.
// The [0] returns the SpeechRecognitionAlternative at position 0.
// We then return the transcript property of the SpeechRecognitionAlternative object

var last = event.results.length - 1;
var color = event.results[last][0].transcript;

// The second [0] returns the SpeechRecognitionAlternative at position 0.
// We then return the transcript property of the SpeechRecognitionAlternative object
var color = event.results[0][0].transcript;
diagnostic.textContent = 'Result received: ' + color + '.';
bg.style.backgroundColor = color;
console.log('Confidence: ' + event.results[0][0].confidence);
Expand Down

0 comments on commit 7f4a1bf

Please sign in to comment.