fewieden / MMM-voice

Offline Voice Recognition Module for MagicMirror²

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding Param?

isaacrlevin opened this issue · comments

With the current model, how would we add params to commands? For instance if I wanted to see the weather in a certain city. I can figure out the work on the API side, but chaining the command is something I am not too sure about. Any thoughts?

@isaac2004 sorry for the late response. With pocketsphinx something like this is not possible out of the box. The whole dictionairy needs to be defined up front.

What could be done to still realize this?

  • In case you are always interested in the same set of cities, they could be defined. Your weather module would need to register the following dictionairy/commands:
this.cities = [
  "MUNICH",
  "NORWALK",
  "NEW YORK",
  "BERLIN"
];

this.sendNotification("REGISTER_VOICE_MODULE", {
  mode: "WEATHER",
  sentences: this.cities.map(city => `HOW IS THE WEATHER IN ${city}`)
});
  • Once the voice module recognizes commands inside the weather mode it will send the text to your weather module. Now you need to check if a valid command was entered.
notificationReceived: function (notification, payload, sender) {
  if(notification === "VOICE_WEATHER" && sender.name === "MMM-voice"){
    this.checkCommands(payload);
  }
},

checkCommands: function(data){
  if(/(HOW)/g.test(data) && /(WEATHER)/g.test(data)){
    for (const city of this.cities) {
      if (data.includes(city)) {
        // request your weather data for the specific city
        return;
      }
    }
  }
}
  • The above proof of concept could be extended to make the cities configurable in the config.js file. Also note, that you probably need to map the city name to an id or similar depending on the underlying weather provider.
  • For more details also have a look into the documentation of this module https://github.com/fewieden/MMM-voice/blob/master/DEVELOPER.md