Local python intent skills

it’s alive ! But seems that something has changed with rhasspy-client :

python3 intentDispatcher.py 
Got unhandled command: 
Let me check. It is 5 45.
Task exception was never retrieved
future: <Task finished coro=<speak() done, defined at intentDispatcher.py:13> exception=AttributeError("'RhasspyClient' object has no attribute 'text_to_speech'")>
Traceback (most recent call last):
  File "intentDispatcher.py", line 18, in speak
    await client.text_to_speech(text)
AttributeError: 'RhasspyClient' object has no attribute 'text_to_speech'

that’s weird since i can see it in the code

The package hasn’t been updated since I added that method.

@synesthesiam can you update the package on pypi?

1 Like

Thx, i pip uninstalled rhasspy-client and installed from source, it’s working.

now i wonder, which is better conceptually? Have a daemon that listens to Rhasspy thanks to the client or use the Command mechanism, great Dilemma

Sorry about that. Merged some of my own changes too and bumped the version to 1.1.0 on pypi.

Could someone please share their intent hanlder? Would be very helpful building one’s own! Appreciate it!

Cheers

I get the same error, did you manage to solve it? :slight_smile:

This is how a basic python handler could look like:

https://pastecode.xyz/view/784c3bd1

It implements “GetDate” and “Hello” intents.

2 Likes

awaesome, should be in the doc !

I’ve made a pull request

1 Like

That’s great, thanks a lot!

Hey @Sam, when running your code I get this error:

Command ‘[’/intenthandler.py’]’ returned non-zero exit status 1.

Did you have the same problem?

Yes, it’s working here. I run a deployment with the official docker container. Have you looked at the server logs? The python error is printed there if there is one.

1 Like

I have the same problem though the script works perfectly in command line when i feed it with the json found in the logs.
No error triggered in rhasspy logs :frowning:

Here they are

[INFO:1674335] quart.serving: 192.168.1.17:57945 POST /api/text-to-intent 1.1 200 461 313683
[DEBUG:1674319] CommandIntentHandler: forwarding -> ready
[DEBUG:1674318] HomeAssistantIntentHandler: POSTed intent to http://localhost:8123/api/events/rhasspy_Hello
[DEBUG:1674311] urllib3.connectionpool: http://localhost:8123 "POST /api/events/rhasspy_Hello HTTP/1.1" 200 43
[DEBUG:1674296] urllib3.connectionpool: Starting new HTTP connection (1): localhost:8123
[DEBUG:1674285] CommandIntentHandler: ready -> forwarding
[ERROR:1674283] CommandIntentHandler: in_started
Traceback (most recent call last):
  File "/home/pi/rhasspy/rhasspy/intent_handler.py", line 328, in in_ready
    self.command, check=True, input=json_input, stdout=subprocess.PIPE
  File "/usr/lib/python3.7/subprocess.py", line 487, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/home/pi/intentHandler.py']' returned non-zero exit status 1.
[DEBUG:1674041] CommandIntentHandler: ['/home/pi/intentHandler.py']
[DEBUG:1674034] __main__: {"intent": {"name": "Hello", "confidence": 1.0}, "entities": [], "text": "bonjour", "raw_text": "bonjour", "recognize_seconds": 0.001742455999192316, "tokens": ["bonjour"], "raw_tokens": ["bonjour"], "speech_confidence": 1, "slots": {}, "wakeId": "", "siteId": "default", "time_sec": 0.008512496948242188}

EDIT : i found the answer, i added a dependency to pytz but it was not installed in venv

1 Like

also make sure that the script has exec permission:
chmod +x handler.py

1 Like

I made a couple of tries, command is a great feature but IMHO it is not usable with a complex python script.
Python is easy but as soon as soon you load some dependencies script starting is very slow. As an example on my Pi3B import mplayer.py takes almost 3 seconds which is way to long when you wait for an answer.

@jason solution with a daemon seems better in that usecase

I agree, @duch, I already suggested AppDaemon, which I played with for a simple script. If I would start a more complex intent handler script now, I would use AppDaemon. You can use it with Home Assistant events or MQTT messages.

Unfortunately I don’t have time now to explore this route further, but you should definitely check it out if you want a daemon-based approach.

1 Like

Hello

Not sure it’s the right place…

I am using Rhasspy 2.5.0 on Ubuntu for testing.

It seems that the program file in “intent handling -> local command” is found only if it has only one character in the name.

I know that sounds strange but I had it working with a program in “/usr/bin/A” however with the same program in “/usr/bin/handle.py” I get :
FileNotFoundError: [Errno 2] No such file or directory: ‘h’: ‘h’

Is it something I did wrong ?

Hi, any chance you could repost, it’s gone from pastecode now? Thanks.

Did you ever get this working? I’m trying to call a local command in Rhasspy and it doesn’t seem to actually run it. Curious if you had to put the script somewhere specific?

Sure you can. I see your post is old, but did you finish it?