Intent handling with command

ok cool, so handly.py is working :slight_smile:
The ${RHASSPY_PROFILE_DIR} is not found in handle.py, because that variable is not known there.
Try it with
os.system(f"aplay /home/pi/.config/rhasspy/profiles/es/sounds/wake.wav")
Assuming you have that in your profile, please check the path.

What is it that you want to achieve? The original code:
speech(random.choice(replies))
should activate the Text to speech

Does this work in a terminal?
aplay /home/pi/.config/rhasspy/profiles/es/sounds/wake.wav

if not, the python script will certainly not work

In the log it does not work:

[DEBUG:2021-04-20 14:58:24,629] rhasspyremote_http_hermes: /home/pi/.config/rhasspy/profiles/es/wake.wav: No such file or directory

In Terminal works and reproduces well:

    aplay /home/pi/.config/rhasspy/profiles/es/wake.wav
    Playing WAVE '/home/pi/.config/rhasspy/profiles/es/wake.wav' : Signed 16 bit Little Endian, Rate 22050 Hz, Stereo

Is it honestly rare, there is some other way of playing audio? I will not use TTS.

Hmm ok, that is strange.

Can you post the whole python script?

#!/usr/bin/env python3
import sys
import json
import os

data = json.loads(sys.stdin.read())
intent = data["intent"]["name"]
wake = data["wakeword_id"]

if wake:
    print("WORRRKKKKKKKKK!!!!!!!!!!!!!!!")
    print(wake)

if intent == "banal_1":
    os.system("aplay /home/pi/.config/rhasspy/profiles/es/wake.wav")
    print("test-test-test")
    print(intent)

Logs:

[DEBUG:2021-04-20 15:17:06,861] rhasspyremote_http_hermes: ['/profiles/es/handle.py']
[DEBUG:2021-04-20 15:17:07,091] rhasspyremote_http_hermes: /home/pi/.config/rhasspy/profiles/es/wake.wav: No such file or directory

[WARNING:2021-04-20 15:17:07,092] rhasspyremote_http_hermes: Failed to parse output as JSON: Expecting value: line 1 column 1 (char 0)
[WARNING:2021-04-20 15:17:07,092] rhasspyremote_http_hermes: Output: b'WORRRKKKKKKKKK!!!!!!!!!!!!!!!\noye_robot\ntest-test-test\nHola\n'
[DEBUG:2021-04-20 15:17:08,772] rhasspy-wake-raven: Exiting refractory period

Note “Hello” was the “Intent” I said. It registers everything well, executes the print correctly. The problem is sound.

I am trying more things, as with threads and does not work with the handle but if executing the direct python3, you can think of the reason?

import subprocess
    
def runcommand (cmd):
        proc = subprocess.Popen(cmd,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE,
                                shell=True,
                                universal_newlines=True)
        std_out, std_err = proc.communicate()
        return proc.returncode, std_out, std_err

runcommand("aplay /home/pi/.config/rhasspy/profiles/es/wake.wav")

I do not know much about the os command, but you might want to try playsound

I do not know what you ar e trying to achieve, but for me this is clearly some python issue and not a Rhasspy issue :slight_smile:

1 Like

@romkabouter @synesthesiam A thousand thanks for all your help, really.

2 Likes

You could always POST the WAV data to Rhasspy itself:

curl -X POST \
     -H 'Content-Type: audio/wav' \
     --data-binary @/path/to/file.wav \
     'http://localhost:12101/api/play-wav'

or send an MQTT message:

mosquitto_pub -p 12183 \
              -t hermes/audioServer/default/playBytes/1 \
              -s < /path/to/file.wav
1 Like

It works on console, but not in the Python code of handle.py

[DEBUG:2021-04-20 18:05:55,459] rhasspyasr_deepspeech_hermes: Receiving audio
[DEBUG:2021-04-20 18:05:55,488] rhasspyremote_http_hermes: Warning: Couldn't read data from file "/home/pi/Desktop/wake.wav", this makes 
Warning: an empty POST.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    85  100    85    0     0   1024      0 --:--:-- --:--:-- --:--:--  1024

Log:

[DEBUG:2021-04-20 21:23:20,467] rhasspyremote_http_hermes: Traceback (most recent call last):
  File "/profiles/es/handle.py", line 5, in <module>
    from playsound import playsound
ModuleNotFoundError: No module named 'playsound'

The problem is that that comes out with other dependencies, most. I have them installed correctly, in console runs well.

I think with HTTP POST if it’s going to work, but I still can not make it work on Python. Can you help me?

I have this:

import requests

requests.post("http://localhost:12101/api/play-wav",
              data = "/home/pi/Desktop/demo.wav",
              headers = {"Content-Type": "audio/wav"})

Hmm ok, I don’t know. Maybe because the python is called from Rhasspy docker, which had playsound not installed.

1 Like

Do you know about this?

From what I have read in various topics, your biggest problem is not understanding how docker works. I assume you are trying to get the script to run as command script and therefore you are running inside docker and the path “/home/pi/Desktop/demo.wav” does not exist inside docker.

From the way it sounds when you write English is not your native language (it isn’t mine either) and most problems you face come from not recognizing what is available inside docker and what is outside. You should find yourself an introduction into docker in your language somewhere on the internet and visit the script problem after you know how to get files into docker, what is available inside docker and what is on the host system. That is not something, the rhasspy forum does cover naturally and while we try to help you, you seem to run into the same problem over and over when trying out different approaches to how to play sound from rhasspy.

You have stuff installec on the host system, and your commands work there, but the host system is completely different to the system rhasspy runs inside docker, so naturally everything you try in there doesn’t work if you try it the same way you do on the host system. The host system of course finds “/home/pi/Desktop/demo.wav”, but you can think of a docker container as a completely different linux system, and what you install on the host, or what files you have on the host, just is not available naturally in there. So you have to learn about how docker works and how to get stuff inside docker, about how the paths are different between host system and docker in regards to the profile folder ("/profiles/es" inside docker and “/home/pi/.config/rhasspy/profiles/es” on the host system). Without you having that understanding, there is not much we can help you with on this forum.

1 Like

You could say and only with that would have been enough.

But, all the other you said will appreciate it and take your advice. You’re right, but, up I’ve commented that I’m new on the subject, so I hope it has not been a lot of trouble.

I already solve the problem, I thank everyone for help (@Daenara @romkabouter @synesthesiam). :heart:

1 Like