How to play WAV File on Satellite

Hi,
i have a master/satellite System with master running headless on Debian/XEN with docker
and 5 Satellites running with raspian on Raspberry 3/4 with docker
I use pulseaudio and pulseaudio client for Sound, so i can run the rhasspy docker image and a squeezelite player simultaneously.
So, that is running perfect, i can hear music - using node-red for Intend handling - mute squeezelite for 8 seconds, if wakeword detected
Also TTS is perfect, i can route to every satellite i want.

But how can i play a stupid wave file on a specific Satellite as result of an Alarm or Timer Event?
I am using MQTT for communication between master and Satellite. so i want to use a MQTT Node in Nodered for play this specific WAV.

tried it with the topic hermes/audioServer/buerovolker/playBytes where buerovolker is my SiteID , but no success.
please give me a Hint.

regards

Try hermes/audioServer/buerovolker/playBytes/test. (so to a subtopic of playBytes)
Don’t know if that is the issue though, but worth a try

Hi - don’t work

try to play with rhasspy-speakers-cli-hermes … but

usr/lib/rhasspy/rhasspy-speakers-cli-hermes/bin/rhasspy-speakers-cli-hermes -h
Traceback (most recent call last):
File “/usr/lib/python3.7/runpy.py”, line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File “/usr/lib/python3.7/runpy.py”, line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File “/usr/lib/python3.7/runpy.py”, line 109, in _get_module_details
import(pkg_name)
File “/usr/lib/rhasspy/rhasspy-speakers-cli-hermes/rhasspyspeakers_cli_hermes/init.py”, line 11, in
import wavchunk
ModuleNotFoundError: No module named ‘wavchunk’

then tried to install wavchunk

pip3 install wavchunk
Collecting wavchunk
Downloading https://files.pythonhosted.org/packages/0c/ab/8cae43190606eb0c0e319e5949c4da83336f8ce2dc53cfd3ccec258e827b/wavchunk-1.0.1.tar.gz
Building wheels for collected packages: wavchunk
Running setup.py bdist_wheel for wavchunk … error
Complete output from command /usr/bin/python3 -u -c “import setuptools, tokenize;file=’/tmp/pip-install-v5e9qbw6/wavchunk/setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” bdist_wheel -d /tmp/pip-wheel-_5ifkrjg --python-tag cp37:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] …]
or: -c --help [cmd1 cmd2 …]
or: -c --help-commands
or: -c cmd --help

error: invalid command ‘bdist_wheel’


Failed building wheel for wavchunk
Running setup.py clean for wavchunk
Failed to build wavchunk
Installing collected packages: wavchunk
Running setup.py install for wavchunk … done
Successfully installed wavchunk-1.0.1
root@voice05:/# /usr/lib/rhasspy/rhasspy-speakers-cli-hermes/bin/rhasspy-speakers-cli-hermes --play-command aplay --debug
Traceback (most recent call last):
File “/usr/lib/python3.7/runpy.py”, line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File “/usr/lib/python3.7/runpy.py”, line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File “/usr/lib/python3.7/runpy.py”, line 109, in _get_module_details
import(pkg_name)
File “/usr/lib/rhasspy/rhasspy-speakers-cli-hermes/rhasspyspeakers_cli_hermes/init.py”, line 12, in
from rhasspyhermes.audioserver import (
ModuleNotFoundError: No module named ‘rhasspyhermes’
root@voice05:/# pip3 install rhasspyhermes
Collecting rhasspyhermes
Could not install packages due to an EnvironmentError: 404 Client Error: Not Found for url: https://pypi.org/simple/rhasspyhermes/

hmm …??

The package itself is called rhasspy-hermes as far as I know, so you might try installing that. But with this many missing dependencies there might be something wrong with your installation. It should have installed those, rhasspyhermes is used by almost every part of rhasspy, if that is not installed, then something went wrong installing.

i installed it as docker container, as described in the Docs

it is the same on an older (2.5.8) docker image on another Raspberry

pi@voice03:~ $ DID=$(docker ps -q)
pi@voice03:~ $ docker exec -it ${DID} /bin/bash
root@voice03:/# /usr/lib/rhasspy/rhasspy-speakers-cli-hermes/bin/rhasspy-speakers-cli-hermes -h
Traceback (most recent call last):
File “/usr/lib/python3.7/runpy.py”, line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File “/usr/lib/python3.7/runpy.py”, line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File “/usr/lib/python3.7/runpy.py”, line 109, in _get_module_details
import(pkg_name)
File “/usr/lib/rhasspy/rhasspy-speakers-cli-hermes/rhasspyspeakers_cli_hermes/init.py”, line 11, in
import wavchunk
ModuleNotFoundError: No module named ‘wavchunk’
root@voice03:/# pip3 install wavchunk
Collecting wavchunk
Downloading https://files.pythonhosted.org/packages/0c/ab/8cae43190606eb0c0e319e5949c4da83336f8ce2dc53cfd3ccec258e827b/wavchunk-1.0.1.tar.gz
Building wheels for collected packages: wavchunk
Running setup.py bdist_wheel for wavchunk … error
Complete output from command /usr/bin/python3 -u -c “import setuptools, tokenize;file=’/tmp/pip-install-c67q3pqx/wavchunk/setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” bdist_wheel -d /tmp/pip-wheel-altlwjag --python-tag cp37:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] …]
or: -c --help [cmd1 cmd2 …]
or: -c --help-commands
or: -c cmd --help

error: invalid command ‘bdist_wheel’


Failed building wheel for wavchunk
Running setup.py clean for wavchunk
Failed to build wavchunk
Installing collected packages: wavchunk
Running setup.py install for wavchunk … done
Successfully installed wavchunk-1.0.1
root@voice03:/# exit
exit

and on another 2.5.9 Raspberry

pi@voice03:~ $ DID=$(docker ps -q)
pi@voice03:~ $ docker exec -it ${DID} /bin/bash
root@voice03:/# /usr/lib/rhasspy/rhasspy-speakers-cli-hermes/bin/rhasspy-speakers-cli-hermes -h
Traceback (most recent call last):
File “/usr/lib/python3.7/runpy.py”, line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File “/usr/lib/python3.7/runpy.py”, line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File “/usr/lib/python3.7/runpy.py”, line 109, in _get_module_details
import(pkg_name)
File “/usr/lib/rhasspy/rhasspy-speakers-cli-hermes/rhasspyspeakers_cli_hermes/init.py”, line 11, in
import wavchunk
ModuleNotFoundError: No module named ‘wavchunk’
root@voice03:/# pip3 install wavchunk
Collecting wavchunk
Downloading https://files.pythonhosted.org/packages/0c/ab/8cae43190606eb0c0e319e5949c4da83336f8ce2dc53cfd3ccec258e827b/wavchunk-1.0.1.tar.gz
Building wheels for collected packages: wavchunk
Running setup.py bdist_wheel for wavchunk … error
Complete output from command /usr/bin/python3 -u -c “import setuptools, tokenize;file=’/tmp/pip-install-c67q3pqx/wavchunk/setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” bdist_wheel -d /tmp/pip-wheel-altlwjag --python-tag cp37:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] …]
or: -c --help [cmd1 cmd2 …]
or: -c --help-commands
or: -c cmd --help

error: invalid command ‘bdist_wheel’


Failed building wheel for wavchunk
Running setup.py clean for wavchunk
Failed to build wavchunk
Installing collected packages: wavchunk
Running setup.py install for wavchunk … done
Successfully installed wavchunk-1.0.1
root@voice03:/# exit
exit

don*t look like an error from me ??

ok … at least get the errors removed with…

(because of faulire). pip3 uninstall wavchunk
pip3 install wheel
pip3 install wavchunk
pip3 install rhasspy-hermes

then … at least the command seems to work :slight_smile:

root@voice05:/# /usr/lib/rhasspy/rhasspy-speakers-cli-hermes/bin/rhasspy-speakers-cli-hermes -h
usage: rhasspy-speakers-cli-hermes [-h] --play-command PLAY_COMMAND
[–list-command LIST_COMMAND]
[–volume VOLUME] [–host HOST]
[–port PORT] [–username USERNAME]
[–password PASSWORD] [–tls]
[–tls-ca-certs TLS_CA_CERTS]
[–tls-certfile TLS_CERTFILE]
[–tls-keyfile TLS_KEYFILE]
[–tls-cert-reqs {CERT_REQUIRED,CERT_OPTIONAL,CERT_NONE}]
[–tls-version TLS_VERSION]
[–tls-ciphers TLS_CIPHERS]
[–site-id SITE_ID] [–debug]
[–log-format LOG_FORMAT]

optional arguments:
-h, --help show this help message and exit
–play-command PLAY_COMMAND
Command to play WAV data from stdin
–list-command LIST_COMMAND
Command to list available output devices
–volume VOLUME Volume scale to apply to all audio
–host HOST MQTT host (default: localhost)
–port PORT MQTT port (default: 1883)
–username USERNAME MQTT username
–password PASSWORD MQTT password
–tls Enable MQTT TLS
–tls-ca-certs TLS_CA_CERTS
MQTT TLS Certificate Authority certificate files
–tls-certfile TLS_CERTFILE
MQTT TLS client certificate file (PEM)
–tls-keyfile TLS_KEYFILE
MQTT TLS client key file (PEM)
–tls-cert-reqs {CERT_REQUIRED,CERT_OPTIONAL,CERT_NONE}
MQTT TLS certificate requirements for broker (default:
CERT_REQUIRED)
–tls-version TLS_VERSION
MQTT TLS version (default: highest)
–tls-ciphers TLS_CIPHERS
MQTT TLS ciphers to use
–site-id SITE_ID Hermes site id(s) to listen for (default: all)
–debug Print DEBUG messages to the console
–log-format LOG_FORMAT
Python logger format
root@voice05:/#

You might want to open up a github issue about the missing dependencies in the docker. That way it will be fixed in the future. The missing wheel wasn’t important, it can still install without it but rhasspy-hermes and wavchunk should be in there.

i have done that right now …

but still not able to get a wave file played with a mqtt message :frowning:

Hi, a real beginner when it comes to programming, but thought I’d throw this out there just in case it help.

# I wrote this script because I wanted my Home Assistant to be able to use my Raspberry Pi to play audio files for MQTT messages
# This script only works with wav files, don't try an mp3 unless you want to hear a lot of static!
# This python script that will connect to the mosquitto eclipse broker used by the Raspberry Pi
# The script listens on the mosquitto topic "ha/playaudio/# and if it receives a message containing the full path to wav file will play that wav file  
# To use this script with Home Assistant, have Home Assistant publish a message on ha/playaudio/ with the path to the wav file as the message
# Here's an example of an automation that will play the Front_Center.wav file located in /usr/share/sounds/alsa/ directory. (part of the standard Raspberry Pi install)
#- id: '6535824662089'
#  alias: Reminder
#  trigger:
#    - at: '09:10:05'
#      platform: time
#  action:
#    - service: mqtt.publish
#      data_template:
#         {
#          "topic": "ha/playaudio/",
#          "payload": "/usr/share/sounds/alsa/Front_Center.wav"
#         }
# Be careful of the spacing when creating automations, Home Assistant is very picky. A copy and paste of the above automation into the automation.yaml should work after all of the "#"'s are removed
# Depending on where you locate this file (I have it in /use/share/) and how you create it, you may need to modify its properties to run it
# Finally, there isn't any santization or checking of the message before it is run.  This can cause bad juju if a nefarious party wanted to try something, so use at your own risk! 
#
#
# !/usr/bin/env python
# encoding: utf-8
from __future__ import print_function #brings the print function from Python 3 into Python 2.6+, only necessary for debugging, and has to be first line in program
import paho.mqtt.client as mqtt #import the client, if you need to install: pip install paho-mqtt
import subprocess

def on_connect(client, userdata, flags, rc):
#  print("Connected with result code " + str(rc)) # for debugging, uncomment to check if connected, should be result code 0
  client.subscribe("ha/playaudio/#")

def on_message(client, userdata, message):
    print("message received " ,str(message.payload.decode("utf-8"))) # for debugging, uncomment to check message
#  print("message topic=",message.topic) # for debugging, uncomment to check topic
#  print("message qos=",message.qos) # for debugging, uncomment to check quality of service
#  print("message retain flag=",message.retain) # for debugging, uncomment to check retained message flag
    wavefile = ''
    wavefile = str(message.payload.decode("utf-8"))
    subprocess.call(['aplay', str(wavefile)])

client = mqtt.Client() 
client.on_connect = on_connect
client.on_message = on_message
client.connect("localhost", 1883, 60) 
client.loop_forever()

thx,
but now i did it with the API and a “http request” Node
looks like that ->

  • take the SiteId to choose the right URL as msg.payload
  • add the msg.header object with “type audio/wav” and set msg.url from payload
  • choose the WAV and send it to the request Node

voilla -> it rings

works perfect

hello volkerg,
could you please share your node-red nodes ?
thx

Don’t know if that will help you, but here it is …

[
{
“id”: “4fc4a3b8.096dac”,
“type”: “inject”,
“z”: “6ef0842d.364594”,
“name”: “”,
“topic”: “”,
“payload”: “buerovolker”,
“payloadType”: “str”,
“repeat”: “”,
“crontab”: “”,
“once”: false,
“onceDelay”: 0.1,
“x”: 310,
“y”: 880,
“wires”: [
[
“b5045bb3.dae9d”
]
]
},
{
“id”: “91f0f52c.a641e”,
“type”: “http request”,
“z”: “6ef0842d.364594”,
“name”: “API-PlaySound”,
“method”: “POST”,
“ret”: “txt”,
“paytoqs”: false,
“url”: “”,
“tls”: “”,
“persist”: false,
“proxy”: “”,
“authType”: “”,
“x”: 1300,
“y”: 760,
“wires”: [
[
“99bcff.f2d9f3”
]
],
“info”: “http://voice05:12101/api/play-wav
},
{
“id”: “99bcff.f2d9f3”,
“type”: “debug”,
“z”: “6ef0842d.364594”,
“name”: “”,
“active”: true,
“tosidebar”: true,
“console”: false,
“tostatus”: false,
“complete”: “true”,
“targetType”: “full”,
“x”: 1470,
“y”: 760,
“wires”: []
},
{
“id”: “fc5330e6.cb3e68”,
“type”: “file in”,
“z”: “6ef0842d.364594”,
“name”: “”,
“filename”: “/home/pi/wav/service-bell.wav”,
“format”: “”,
“chunk”: false,
“sendError”: false,
“encoding”: “none”,
“x”: 1050,
“y”: 760,
“wires”: [
[
“91f0f52c.a641e”
]
]
},
{
“id”: “5900f128.67e92”,
“type”: “function”,
“z”: “6ef0842d.364594”,
“name”: “add_headers_url”,
“func”: “msg.headers = {};\nmsg.url = “”;\nmsg.url = msg.payload;\nmsg.headers[‘content-type’] = ‘audio/wav’;\nreturn msg;”,
“outputs”: 1,
“noerr”: 0,
“x”: 790,
“y”: 760,
“wires”: [
[
“fc5330e6.cb3e68”
]
]
},
{
“id”: “b5045bb3.dae9d”,
“type”: “change”,
“z”: “6ef0842d.364594”,
“name”: “”,
“rules”: [
{
“t”: “change”,
“p”: “payload”,
“pt”: “msg”,
“from”: “buerovolker”,
“fromt”: “str”,
“to”: “http://voice05:12101/api/play-wav”,
“tot”: “str”
},
{
“t”: “change”,
“p”: “payload”,
“pt”: “msg”,
“from”: “wohnzimmer”,
“fromt”: “str”,
“to”: “http://voice03:12101/api/play-wav”,
“tot”: “str”
},
{
“t”: “change”,
“p”: “payload”,
“pt”: “msg”,
“from”: “schlafzimmer”,
“fromt”: “str”,
“to”: “http://voice02:12101/api/play-wav”,
“tot”: “str”
}
],
“action”: “”,
“property”: “”,
“from”: “”,
“to”: “”,
“reg”: false,
“x”: 540,
“y”: 760,
“wires”: [
[
“5900f128.67e92”
]
]
},
{
“id”: “40361834.b1a63”,
“type”: “link in”,
“z”: “6ef0842d.364594”,
“name”: “Link_alarm”,
“links”: [
“d26edfcd.cfd8”
],
“x”: 355,
“y”: 720,
“wires”: [
[
“b5045bb3.dae9d”
]
]
}
]

Thank you, but can´t import this.

It says “SyntaxError: Unexpected token “ in JSON at position 4”

might be a copy/paste problem

[
{
“id”: “4fc4a3b8.096dac”,
“type”: “inject”,
“z”: “6ef0842d.364594”,
“name”: “”,
“topic”: “”,
“payload”: “buerovolker”,
“payloadType”: “str”,
“repeat”: “”,
“crontab”: “”,
“once”: false,
“onceDelay”: 0.1,
“x”: 490,
“y”: 840,
“wires”: [
[
“b5045bb3.dae9d”
]
]
},
{
“id”: “91f0f52c.a641e”,
“type”: “http request”,
“z”: “6ef0842d.364594”,
“name”: “API-PlaySound”,
“method”: “POST”,
“ret”: “txt”,
“paytoqs”: false,
“url”: “”,
“tls”: “”,
“persist”: false,
“proxy”: “”,
“authType”: “”,
“x”: 1300,
“y”: 760,
“wires”: [
[
“99bcff.f2d9f3”
]
],
“info”: “http://voice05:12101/api/play-wav
},
{
“id”: “99bcff.f2d9f3”,
“type”: “debug”,
“z”: “6ef0842d.364594”,
“name”: “”,
“active”: true,
“tosidebar”: true,
“console”: false,
“tostatus”: false,
“complete”: “true”,
“targetType”: “full”,
“x”: 1470,
“y”: 760,
“wires”: []
},
{
“id”: “fc5330e6.cb3e68”,
“type”: “file in”,
“z”: “6ef0842d.364594”,
“name”: “”,
“filename”: “/home/pi/wav/service-bell.wav”,
“format”: “”,
“chunk”: false,
“sendError”: false,
“encoding”: “none”,
“x”: 1050,
“y”: 760,
“wires”: [
[
“91f0f52c.a641e”
]
]
},
{
“id”: “5900f128.67e92”,
“type”: “function”,
“z”: “6ef0842d.364594”,
“name”: “add_headers_url”,
“func”: “msg.headers = {};\nmsg.url = “”;\nmsg.url = msg.payload;\nmsg.headers[‘content-type’] = ‘audio/wav’;\nreturn msg;”,
“outputs”: 1,
“noerr”: 0,
“x”: 790,
“y”: 760,
“wires”: [
[
“fc5330e6.cb3e68”
]
]
},
{
“id”: “b5045bb3.dae9d”,
“type”: “change”,
“z”: “6ef0842d.364594”,
“name”: “”,
“rules”: [
{
“t”: “change”,
“p”: “payload”,
“pt”: “msg”,
“from”: “buerovolker”,
“fromt”: “str”,
“to”: “http://voice05:12101/api/play-wav”,
“tot”: “str”
},
{
“t”: “change”,
“p”: “payload”,
“pt”: “msg”,
“from”: “wohnzimmer”,
“fromt”: “str”,
“to”: “http://voice03:12101/api/play-wav”,
“tot”: “str”
},
{
“t”: “change”,
“p”: “payload”,
“pt”: “msg”,
“from”: “schlafzimmer”,
“fromt”: “str”,
“to”: “http://voice02:12101/api/play-wav”,
“tot”: “str”
}
],
“action”: “”,
“property”: “”,
“from”: “”,
“to”: “”,
“reg”: false,
“x”: 540,
“y”: 760,
“wires”: [
[
“5900f128.67e92”
]
]
}
]

Sorry, same as before. Can you post code in preformatted text?
image

It is the “” that is the problem, they are changed when not using code blocks (from "" to “”)