Intent Classification
There are often a lot of ways to say the same thing: “boot up”, “power on”, and “fire up” are all different ways that someone might say “turn on”.
To handle these cases, we can use an IntentClassifier
. This type of voice controller allows you to define actions in natural language
that you want users to be able to invoke with a variety of different possible commands.
When the user gives a command, the IntentClassifier
tries to invoke the most semantically similar action that you specify:
// command handlers map voice commands to the actions they should trigger
const commandHandlers = {
"turn on": () => { // triggers when you say something similar to "turn on"...
document.querySelector("body").style.backgroundColor = "white"
},
"turn off": () => { // ...and when you say something similar to "turn off"
document.querySelector("body").style.backgroundColor = "black"
}
}
const intentClassifier = Moonshine.IntentClassifier(commandHandlers)
var transcriber = new Moonshine.MicrophoneTranscriber(
"model/tiny",
intentClassifier
)
transcriber.start();
Now when the user says something similar to “turn on” or “turn off”, the most relevant action will be triggered.
Note that we did not enable streaming mode—this is highly recommended when you are using voice control.