Connecting command line parser to mqtt

Connecting Python-IntentHandlers to Rhasspy

As Rhasspy can tell you the weather (at least if you speak German) descriped, it would be a good idea to handle intents directly in python.
The best way to exchange information to the python-script and back to calling satellite would be mqtt,
especially if you use docker container for rhasspy or nodered.

As you can see in https://rhasspy.github.io/rhasspy-voltron/tutorials.html#server-with-satellites ( Python Skill Code), there is already a basic script.

Whats missing is a connection to the skills.

My Idea:

Adding a function into the script,

import importlib

def handle_intent(nlu_payload):
    try:
        module = importlib.import_module(nlu_payload["intent"]["intentName"] + ".action")
        return module.getAnswer(nlu_payload)
    except:
        return ""

calling it and resending it.

 answer = handle_intent(nlu_payload)
 client.publish("hermes/tts/say", json.dumps({"text": answer , "siteId": site_id}))

Now the stuff for the intenthandler programmers:

In Profile folder, you create a subfolder (Intents?),intentHandler
Inside:

  • The script from above (checkIntent.py)
  • Each Intenthandler in its own folder with the Intent Name (GetTime, SetSituations)
  • Inside the Intentfolder the starting python-module called “action.py”
  • Inside the “action.py” a function called getAnswer(payload), which returns the answer that will be resendet to the satellites.

Then you only have to copy the new IntentHandler in that Intents-folder, start the checkIntent.py script and thats it.

Maybee it’s a useful idea, but I think the import stuff could be better. It would be also better if you could arrange the answering procedure with just a print() command.

1 Like