TTS on Bluetooth speaker via Raspberry Pi

Hi there,

This demo provides the following custom components for Home Assistant, and allows them to place nicely together:

  • Bluetooth tracker (presence detection)
  • Bluetooth speaker (for TTS)

Head over to the GitHub repo, where you can find the relevant files and documentation to get started:

Finally got this working in my setup. I have HA running on a Raspberry Pi, and wanted to use a spare Bluetooth speaker for TTS.

Got some great ideas from this post:

I also used some of the steps from here:

21 Likes

Wow, this is a really useful idea! Would be nice to take advantage of the BT stack in my Pi that’s just sitting there doing nothing.

1 Like

If you try it, let me know how you go. I spent several hours trying to get it all working, and then once I got it working, went back to document the required steps.

Great thing is you can have multiple Bluetooth speakers connected to your HA (i.e. in different areas of the house), and control them all individually (including volume control).

I definitely want to try it, but I’m testing some new code for one of the devs so it may take awhile before I can get to it.

But I’ll post back here when I do! Thanks for sharing it.

Hello @pkozul.
Why are you using service and not deamon option in pulseaudio config?
What is advantage?

Hi @Lapatoc,

No real reason. I’m new to Pulse Audio so I just followed the doco I found.

Are you running it as daemon? If so, where did you put the command to start it?

The advantages of using a service are

  1. You can use the standard systemctl commands to start/stop/restart the service
  2. systemd starts services in parallel, which speeds up boot time.

BTW, my Bluetooth speaker was switched off overnight. I just switched it back on and TTS has continued working with that speaker, so it looks like the Raspberry Pi is smart enough to automatically reconnect, even after the speaker has been switched off.

2 Likes

This is great, thanks for sharing. I have a couple of BT speakers laying around and will give it a try.

What I’d really like to do is have all of HA’s TTS go through my Echo Dot and just get all TTS through that speaker. Does anyone know if you can still use Alexa commands if it’s paired as a speaker?

Hello,

First of all, thanks for sharing!

Can this be used as a “voice confirmation” for example when a light was turned on and off?
with a code something like this: ?

automation:
alias: Sunset Light On
initial_state: True
hide_entity: False
trigger:
platform: sun
event: sunset
action:
service: light.gazebo_light
action 2:
service: tts.google_say
data:
entity_id: media_player.bluetooth_speaker
message: ‘Gazebo light turned on’

Hi @hackertc. I think that’s exactly what this is for. Any time you want something spoken through your speakers, call the tts.google_say service, as you have demonstrated.

I will backup (first find a way to do so) my Pi Card, then I will try your project, i will comeback with a feedback.
Later Edit:

Just trying to get it to work. After finishing all steps i got this error:

General Errors:
- Platform not found: media_player.bluetooth_speaker

@hackertc Which version of HA are you using? I’m on 0.48.0 (latest).

Did you create /home/pi/.homeassistant/custom_components/media_player/bluetooth_speaker.py in the correct folder? Is your HA installed in the same location as mine?

There is some doco here:

Well. i just tried to reproduce the tutorial and get those:

[pulseaudio] server-lookup.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[pulseaudio] main.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[pulseaudio] bluez4-util.c: org.bluez.Manager.GetProperties() failed: org.freedesktop.DBus.Error.UnknownMethod: Method "GetProperties" with signature "" on interface "org.bluez.Manager" doesn't exist

@thundergreen Did those messages appear in a log file? I recall getting some error messages regarding X11 although it still worked. I think they were more like warnings in my case. Have you tried calling the TTS service regardless of this to see if it works?

unfortunaly it is not working no… sometimes it shows playing but rarely and i dont hear anything

still

[pulseaudio] main.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[pulseaudio] bluez4-util.c: org.bluez.Manager.GetProperties() failed: org.freedesktop.DBus.Error.UnknownMethod: Method "GetProperties" with signature "" on interface "org.bluez.Manager" doesn't exist

Might be stating the obvious, but the simplest way for me to test this along the way was using the Developer Tools > Services in the front end:

@thundergreen Do you definitely have Pulse Audio running as a service?

Do you get the following when you run ps aux | grep pulse ?

[email protected]:~ $ ps aux | grep pulse
pulse      446  0.0  0.8 101372  7764 ?        S<sl Jul08   0:03 /usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1
pi       13425  0.0  0.1   4276  1844 pts/1    S+   06:55   0:00 grep --color=auto pulse

@thundergreen Can you try inserting the Bluetooth policy lines into /etc/pulse/system.pa ? The very bottom of the file should then appear as follows:

### Bluetooth Support
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

Reboot and see how you go…