Snips services for testing

With the various Rhasspy services getting more solid, I’d like to start testing some actual Snips skills. I assume these run as external MQTT services, and work with dialogue session messages, right?

Any suggestions on some basic skills to test?

2 Likes

That’s how it works in the main. The skills are naturally adapted to the internal structure of Snips. The training of the words and the corresponding intents had to be done in the online portal (Console) of Snips and the generated data was downloaded and installed on the Raspberry Pi with the help of the SAM assistant. I didn’t analyze this in detail, but I noticed that when I looked at the Python code and made SCP connections, Snips was always creating one directory per skill named by the developer.

As a first test with Snips I had installed a date, time and dateinfo Skill for Snips from the developer (MrJohnZoidberg). You should like his name :rofl: The skill works very well and allows you to ask for the time, day of the week, date and calendar week. It communicates on German but I think if you look at the code it is no problem. For me as a german speaking person it was of course a welcome test.

Snips Skill:

#!/usr/bin/env python3

from hermes_python.hermes import Hermes, MqttOptions
import datetime
import random
import toml


USERNAME_INTENTS = "domi"
MQTT_BROKER_ADDRESS = "localhost:1883"
MQTT_USERNAME = None
MQTT_PASSWORD = None


def user_intent(intentname):
    return USERNAME_INTENTS + ":" + intentname


def subscribe_intent_callback(hermes, intent_message):
    intentname = intent_message.intent.intent_name

    if intentname == user_intent("currentDate"):
        year = datetime.datetime.now().year
        month = datetime.datetime.now().month
        day = datetime.datetime.now().day
        weekday = datetime.datetime.now().isoweekday()
        weekday_list = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag']
        result_sentence = "Heute ist {0}, der {1}.{2}.{3} .".format(weekday_list[weekday - 1], day, month, year)
        current_session_id = intent_message.session_id
        hermes.publish_end_session(current_session_id, result_sentence)

    elif intentname == user_intent("currentTime"):
        hours = datetime.datetime.now().hour
        minutes = datetime.datetime.now().minute
        if minutes == 0:
            minutes = ""
        if hours == 1:
            result_sentence = "ein Uhr {0} .".format(minutes)
        else:
            result_sentence = "{0} Uhr {1} .".format(hours, minutes)
        first_part = ["Gerade ist es", "Es ist jetzt", "Es ist", "Die aktuelle Zeit ist"]
        result_sentence = random.choice(first_part) + " " + result_sentence
        current_session_id = intent_message.session_id
        hermes.publish_end_session(current_session_id, result_sentence)

    elif intentname == user_intent("weekNumber"):
        datetime_str = intent_message.slots.date.first().value[:-10]
        datetime_obj = datetime.datetime.strptime(datetime_str, "%Y-%m-%d %H:%M")
        result_sentence = "An diesem Datum ist die Kalenderwoche {0}".format(datetime_obj.isocalendar()[1])
        current_session_id = intent_message.session_id
        hermes.publish_end_session(current_session_id, result_sentence)

    elif intentname == user_intent("dateInfo"):
        result_sentence = "Diese Funktion ist noch nicht vorhanden, wird aber bald hinzugefügt."
        datetype = intent_message.slots.datetype.first().value
        if datetype == 'weekday' or 'wochentag' in datetype:
            weekday = datetime.datetime.now().isoweekday()
            weekday_list = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag']
            result_sentence = "Heute haben wir {weekday}.".format(weekday=weekday_list[weekday - 1])
        elif datetype == 'year':
            year = datetime.datetime.now().year
            result_sentence = "Wir sind im Jahr {year}".format(year=year)
        elif datetype == 'weeknumber' or 'kw' in datetype:
            weeknumber = datetime.datetime.now().isocalendar()[1]
            result_sentence = "Wir haben gerade die Kalenderwoche {weeknumber}".format(weeknumber=weeknumber)
        elif datetype == 'minute':
            minutes = datetime.datetime.now().minute
            result_sentence = "Wir haben die Minute {minutes}".format(minutes=minutes)
        elif datetype == 'hour':
            hours = datetime.datetime.now().hour
            result_sentence = "Wir haben gerade die Stunde {hours}".format(hours=hours)
        current_session_id = intent_message.session_id
        hermes.publish_end_session(current_session_id, result_sentence)


if __name__ == "__main__":
    snips_config = toml.load('/etc/snips.toml')
    if 'mqtt' in snips_config['snips-common'].keys():
        MQTT_BROKER_ADDRESS = snips_config['snips-common']['mqtt']
    if 'mqtt_username' in snips_config['snips-common'].keys():
        MQTT_USERNAME = snips_config['snips-common']['mqtt_username']
    if 'mqtt_password' in snips_config['snips-common'].keys():
        MQTT_PASSWORD = snips_config['snips-common']['mqtt_password']

    mqtt_opts = MqttOptions(username=MQTT_USERNAME, password=MQTT_PASSWORD, broker_address=MQTT_BROKER_ADDRESS)
    with Hermes(mqtt_options=mqtt_opts) as h:
        h.subscribe_intents(subscribe_intent_callback).start()

Here is the link to the GitHub repository:

This is the screenshot from the Snips console showing the corresponding Intents:

Translation:

currentDate:
“What day is today”
“What day is it”

dateInfo:
“What is the week number”
“What week number we have”

weekNumber:
“What week is today?”
“May 31 is what week?”

currentTime:
“Give me the time”
“Tell me the time”

I think as a start a date time query for Rhasspy would be great!

2 Likes

I agree. And, the most important feature - at least for me - is a timer :wink:. Unfortunately I never found a working one for Snips.

Hi @schnopsi
What logic do you want to implement? I’m using home assistant and have timer there. I’m enabling it by rhasspy voice command and then HA turn off my TV in 20 minutes… I’m using it to fall asleep with music :crazy_face:

I haven’t done it, but it’s possible to pass minutes value in a command

Did the same with FHEM. But I’m still not sure, where I want to have the logic. Somehow I would prefer, if my speech assistant is able to do some basic things (like timer and time) without the need of any kind of software behind.
But, that’s not the topic here :wink:

1 Like

Awesome, thank you for the response! I’ll test this skill out and see how it works. How could anything by a Zoidberg not work, after all :smiley:

2 Likes