Not sure of the method used, but it seems to be effective
This implementation utilizes the SpeechRecognition function from Web Speech API (visit)->https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition
Keep in mind its cross-browser compatibility(verified on Chrome) - may not work on Firefox as per my knowledge -> please check and confirm
It includes a predefined list of colors where the recognized speech is input into a text field (you may have a different list or none at all)
The example code is extracted from the mentioned link
var color = "aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | linen | magenta | maroon | moccasin | navy | olive | orange | orchid | peru | pink | plum | purple | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow";
var colorArray = color.split(" | ");
for (i = 0; i <= colorArray.length; i++) {
$("ul").append("<li>" + colorArray[i] + "</li>");
}
var SpeechRecognition = window.webkitSpeechRecognition;
var grammar = '#JSGF V1.0; grammar colors; public <color> = ' + color + ";";
var recognition = new SpeechRecognition();
var speechRecognitionList = new webkitSpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
recognition.continuous = false;
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
var bg = document.querySelector('html');
document.body.onclick = function() {
recognition.start();
console.log('Ready to receive a color command.');
}
recognition.onresult = function(event) {
var color = event.results[0][0].transcript;
$("input").val(color);
bg.style.backgroundColor = color;
}
<h1 class="output">Click Here to speak</h1>
<input type="text">
<br>
<h4>List of colors</h4>
<ul>
</ul>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
Note that this code may not run correctly here -> try running it elsewhere (requires microphone permission)
Hope you find this information helpful