This document describes the way to support your own MagicMirror² module with voice control.
Use an unique mode, which is not already taken from one of the other modules in this list.
Try to avoid short words like ON
, TO
, etc. as far as possible
As soon as you receive the notification ALL_MODULES_STARTED
from the core system, register your voice commands by sending the following notification
- notification:
REGISTER_VOICE_MODULE
- payload: Object with
mode
(string) andsentence
(array) properties
notificationReceived: function (notification, payload, sender) {
if(notification === "ALL_MODULES_STARTED"){
this.sendNotification("REGISTER_VOICE_MODULE", {
mode: "FOOTBALL",
sentences: [
"OPEN HELP",
"CLOSE HELP",
"SHOW STATISTIC",
"HIDE STATISTIC"
]
});
}
}
When the user is in the mode of your module, you will receive the following notification
- notification:
VOICE_YOURMODE
- payload: String with all detected words.
notificationReceived: function (notification, payload, sender) {
...
if(notification === "VOICE_FOOTBALL" && sender.name === "MMM-voice"){
this.checkCommands(payload);
}
}
// test for your commands
checkCommands: function(data){
if(/(OPEN)/g.test(data) && /(HELP)/g.test(data)){
// do your magic
}
...
}
When the mode of MMM-voice gets changed it will send a broadcast VOICE_MODE_CHANGED
- notification:
VOICE_MODE_CHANGED
- payload: Object with
old
(string) andnew
(string) mode as properties
This gets handy e.g. to revert your manipulations on the DOM.
notificationReceived: function (notification, payload, sender) {
...
if(notification === "VOICE_MODE_CHANGED" && sender.name === "MMM-voice" && payload.old === "FOOTBALL"){
// do your magic
}
}