Bluetooth audio not working with Rhasspy in a docker container

I’ve read a bunch of articles about bluetooth and docker. I still don’t understand what is going on.
When I use a USB headset, everthing works great.
When I connect my Bluetooth headset, from linux cmd line, I can record and play using arecord and aplay. To play on my headset I use: aplay -D bluealsa:DEV=41:42:13:CF:BD:94 t1.wav

When I try to play from with with Rhasspy I get:
AudioServerException: Command ‘[‘aplay’, ‘-q’, ‘-D’, ‘bluealsa:DEV=41:42:13:CF:BD:94’]’ returned non-zero exit status 1.
And in the docker-compose window I get:

rhasspy | [ERROR:2022-07-25 19:55:25,338] rhasspyserver_hermes: AudioPlayError(error=“Command ‘[‘aplay’, ‘-q’, ‘-D’, ‘bluealsa:DEV=41:42:13:CF:BD:94’]’ returned non-zero exit status 1.”, site_id=‘default’, context=‘5d2f63e8-bbc6-4258-a658-54057a3e0fce’, session_id=‘5d2f63e8-bbc6-4258-a658-54057a3e0fce’)
rhasspy | [ERROR:2022-07-25 19:55:25,340] rhasspyserver_hermes: Command ‘[‘aplay’, ‘-q’, ‘-D’, ‘bluealsa:DEV=41:42:13:CF:BD:94’]’ returned non-zero exit status 1.
rhasspy | Traceback (most recent call last):
rhasspy | File “/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/quart/app.py”, line 1821, in full_dispatch_request
rhasspy | result = await self.dispatch_request(request_context)
rhasspy | File “/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/quart/app.py”, line 1869, in dispatch_request
rhasspy | return await handler(**request_.view_args)
rhasspy | File “/usr/lib/rhasspy/rhasspy-server-hermes/rhasspyserver_hermes/main.py”, line 1699, in api_text_to_speech
rhasspy | results = await asyncio.gather(*aws)
rhasspy | File “/usr/lib/rhasspy/rhasspy-server-hermes/rhasspyserver_hermes/main.py”, line 1685, in speak
rhasspy | say_chars_per_second=say_chars_per_second,
rhasspy | File “/usr/lib/rhasspy/rhasspy-server-hermes/rhasspyserver_hermes/init.py”, line 632, in speak_sentence
rhasspy | raise AudioServerException(play_response.error)
rhasspy | rhasspyserver_hermes.AudioServerException: Command ‘[‘aplay’, ‘-q’, ‘-D’, ‘bluealsa:DEV=41:42:13:CF:BD:94’]’ returned non-zero exit status 1.

Did you manage to get it work ?

Yes, I eventually got it to work. Lots of trials and fails, but eventually … it works!
It doesn’t auto-reconnect if I lose connection, but that is not docker related.

Cool! What settings did you use in rhasspy? I’m exactly where you stand at the beginning of the post :slight_smile:

For Audio Recording, I’m using “PyAudio (Recommended)”. All default settings.
For Audio Playing, I’m using: “aplay (Recommended)” with
Device: pulse
Available Devices: shows: PulseAudio Sound Server (pulse)

It was harder to get recording working than playing. Here is the last bit from my notes (quite a while ago)

  • REFERENCE: Set up a Bluetooth Speaker with a Raspberry Pi - OKdo
  • sudo apt update
  • sudo apt full-upgrade -y
  • sudo apt purge bluealsa
  • sudo apt install pulseaudio-module-bluetooth
  • sudo usermod -a -G bluetooth pi
  • sudo reboot now
  • sudo apt autoremove -y
  • sudo apt update
  • sudo apt full-upgrade -y
    • LOTS of services needed restart in this process, YES to all
  • sudo reboot now
  • systemctl --user start pulseaudio
  • NOW I can play wav file using
    • paplay FILENAME

For testing from the cmdline I used:
arecord -D pulse -f S16_LE -d 5 pulse.wav
and
paplay pulse.wav

Thanks a lot, will try this !

I also found this was helpful … the purge and reinstall seemed vital.

Did you get BT working with Rhasspy in a container?
I’m putting together a document to explain the details if it would be useful.