Send wav file over mqtt

I am in the process of switching from a python script that handles my intents from rhasspy, to using home assistant. I have configured rhasspy and home assistant so that rhasspy sends events over to home assistant and I have automations setup to handle those events.

Everything works perfectly fine but I am trying to have home assistant send a wav file to one of the rhasspy satellites via mqtt when the automations run. this way you will hear a sound at the speaker to indicate the task of turning on the light was completed.

In my original setup with the python script, i was accomplishing this by having python run a cmd on the local linux machine (os.system). it was a mosquitto_pub cmd that sent a wav file over to the speaker that made the original request. It looked like his:

mosquitto_pub -p 1883 -t /hermes/audioServer/Bedroom/playBytes/test - f mellow.wav -u XXXXXX -P XXXXXXX  

So I am essentially trying to configure an action in an automation to do that cmd. I use the service MQTT: Publish. set the topic as “/hermes/audioServer/Bedroom/playBytes/test”, set the payload as “mellow.wav” Nothing happens, there is no sound played when the automation triggers.

Reading other topics in this community similar to this one, it was brought up that wav files cant be sent over mqtt. But my mosquitto_pub cmd working makes me think that it can.

I have also tried setting up a shell cmd that would execute the mosquitto_pub cmd. I added the shell cmd to my config file. named it sendwav. I then attempted to have the automation run that shell cmd. again, no sound was played. I changed the shell cmd to simply create a txt file when executed. That worked when the automation triggered. So i assume I set up the shell cmd correctly.

So I have run out of ideas. Has anyone ever tried somethig like this and had success?

Although ingenious from the rhasspy creator, MQTT is really not the proper tool to send K’s and K’s of binary data.

1 Like

Thank you Koying. I guess I will see if I can think of any other way to accomplish this.

Create shell command:

shell_command:
  play_wav_ping: "curl -X POST http://192.168.xxx.xxx:12101/api/play-wav -H 'Content-Type: audio/wav' --data-binary '@/config/www/sound/ping.wav'"

or if you want to change file in your scripts:

  shell_play_wav: "curl -X POST '{{ url }}:12101/api/play-wav' -H 'Content-Type: audio/wav' --data-binary '@/config/www/sound/'{{ name }}'.wav'"

in your scripts put the file name and satellite address.

service: shell_command.shell_play_wav
data:
  name: "ping"
  url: "http://192.168.xxx.xxx"

My satellites are rhasspy mobile (app android) and it works.
I recommend sending small files, just for event notification. I start the ping file before the time is announced.

If i am using MQTT, not the HTTP API for Rhasspy, will this work? If that answer is yes then I think I will have to create a separate automation for each of my satellites since I dont think the IP address is sent over with the event from rhasspy to home assistant. So I would need to hard code it essentially and then somehow identify them when the events come in and match them to the right IP.