Connect to Bluetooth
In VNC click Add Device
In the Alexa App select the Echo Dot device and Bluetooth Connections.
Click on Connect a device
In VNC should soon see a new device to add click on it and then on Pair
Should get an indication that pairing successful
Then right click on speaker icon
Click on device to pair
Should get a popup saying connected as an output device.
Connectivity use to be as easy as above, but now PulseAudio (as used by aplay) is not accessible from Node Red, only from the Terminal (as of Bullseye). The solution would be to either make PulseAudio open system wide (not adviseable - though it must have been for it to have worked previously) or make it specifically available to Node Red.
If unable to Make PulseAudio specifically available to Node Red modify /etc/pulse/client.conf file to enable autospawn = yes .This may or may not work!
Making PulseAudio specifically available to Node Red (no longer a guaranteed solution)
Create a PulseAudio Configuration File by entering into the Raspberry Pi Terminal:
cp /etc/pulse/client.conf ~/.config/pulse/client.conf
Open the newly created configuration file in nano text editor
sudo nano ~/.config/pulse/client.conf
Alternatively create the ~/.config/pulse/client.conf file using sudo nano as above then enter
.include /etc/pulse/client.conf
# User's directives go here.
In the configuration file in nano enable and change the following line
autospawn = yes
Exit and save the file. This configuration prevents PulseAudio from starting automatically and ensures it runs with minimal resources.
It is necessary to run PulseAudio for the Node-RED user using the pulseaudio command:
sudo -u <RPI-username> pulseaudio --start
Replace <RPI-username> with the actual username of the Node-RED user.
(It might be important to do start pulseaudio before starting Node Red)
For a Node Red Flow to play an audio file using aplay through PulseAudio using either the Terminal or via the Exec Node command use for e.g.
aplay -D pulse </path/to/audio.wav>
In this command, -D pulse specifies the PulseAudio output device.
Tested with headphones and Amazon Echo over the bluetooth connection to Node Red. (Amazon Echo response unreliable)
Notes
XDG_RUNTIME_DIR=/run/user/1000 pactl info https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/14
sudo nano /etc/pulse/client.conf
uncomment autospawn = yes
Reboot
For a Node Red Flow to play an audio file using aplay through PulseAudio using either the Terminal or via the Exec Node command use for e.g.
aplay -D pulse </path/to/audio.wav>
In this command, -D pulse specifies the PulseAudio output device.
Appending -vv to the command produces a verbose output, which can be from stderr of the Exec node, which I found useful for testing. The command in the Terminal produced sound through my connected Bluetooth headphones, but not when it was issued from the Node red Exec node despite the stderr output showing everything was working without error. Initial solution was to be found in refreshing the connection to the headphones in speaker Device profiles from the Desktop in VNC.
Setting
Pulse Manual sud
pacmd list-sinks | grep 'name:' only lists the one audio device actively connected
If QY7
<bluez_sink.1C_52_16_07_91_EA.a2dp_sink>
If
<bluez_sink.44_00_49_EA_55_7E.a2dp_sink>
pi@piZero2:~ $ bluetoothctl
[bluetoothctl] list
Agent registered
[Echo Dot-WFK]# list
Controller B8:27:EB:B4:99:4D piZero2 [default]
[Echo Dot-WFK]# exit
Set as default
bluetoothctl
#!/bin/bash
pacmd set-default-sink bluez_sink.B8_27_EB_B4_99_4D
pi@piZero2:~ $ sudo apt-get --purge remove -s bluez
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
bluez-firmware
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
bluez* pi-bluetooth* pulseaudio-module-bluetooth*
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
Purg pi-bluetooth [0.1.19]
Purg pulseaudio-module-bluetooth [14.2-2+rpt1]
Purg bluez [5.55-3.1+rpt2]
pi@piZero2:~ $