There a lot Rhasspy can do yet, with HA and I hope soon with Jeedom, but is it possible to handle some of our intent with a simple python script ?
For example, if intent recognized is ‘GetTime’, it would start a python script than will import rhasspy as a package, get the hour, and send back a tts command to say the answer on the right site_id ?
Sort of Snips skills
I have been looking at AppDaemon to do this. I made a very simple proof of concept and this works, but there’s still a lot of work to make this easy and maintainable for app developers, including adding intents in the app, supporting multiple languages, and so on.
Eventually we should have something like SnipsKit, which I wrote to streamline creating Snips apps. I don’t want to have a hardcoded URL for a Rhasspy installation in apps, for instance, which was a real pain in the ass with the way Snips apps worked by default.
On the other hand, running installable intent skills like Snips looks like a lot of work:
a SDK to build the skill (in multiple language like Javascript, Python, etc.) and the binaries to execute them
a skill store to find them
a skill repository to store them (Github?)
a skill installation process (Oauth2? APi keys?)
a skill manager to control all this
etc…
There is the Alice project that do just that but is still based on Snips softwares. The devs are migrating away from these Snips dependencies since the Sonos acquisition but they are not there yet (that’s why I recently spoke to them about Rhasspy to provide the parts they lack and plug everything together via the Hermes protocol but it looks like they want to do their own system).
I think Home Assistant, Jeedom, Hermes protocol MQTT/Websocket and Command intent handlers should be enough and that Rhasspy should focus on the voice interaction part (that’s the hardest part for makers to get right).
The more advanced users probably want to implement their own skills system based on their favorite language/system (as I did) because the interactions end up to be quite complex (playing music via Spotify, triggering alarms across multiple satellites, controling a multiroom playback, per user restrictions, assistant personality, etc.).
I don’t wish/ask for a store, repo, install etc, just a way to handle local python scripts for devs.
Once @synesthesiam add the Command intent handler, I will be able to handle all my need in Jeedom, even running python/php script on some intent. So that’s not high priority for me, just though some other users would also get back into such skills. I use a few with Snips, but can handle them with Jeedom once Rhasspy got its connection to it
Yes, but you can do that in the command intent handler.
Either you have to program it in HA (or other software), or program it in the command intent handler.
This is not intent recognition, but intent handling. There might be some confusion about that?
What I find really missing from the current Command intent handler is the ability to return a response via stdout to be automatically spoken by the TTS system (if enabled).
I’m building an interactive robot for my kids (and for me) to have fun with.
I’ve been using the rhasspy-client package and the HTTP API. Here is a short example of the pattern I’ve been using. Hopefully it may be useful to others:
#!/usr/bin/env python
import asyncio
import aiohttp
import websockets
import json
import datetime
from rhasspyclient import RhasspyClient
url = 'http://localhost:12101/api'
async def speak(text):
async with aiohttp.ClientSession() as session:
client = RhasspyClient(url, session)
# Call sub-commmand
await client.text_to_speech(text)
def async_speak(text):
global loop
print(text)
asyncio.ensure_future(speak(text), loop=loop)
def GetTime(intent):
# If you need, you can access a dict of slots in the intent
# slots = intent['slots']
now = datetime.datetime.now().time()
hour = now.hour
minute = now.minute
t = hour + (minute / 60)
if (hour > 12):
hour -= 12
if minute == 0:
minute = 'oclock'
elif minute < 10:
minute = 'o %d' % minute
stime = "%s %s" % (hour, minute)
async_speak("Let me check. It is %s." % (stime))
def Christmas(intent):
# If you need, you can access a dict of slots in the intent
# slots = intent['slots']
today = datetime.datetime.now()
christmas = datetime.datetime(today.year, 12, 25)
if (today >= christmas):
christmas = datetime.datetime(today.year + 1, 12, 25)
days = (christmas - today).days
async_speak("There are %s days until Christmas, not including today." % days)
async def get_event():
uri = "ws://localhost:12101/api/events/intent"
global timers
async with websockets.connect(uri) as websocket:
intent = await websocket.recv()
intent = json.loads(intent)
#print(f"< {intent}")
cmd = (intent['intent']['name'])
f = globals().get(cmd)
if f:
f(intent)
else:
print('Got unhandled command: %s' % cmd)
loop = asyncio.get_event_loop()
while True:
asyncio.get_event_loop().run_until_complete(get_event())
I am wondering about ways to have the sentences grouped with the intents. So that when implementing an intent you can see at a glance which slots and structure you have in the grammar. To this end, I am thinking about embedding the sentence/grammar in docstrings, then sending them to rhasspy (and running training) using the API when my robot script starts up.
FileNotFoundError: [Errno 2] No such file or directory: ‘/home/pi/.config/rhasspy_handler/intentDispatcher.py’: ‘/home/pi/.config/rhasspy_handler/intentDispatcher.py’
And setting system command make me loosing system remote, so no more post to server (jeedom plugin).
My Jeedom plugin is set to handle only intentNameJeedom names (finish with jeedom), so I could have a python script handling other intents. But can’t get it starting, and can’t get the two, command AND remote.
I could handle to post myself to jeedom plugin in the intent handler, but do you have an exemple of path working ?
pip3 install rhasspyclient
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting rhasspyclient
Could not install packages due to an EnvironmentError: 404 Client Error: Not Found for url: https://pypi.org/simple/rhasspyclient/
@duch, I wrote the script intending it to be a standalone script that runs continuously, handling intents that Rhasspy detects. I took this approach because I am not running home assistant in my project. Rhasspy needs to also be running (I run it in docker).
What is your context? How you are calling this script?