Playing audio files on remote machine and use their speakers - not the hosts'

Sorry folks, it's been a while and I seem to be forgetting more than I would like to admit.

I have my RasPi 3 with a Bluetooth speaker connected.
I've tested that and it is working.
I go to it's CLI/Terminal and can play sounds that are heard/played on the bluetooth speaker.

I want Node-Red to play sounds with the node-red-contrib-play-audio node.
It plays the sound out the host's speakers. (This machine)

I am trying to get the watson text to speech to output it's stuff to the bluetooth speaker.
As that works on this machine...... I'd like to get it working on the RasPi.

But when I do a test with just a test "Hello" it is played back on this machine's speakers.

Please....
What do I need to do to get NR to use the bluetooth speakers?

In short: You need to use another node. node-red-contrib-play-audio README clearly states:

play audio

A node to play audio in the browser.

I entered "audio" in the Palette Managers search field ... and it returned about 40 alternatives. Not sure which one fits for you - but there're certainly options!

1 Like

Thanks.

Sorry for asking the dumb question.

I guess I fell into the trap of testing it on this machine and thinking it would work on a remote one.

I'll go looking tomorrow. It is 23:53 here and I think I've had enough for today.

1 Like

I use Google Translate to convert text to sound which is output as an mp3 and converted on the fly to a wav by ffmpeg which pipes it to aplay which can be output to a bluetooth speaker such as an Echo Dot. More information can be found at Pi_2_bleSpeaker .

1 Like

Thanks.

Alas things are going badly here and I haven't been here for a while.

I'll see if I can work out how to do that.

Do look at the link it will explain how to output to a Bluetooth speaker from within node red. However, these days I’m finding getting a successful Bluetooth connection to my Echo Dot is very hit and miss (maybe too far away from raspberry pi), but no issues with my Bluetooth earbuds nearby. I’m using Debian Bullseye on the pi, there was a reason why I avoided Bookworm for now, but I can’t recall why.

If the original is pure text...can't you send that to the RPi via MQTT and then you use the already working flow I assume you have in the RPi

Alas: It is working on my work machine which is not always on.

I want to put the speech node on one which is always on.

So, sorry, the idea can't be done.

Ok, maybe getting off topic.

I have the TTS working.

But now am stuck with how to get the sound playing.

There is the dashboard node audio-out.

It says in the notes that it accepts TTS input.
Which is what I am sending it from the watson TTS node.

I followed (as best I could) the link how to connect a BLE speaker but it isn't that clear.

BUT!

To qualify that:

If I ssh to the machine and do a command to play a sound the sound is played on the BLE speakers.
(Which is wanted)

So that part is working.

Now I'm confused though:

This is the test so far:

Ignore the crossed out nodes.
They are from testing.

So the top part:
I press the inject node and I get the message (debug) as shown.

NOTHING comes out the speaker/s.

The lower two nodes:
(I digress)
I open a shell and type the command and it works.
The sound is played out the BLE speaker.

But if I do it this way - via the exe node: NOTHING.
Confused.

Anyone?

From what you have written my understanding is that you have node red running on a raspberry pi.
As I have already said there may be issues with respect to sound using the latest Bookworm so I have stuck to Bullseye. Perhaps if you using the latest OS then that is where your problems lie. However I have no experience of using Watson TTS.

As shown previously I don't install any new nodes in the pallet, all done with a function node and an exec node which calls programs already installed on the raspberry pi by default. If you are running Buster then the code below should work out of the box. If Bullseye then a little adjustment is required as documented.

image

[{"id":"235f16ee6e459f2c","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"350b59db769ddb8c","type":"inject","z":"235f16ee6e459f2c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Try This","payloadType":"str","x":230,"y":180,"wires":[["22cf2480898ad913"]]},{"id":"22cf2480898ad913","type":"function","z":"235f16ee6e459f2c","name":"TTS","func":"msg.payload = encodeURIComponent(msg.payload.trim());// replace spaces with %20 for url GET REQUEST\nmsg.url = \"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=\" + msg.payload;\nmsg.payload = \"'\" + msg.url + \"'\";// need enclose REQUEST in quotes\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":180,"wires":[["473060c1102377c9"]]},{"id":"473060c1102377c9","type":"exec","z":"235f16ee6e459f2c","command":"ffmpeg -i","addpay":"payload","append":"-f wav - | DISPLAY=:0 aplay ","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":620,"y":180,"wires":[[],[],[]]}]

I am on BUSTER.

From your link you posted:

Making PulseAudio specifically available to Node Red

Create a PulseAudio Configuration File by entering into the Raspberry Pi Terminal:

sudo nano /home/<RPI-username>/.config/pulse/client.conf
Replace <RPI-username> with the actual username for the RPI device. 

In the configuration file in nano add the following lines

autospawn = no

daemon-binary = <default location>

where the <default location> is determined from that viewable in /etc/pulse/client.conf` file. 

Frightening that they say the line:
daemon-binary = <default location>
THEN say where the <default location> is determined from that viewable in /etc/pulse/client.conf file.`

From MY file:

e terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.

## Configuration file for PulseAudio clients. See pulse-client.conf(5) for
## more information. Default values are commented out.  Use either ; or # for
## commenting.

; default-sink =
; default-source =
; default-server =
; default-dbus-server =

; autospawn = yes
; daemon-binary = /usr/bin/pulseaudio
; extra-arguments = --log-target=syslog

; cookie-file =

; enable-shm = yes
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB

; auto-connect-localhost = no
; auto-connect-display = no
pi@TimePi:~ $ 

So I am not sure what I am supposed to put in the file at that point.

I'll look at the flow you posted now.

(early added P.S.)
The RasPi is HEADLESS!

Only for the sake of testing it I tried that flow on THIS machine.

Ok, it doesn't have bluetooth speakers, but it has WIRED speakers.

NOTHING HEARD.

Looking at the outputs of the exec node:

stderr:

ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enab...

return code:
{"code":0}

So I don't get/understand how it is supposed to work.

What I think I need to know at this point:

From a terminal/CLI on the machine I want to use/have TTS working.
Though it is played on the speakers of THIS machine. (THIS machine. The one I use to access NR on the REMOTE machine)
If I enter alias bleep='audacious -pqH ~/Mine/Meep_Meep.mp3' I hear a sound played on the bluetooth speaker.
If I put that in the exec node: NOTHING.
So there is a problem there.

If I use the my flow (as posted above) and use the play audio node (which has been stated will play the sound on the BROWSER'S speakers) I hear the voice.

So I need to get NR to use the device's speakers.
(bluetooth)

Back to that flow I just mentioned
The audio out (default dashboard node)
Yes, I ticked the Play audio when window not in focus. option.

NOTHING is heard.

Firstly if you are using Buster then it should work with a bluetooth speaker without creating the configuration file, at least it did when I was using Buster (assuming there has been no further update changes to Buster). When using Bullseye then you need the configuration file to make Pulseaudio specifically available to Node Red. As you have identified the <default location> is /usr/bin/pulseaudio

You can create the client.conf file by typing into the terminal
sudo nano /home/<RPI-username>/.config/pulse/client.conf
Replacing <RPI-username> with the actual username for the RPI device.

In the nano editor you enter

autospawn = no
daemon-binary = /usr/bin/pulseaudio

exit nano and save the file.

Node Red should be running on the raspberry pi with the client.conf file you have created, and you have to run Pulseaudio using the pulseaudio command.

sudo -u <RPI-username> pulseaudio --start

Replace <RPI-username> with the actual username for the RPI device.

Bluetooth speakers must be connected to RPI.

I am using a PC with VNC to access my Headless raspberry pi. VNC is a much better option than using a Terminal/Command line to control the RPI especially for connecting the blutooth speakers. If I want to hear the audio output on the PC's speaker then I use the node-red-contrib-play-audio node.
image

[{"id":"235f16ee6e459f2c","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"350b59db769ddb8c","type":"inject","z":"235f16ee6e459f2c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Try This","payloadType":"str","x":230,"y":180,"wires":[["22cf2480898ad913"]]},{"id":"22cf2480898ad913","type":"function","z":"235f16ee6e459f2c","name":"TTS","func":"msg.payload = encodeURIComponent(msg.payload.trim());// replace spaces with %20 for url GET REQUEST\nmsg.url = \"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=\" + msg.payload;\nmsg.payload = \"'\" + msg.url + \"'\";// need enclose REQUEST in quotes\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":180,"wires":[["473060c1102377c9","08633f67dff7d4d8"]]},{"id":"473060c1102377c9","type":"exec","z":"235f16ee6e459f2c","command":"ffmpeg -i","addpay":"payload","append":"-f wav - | DISPLAY=:0 aplay ","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":620,"y":180,"wires":[[],[],[]]},{"id":"08633f67dff7d4d8","type":"http request","z":"235f16ee6e459f2c","name":"Download mp3","method":"GET","ret":"bin","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":460,"y":260,"wires":[["04a2ce812f56f1ea"]]},{"id":"04a2ce812f56f1ea","type":"play audio","z":"235f16ee6e459f2c","name":"","voice":"8","x":650,"y":260,"wires":[]}]

Just to reiterate I'm using a PC with VNC to connect to the headless RPI that is running Node Red. The headless RPI is connected via bluetooth to speakers. The Play audio results in audio locally on the PC.

Hope this has been of some help.

1 Like

Slight progress.

(Side note:)
The flow you just posted then is DIFFERENT to the one back in reply 10.

Now I hear "try this" on the PC's speakers and a short time later on the bluetooth speaker.

Sometimes all, sometimes just "this".

(When you post code for this, could you please only post the nodes and not the entire tab/flow?
As much as that is a good idea just now it is painful to handle at this end.)

The only difference is the addition of the Download mp3 (http request node) and the play audio node, so as to facilitate playing of the sound through your PC speakers.

Regarding posting the entire flow, that is the usual way to post code rather than just the nodes. What is the problem that makes it painful to handle at your end? Can I help?

Why you should hear only the end of the message rather than in it's entirety I'm not sure, unless you are losing bluetooth connectivity, or your device is too slow. I'm using a RPI Zero 2W.

If the response time with the Watson TTS is faster on your PC then maybe you can use that with the Exec node in my flow. In my Exec node ffmpeg has to first convert the mp3 stream from the TTS to a wav stream and then pipe it to aplay for output. What format is the output from Watson TTS? It may already be a wav stream in which case perhaps the Exec node could be just
image

[{"id":"ee741d25f011e150","type":"exec","z":"235f16ee6e459f2c","command":"aplay -D pulse","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":640,"y":400,"wires":[[],[],[]]}]

Ok, so to check:

All I need is the flow shown in your last post and it SHOULD play via the Bluetooth speakers - yes?

(Ok, deleted the lower nodes (of bigger flow) and it seems to be working.)

Alas:

MORE TESTING NEEDED.

Sorry, just I say things are working then Sod's law sets in and then it stops working.

The last post is not a flow, the image merely shows where you would put the Watson TTS node in relation to your flows using Watson. I think the Watson TTS outputs a wav stream, so if that is the case the Exec Node (aplay -D pulse) which I provided for download should work with Watson TTS in your flows.

Fingers crossed.

1 Like

Thanks.

I wasn't trying to be difficult. Just things here are a bit messed up just now and I am not tracking things correctly.

(Got woken up last night by the TTS being triggered by a rogue message.)

Thanks, I'll try the new idea and see if I am smart enough to understand what you are saying.

Ah, :frowning: Not good.

Watson sends an array WAV message.
(Not sure this is a correct representation as this is NOT how it is shown in the debug window.)

[82,73,70,70,255,255,255,255,87,65,86,69,102,109,116,32,16,0,0,0,1,0,1,0,34,86,0,0,68,172,0,0,2,0,16,0,76,73,83,84,26,0,0,0,73,78,70,79,73,83,70,84,13,0,0,0,76,97,118,102,54,48,46,51,46,49,48,48,0,0,100,97,116,97,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

So when I put the exec node as you posted after the WATSON node, I get an error.

Regretfully I am unable to help any further. I've failed twice to even install node-red-node-watson! On looking at the IBM website it seems as though all functionality for the node may cease on December 1st anway. Please keep us informed if that should happen. Of course sometimes the date for deprecation is not strictly observed, and it gets removed unexpectedly at a later date.

1 Like

Thanks.

The speaker is not always playing the entire message I am sending it - the one you posted.
(Nothing against you)

I am very new to bluetooth speakers and that sort of stuff.

I grew up with speakers being wired.

It isn't that important to get it working, but it may be nice to have.

I'll keep you in the loop what happens in a few days if it is still working or not.
I did see something - somewhere that the WATSON thing may be ending.
But like so many things these days, I'll wait for it to actually happen.