⬆ Level up
RhasspyIntentLauncher
What does this program do?
After you have specified your sentences/slots/words you speak a command. If everything works Rhasspy will recognize the correct intent - but then? You need a way to run your application to respond to the user's command/query.
This program can run as a daemon (I suggest on your Rhasspy master) and listen for MQTT messages indicating which intent has been recognized. It'll then check a specific folder if it can find a program or script by the name of the intent. E.g. if the recognized intent was hermes/intent/GetTime it hopes to find a file by the name of GetTime. File endings are not relevant.
If a script can be found it'll run it. It extracts the siteId as well as all slots from the MQTT message and it will pass those to the script resulting in an execution like e.g. StocksQuery.sh --siteId satellite01 --stockName Tesla.
Your script now has two general options on how to exit.
- It can finish with something like echo "Tesla stock is currently at xyz dollars".
- It can not print anything, but exit with 0 or an error code.
Sometimes it's better to speak a text response, sometimes a simple beep sound is fitting better. To accomodate for that you can control that through your exit code:
- Exit code 0 or an error will play a sound from the sounds-directory mentioned below that indicates success or an error (in addition to possible text output).
- Exit code 99 means no sound will be played. Only your text will be spoken (if there is one).
Downloads
Installation instructions
The instructions assume paths and users that normally exist on a Raspberry Pi. If your environment is different you'll need the steps.
- Install Java, e.g. with openjdk-10-jre
- Copy the program from the downloads section and put it into its own folder, e.g. /home/pi/rhasspyIntentLauncher
- Copy the start/stop script from the downloads section and put it into that folder. Make sure it's executable: chmod 775 rhasspyIntentLauncher
- In that folder create a file called RhasspyIntentLauncher-settings.ini
- Fill that settings file with values like below, modify them as it's suits you. The most important ones:
- language: It's especially relevant for how well TTS will work.
- mqttClientServerHostname
- scriptsPath
- ignoredSatellites - In my setup I'm currently receiving an additional MQTT messages with the siteId of my master. I'm filtering that. You can specifiy multiple values here separated by a comma.
- You can create a subfolder called sounds and in that folders by the names confirm/error/other. A random one of each category will be played as audible feedback. You use the example provided in the downloads.
- Create a systemd service file at /etc/systemd/system/rhasspy-intent-launcher.service
- Fill it with the values below. Remember to edit the paths at the top to match with whatever location you put the program
- Run sudo systemctl daemon-reload
- Run sudo systemctl enable rhasspy-intent-launcher.service
- Run sudo systemctl start rhasspy-intent-launcher.service
- Put runnable scripts/application into the folder you specified as scriptsPath in the config file and give it a try.
Config file example
intentMqttPath=hermes/intent/#
language=de-DE
sslDebug=false
keystoreFilename=keystore.jks
keystorePassword=changeme
logFileEnabled=false
logFolderPath=/var/log/rhasspyIntentLauncher
logLevel=5
logMaxSize=5
scriptsPath=/home/pi/rhasspyScripts
mqttClientServerHostname=mqtt.myDomainName.com
mqttClientServerPort=1883
mqttClientUseSsl=false
mqttClientUseAuthentication=false
mqttClientUsername=
mqttClientPassword=
ignoredSatellites=master
systemd service file "rhasspy-intent-launcher.service"
[Unit]
Description=rhasspy-intent-launcher
After=network.target
[Service]
ExecStart=/home/pi/rhasspyIntentLauncher/rhasspyIntentLauncher start
ExecStop=/home/pi/rhasspyIntentLauncher/rhasspyIntentLauncher stop
WorkingDirectory=/home/pi/rhasspyIntentLauncher
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
Bash script examples
These scripts don't do a lot, just output a simple response by playing a sound or speaking a text. Consider them an example for how to work.
Play a specific sound file (example here: "announce me" -> play Imperial March)
#!/bin/bash
SITEID=""
PARAMS=""
while (( "$#" )); do
case "$1" in
--siteId)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
SITEID=$2
shift 2
else
echo "Error: Argument for $1 is missing" >&2
exit 1
fi
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
# set positional arguments in their proper place
eval set -- "$PARAMS"
if [ "$SITEID" = "" ]
then
echo "Specify siteId"
exit 1
else
#Encrypted connection
mosquitto_pub -h mqtt.myServer.org -p 8883 -t hermes/audioServer/$SITEID/playBytes/0815 --cafile /home/pi/root_cert_base64.crt --tls-version tlsv1.2 -f /home/pi/imperial_march.wav
#Unencrypted connection
mosquitto_pub -h mqtt.myServer.org -p 1883 -t hermes/audioServer/$SITEID/playBytes/0815 -f /home/pi/imperial_march.wav
exit 99
fi
Speak a text response (example here: "What's the first rule of Fight Club")
#!/bin/bash
echo "DO NOT talk about Fight Club"
exit 99
Additional hints
If you want to activate an encrypted connection to your MQTT server and you get errors like trust anchor not found you need to create a java keystore. With a program like Keystore Explorer that's pretty easy. Create a new file and then click "Import trusted certificate". Select a file containing the root certificate that signed your MQTT server's certificate.
Afterwards put the keystore file in the same folder as the intent launcher and also mention the keystore file in the config file.