Play Audio instead of TTS

This is my code:

#!/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 == "hello":
    os.system("aplay /home/pi/Desktop/0.mp3")
    print("test-test-test")
    print(intent)

I see that Rhasspy TTS has the option of Local Command, but, do not use it (I do not see any example and I’m a little lost), so I think the most feasible thing is to do it directly on the Python code, or I’m wrong?

The code that I have reproduces the audio from console, but, not in handle.py

Some help?

I wrote a little node express server that should check the incoming text (from TTS) and return a specific wwav-file.
Sadly I don’t know how to retrieve the text.

Would I need to write a python command to get the text and then send it to my server?

Hopefully we’ll get our answers :slight_smile:

Hi Denkmit,
A long time ago, I wrote my first python script to do something similar to what you want (I think). I used the MQTT broker and topics to play specific wav files. Maybe this might help. (forgive the “rough and ready nature” of the script; as I said, first one that I wrote that I actually used!)

Hi Jeff,
Thanks for the quick reply!

I haven’t worked with mqtt or HomeAssistent before. So I’m not sure if I’m overlooking anything.

As far as I can interprete your script you are waiting for a mqqt message “playaudio”, which seems, at least for me, already to late. My own “TTS-server” is on another machine, so I could not play audio there.
What I’m aiming at is translating the received text-content to a specific wav-file and return it to be played at the calling sattelite.

My problem is that i don’t receive the text-content, or don’t know how to.

Maybe I could extend rhasspy’s script where it sends the request to the remote server to include the text-content.
While I’m digging through the code I’m sure I’ll learn something more about mqtt :smiley:

Hi Denkmit,
Just like you, I’m probably overlooking something! :slight_smile: The way I’ve set it up is that I’ve created the following sentences structure in Rhasspy:

Blockquote
[FirePhoton]
fire photon torpedoes
fire torpedoes

In Home Assistant, I’ve written the following “Intent”:

Blockquote
FirePhoton:
action:
- service: mqtt.publish
data:
topic: ha/playaudio
payload: /home/pi/soundeffects/mqttsoundeffects/tos_photon_torpedo_2.wav

Rhasspy sends the “Intent” [FirePhoton] to HA, and HA publishes on the “ha/playaudio” topic on MQTT, with the payload of the directory location and file name of the wav file to be played “/home/pi/soundeffects/mqttsoundeffects/tos_photon_torpedo_2.wav” and the python script is listening on the MQTT broker for the “ha/playaudio” topic, and parses out the payload for the name of the wav file to play via the subprocess call to “aplay”.

I think you could set something similar up (take a look at this setup : Using the Node.js MQTT Client -Starting Guide) by having your Node Express server connect to the MQTT broker and listen on a topic, and when it receives a message on your topic, make an OS call to aplay. I’ve never worked with Node so I’m very sorry I can’t be of more help with giving you some code, but conceptually, I think this should work.
Jeffrey

Sorry for butting in where I am still trying to get my head around how MQTT messages … but …
I don’t see any “playaudio” message in Rhasspy’s list of services. Is this a new service you are writing your own code for ? Or do you perhaps mean to use PlayBytes ?

Hi Don,
They python script I wrote doesn’t rely on Rhasspy, it does a subprocess call to the O/S for aplay (which plays the wav file). I could (and probably) should have used playbytes and Rhasspy, but my script has no overhead on Rhasspy (since it runs independently) so a long wav file doesn’t cause problems (I actually use a modified version to play carols on the hour that run for 30 to 45 seconds during the holidays) and at the time, it worked, so I was happy!
Jeffrey