Intent handling with command

I do not know what I’m doing wrong, thank you to help me, please.

What I did was the following:
Place the example code on the desktop: https://github.com/synesthesiam/rhasspy/blob/master/bin/mock-commands/handle.py

Then in Profile.JSON Place it as and as the documentation says:

"handle": {
  "system": "command",
  "command": {
      "program": "/path/to/program",
      "arguments": []
  }
}

Note: I did it from the web configurations and update profile.json and wrote the same as I had.

To the Handle.py code add this (to realize whether it works or not when playing that sound):

elif intent == "Hello":
    replies = ['Hi!', 'Hello!', 'Hey there!', 'Greetings.']
    os.system('mpg321 /home/pi/Desktop/test.mp3')

I pronounce “Hello”, I detect it on the web but I do not work the code, I do not know if something else has to be done.

I continued to test another code. With the other if it ran well, but, I have to have it running it to work.

I guess the ideal thing is not having it always running to work… or I’m wrong?

The code that I speak is as follows:

import websocket
import json
from datetime import datetime
import os
import time

# Intents are passed through here
def on_message(ws, message):
    data = json.loads(message)
    print("**Captured New Intent**")
    print(data)

    if ("Hello" == data["intent"]["name"]):
        os.system(‘mpg321 /home/pi/Desktop/test.mp3’)
        
   
def on_error(ws, error):
    print(error)

def on_close(ws):
    print("\n**Disconnected**\n")

def on_open(ws):
    print("\n**Connected**\n")

# Start web socket client
if __name__ == "__main__":
    ws = websocket.WebSocketApp("ws://localhost:12101/api/events/intent",
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
    ws.on_open = on_open
    ws.run_forever()

Did you change the /path/to/program to actually point to your program?

That’s right, I change the path (via profile.json) of the Python file (it’s on the desktop). I said “Hello” and nothing happened, I’m doing something wrong?

Note 1: I change the patch manually from the file (profile.json), and also change it from the web (from the web I only change the patch and the file profile.json was automatically changed).

Note 2: With the 2nd code all the commands are executed correctly via websocket, but I guess it is not the right way to do it, right?

If you’re using Docker, make sure that you give the running container access to /path/to/program with a -v /path/to:/path/to in the docker run command.

1 Like

Honestly I do not understand what I should do. Imagine that my path is at: /home/pi/desktop/robot.py

What should I execute? (Sorry, I’m new using Docker)

Let’s start from the beginning :slight_smile:

What command did you start the Rhasspy docker with?

1 Like

Just this: New profile with Docker

Ok, with that command this folder:
$HOME/.config/rhasspy/profiles is mapped to /profiles in the container.

If you put robot.py into $HOME/.config/rhasspy/profiles, then you can set this in your profile:
“program”: “/profiles/robot.py”

At http://localhost:12101/settings
The option “Intent Handling” Select “Local Command”, in “Program” I wrote: /profiles/robot.py

I keep it and I went straight to the code to see that everything is fine, the following comes out:

"handle": {
    "command": {
        "program": "/profiles/robot.py"
    },
    "system": "command"
},

It does not do anything when I say a phrase, I am waiting for when I call the robot react according to the code (honestly I do not know what the typical operation is).

The code that I put on robot.py was this:

Under “Hello” I add that it reproduces an audio when you recognize it, but nothing happens.

What am I doing wrong? :confused:

What is the Rhasspy log?
What do you have as sentences in what language?

1 Like

rhasspyserver_hermes: Sent 421 char(s) to websocket
rhasspyserver_hermes: <- NluIntent(input=‘Hello’, intent=Intent(intent_name=‘Hello’, confidence_score=1.0), site_id=‘default’, id=None, slots=[], session_id=‘default-hey_robot’, custom_data=‘hey_robot’, asr_tokens=[[AsrToken(value=‘hello’, confidence=1.0, range_start=0, range_end=5, time=None)]], asr_confidence=0.00010727685683729188, raw_input=‘hello’, wakeword_id=‘hey_robot’, lang=None)

This is what comes out in the log, I assure you that the attempt that registers the log is the same as I place in the code:

Note: When I try the second code and I run the Python with Socket works well, the first code I do not run, I guess the first code I should not execute it.

Remember…
This is the 1st code:

This is the 2nd code:

With “Execute” I mean that in console I run Python3 + Path. The code 1 I do not run it, I suppose that Rhasspy does it and that’s why I must place the path in profile.json

The code 2 (the one you have socket) if I run and when I pronounced a phrase the robot recognizes it and runs the conditional that places in the code.

I say it because I want it to be clear what I do, so you can help me with a better precision. Also, because I do not know what “intent handling” of Rhaspy, so he would appreciate it if you explain me, please.

I could not find it in your text, but did you put robot.py here?

Yes, the file “robot.py” with code 1 I put it there: $HOME/.config/rhasspy/profiles
Is next to profile.json

Can you provide a bit more log from Rhasspy?
The intent log in not really the interesting part, since it is correctly recognized

What kind of log do you need?
Where do I find it?

If you haven’t yet, @principe_mestizo, make sure to mark your handling script has executable:

$ chmod +x /path/to/handle.py

The handler scripts don’t have to be Python programs, so Rhasspy just executes them as a program. This means you have to have:

  1. The “shebang” line at the top of your script (#!/usr/bin/env python3)
  2. The script file marked as executable (chmod +x ...)

From the log button.
Surely the intent log you posted is not the only log right?

@synesthesiam gives good pointers as well, I never used a python script as intent handler