TTS on Bluetooth speaker via Raspberry Pi

Right.

I haven’t even tested anything lower than 0.5. I happy with that :slight_smile:

What’s interesting is that setting 0.1 seconds for both pre silence, and post silence, does the job for me. It’s as if the simple existence of a split second of brown noise is enough for my Bluetooth speaker to play the complete TTS file.

Just to reproduce the original issue, I removed the pre silence and post silence and the problem returned - the first part of the file was not being played by the Bluetooth speaker.

Been an interesting adventure with trial and error. At least we have a solution now. It’s a bit of a hack, but it does the job.

1 Like

Would you mind helping me (linux noob) on how to get that part working, I am also trying to use me echo as a bluetooth client for my pi, so currently i can pair and have pulse audio going so;

pactl list cards short
0 alsa_card.platform-soc_audio module-alsa-card.c
2 bluez_card.34_D2_70_7F_D4_F5 module-bluez5-device.c

and then doing:

pactl set-card-profile 2 a2dp
Failure: Input/Output error

First of all, thanks for sharing this!!

I had it working perfectly yesterday, with sound being player through my LaMetric from Home Assistant, which was awesome. I did, though, have to pair the device manually with bluetoothctl.

Today I rebooted and I paired, but I cant get any sounds working.

Pulse is running as a service and the device is paired:

pi@hassbian:/ $ ps aux | grep pulse
pulse      401  0.0  0.8 100352  7680 ?        S<sl 21:19   0:00 /usr/bin/pulseaudio --
system --disallow-exit --disable-shm --exit-idle-time=-1
pi        5896  0.0  0.2   4280  1904 pts/0    S+   21:32   0:00 grep --color=auto pulse
pi@hassbian:/ $ pactl list short | grep bluez
11	module-bluez5-discover		
12	module-bluez4-discover		
13	module-bluez5-device	path=/org/bluez/hci0/dev_A0_2C_36_83_3C_4F	
1	bluez_source.A0_2C_36_83_3C_4F	module-bluez5-device.c	s16le 2ch 44100Hz	
SUSPENDED
1	bluez_card.A0_2C_36_83_3C_4F	module-bluez5-device.c

When I try to play an mp3, this error occurs:

pi@hassbian:/tmp $ mplayer -ao pulse::bluez_sink.A0_2C_36_83_3C_4F  crowd.mp3
MPlayer2 2.0-728-g2c378c7-4+b1 (C) 2000-2012 MPlayer Team
Cannot open file '/home/pi/.mplayer/input.conf': No such file or directory
Failed to open /home/pi/.mplayer/input.conf.
Cannot open file '/etc/mplayer/input.conf': No such file or directory
Failed to open /etc/mplayer/input.conf.

Playing crowd.mp3.
Detected file format: MP2/3 (MPEG audio layer 2/3) (libavformat)
[mp3 @ 0x75bff5b8]max_analyze_duration 5000000 reached
[mp3 @ 0x75bff5b8]Estimating duration from bitrate, this may be inaccurate
[lavf] stream 0: audio (mp3), -aid 0
Load subtitles in .
Selected audio codec: MPEG 1.0/2.0/2.5 layers I, II, III [mpg123]
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)
AO: [pulse] Init failed: No such entity
Failed to initialize audio driver 'pulse::bluez_sink.A0_2C_36_83_3C_4F'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video


Exiting... (End of file)

Any idea what could be the problem? :slight_smile:

Hmm I have followed the instructions here and have got the media_player.tts_bluetooth_speaker in HA. However I’m not getting any sound.

Trying the mplayer command here, it appears I do not have a bluez sink

mplayer -ao pulse::bluez_sink.AC_63_BE_1D_BA_EF  nature_night_swamp_3hr.mp3
MPlayer2 2.0-728-g2c378c7-4+b1 (C) 2000-2012 MPlayer Team
Cannot open file '/home/pi/.mplayer/input.conf': No such file or directory
Failed to open /home/pi/.mplayer/input.conf.
Cannot open file '/etc/mplayer/input.conf': No such file or directory
Failed to open /etc/mplayer/input.conf.

Playing nature_night_swamp_3hr.mp3.
Detected file format: MP2/3 (MPEG audio layer 2/3) (libavformat)
[mp3 @ 0x75b375b8]max_analyze_duration 5000000 reached
[mp3 @ 0x75b375b8]Estimating duration from bitrate, this may be inaccurate
[lavf] stream 0: audio (mp3), -aid 0
Clip info:
 major_brand: dash
 minor_version: 0
 compatible_brands: iso6mp41
 encoder: Lavf57.19.100
Load subtitles in .
Selected audio codec: MPEG 1.0/2.0/2.5 layers I, II, III [mpg123]
AUDIO: 44100 Hz, 2 ch, s16le, 192.0 kbit/13.61% (ratio: 24000->176400)
AO: [pulse] Init failed: No such entity
Failed to initialize audio driver 'pulse::bluez_sink.AC_63_BE_1D_BA_EF'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video

Checking the status of pulse audio I see some errors:

sudo systemctl status pulseaudio.service
● pulseaudio.service - Pulse Audio
   Loaded: loaded (/etc/systemd/system/pulseaudio.service; enabled)
   Active: active (running) since Sun 2017-07-23 13:42:40 PDT; 21min ago
 Main PID: 459 (pulseaudio)
   CGroup: /system.slice/pulseaudio.service
           └─459 /usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1

Jul 23 13:42:40 homeassistant systemd[1]: Started Pulse Audio.
Jul 23 13:42:41 homeassistant pulseaudio[459]: W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set!
Jul 23 13:42:41 homeassistant pulseaudio[459]: W: [pulseaudio] main.c: OK, so you are running PA in system mode. Please note that you most likely shouldn't be doing that.
Jul 23 13:42:41 homeassistant pulseaudio[459]: W: [pulseaudio] main.c: If you do it nonetheless then it's your own fault if things don't work as expected.
Jul 23 13:42:41 homeassistant pulseaudio[459]: W: [pulseaudio] main.c: Please read http://pulseaudio.org/wiki/WhatIsWrongWithSystemMode for an explanation why system mode is usually a bad idea.
Jul 23 13:42:41 homeassistant pulseaudio[459]: W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.config/pulse/cookie': No such file or directory
Jul 23 13:42:41 homeassistant pulseaudio[459]: W: [pulseaudio] authkey.c: Failed to load authorization key '/var/run/pulse/.config/pulse/cookie': No such file or directory
Jul 23 13:42:41 homeassistant pulseaudio[459]: W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.pulse-cookie': No such file or directory
Jul 23 13:42:41 homeassistant pulseaudio[459]: W: [pulseaudio] authkey.c: Failed to load authorization key '/var/run/pulse/.pulse-cookie': No such file or directory
Jul 23 13:42:46 homeassistant pulseaudio[459]: E: [pulseaudio] bluez4-util.c: org.bluez.Manager.GetProperties() failed: org.freedesktop.DBus.Error.UnknownMethod: Method "GetProperties" with signature... doesn't exist
Jul 23 13:42:46 homeassistant pulseaudio[459]: E: [pulseaudio] bluez5-util.c: Found duplicated D-Bus path for device /org/bluez/hci0
Jul 23 13:42:46 homeassistant pulseaudio[459]: E: [pulseaudio] bluez5-util.c: Found duplicated D-Bus path for device /org/bluez/hci0/dev_AC_63_BE_1D_BA_EF
Jul 23 13:42:46 homeassistant pulseaudio[459]: E: [pulseaudio] bluez4-util.c: org.bluez.Manager.GetProperties() failed: org.freedesktop.DBus.Error.UnknownMethod: Method "GetProperties" with signature... doesn't exist
Jul 23 13:43:08 homeassistant pulseaudio[459]: W: [pulseaudio] module-bluez5-device.c: Profile has no transport
Jul 23 13:59:27 homeassistant systemd[1]: Started Pulse Audio.
Hint: Some lines were ellipsized, use -l to show in full.

My Pi is definitely connect to the BT speaker, so that is working. Any advice?

I’ve recently upgraded to 0.49.1 and can’t for the life of me figure out how I could install this.
I often used SSH but that is pretty much useless now for me.

I’ve looked into trying to create an addon but I feel that I don’t have the skills to achieve what I want.

Any advice would be great.

Ok, I’ve got the bluetooth speaker working with the Pi - can play MP3s fine with mplayer. However, I can’t get HASS to play anything. The {“entity_id”:“media_player.tts_bluetooth_speaker”,“message”:“Hello”} test produces no sound.

I have this in my configuration.yaml
media_player:

  • platform: tts_bluetooth_speaker
    address: 00:0D:44:BC:7A:7E # Required - for example, 00:2F:AD:12:0D:42
    volume: 0.45 # Optional - default is 0.5

When I look at states under developer tools, I see:

media_player.tts_bluetooth_speaker
state: off
Attributes:friendly_name: TTS Bluetooth Speaker
supported_features: 516

Bluetooth info:
[bluetooth]# info 00:0D:44:BC:7A:7E
Device 00:0D:44:BC:7A:7E
Name: Logitech Boombox
Alias: Logitech Boombox
Class: 0x240414
Icon: audio-card
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
UUID: Vendor specific (4e5176c5-98a7-3dca-62d7-cdb2b6803bd6)

Should the state be on? Any ideas why this isn’t working?

Thanks!

@pkozul -

The error I’m seeing in the log is:

2017-07-31 01:04:23 ERROR (MainThread) [homeassistant.core] Invalid service data for tts.google_say: Entity ID media_player is an invalid entity id for dictionary value @ data[‘entity_id’]. Got ‘media_player’

This might be from when I called tts/google_say with:
{“entity_id”:"media_player, “message”:“Hello”}

But it doesn’t work with this either:
{“entity_id”:“media_player.tts_bluetooth_speaker”, “message”:“Hello”}

Any ideas?

Thanks!

If I have two raspberry Pi 3 (bedroom and lounge) each connected to a Bluetooth speaker. Can I send an announcement to both bluetooth speakers simultaneously? If so how can I accomplish this?

Supposedly doing something like this for the tts/google_say action
{“entity_id”:“media_player”,“message”:“Hello”}

Should go to all media players - but I haven’t gotten it to work at all yet.

@oakbrad - did you ever figure this out? I’m in the same boat - can use mplayer to play MP3 to the bluetooth speaker, but can’t get the TTS service to play to it.

Hey, followed all instructions including additional mentions in this thread, everything went well to my knowledge, but the media_player is NOT showing up under devices.

media_players.yaml =
- platform: tts_bluetooth_speaker
name: Echo Dot
address: 44:65:0D:64:DC:90
volume: 1.0
pre_silence_duration: 0.1
post_silence_duration: 0.1
cache_dir: /tts

Never mind the formatting, Preformatted Text doesn’t seem to apply.

And bluetooth seems to be connected, I also get the voice confirmation when connected.
Capture

Error Log =
Unable to find service media_player/play_media

EDIT:
chmod: changing permissions of ‘/home/homeassistant/.homeassistant/scripts/pair_bluetooth.sh’: Operation not permitted

Any chance of this being made into an app for Hass.io?

3 Likes

Hi pkozul,

Great work!!, It is working for me really well. As an interesting note it shows as a Bluetooth tracker on the front end, also if your Bluetooth device is not being used for a while, eventually it will turn off.
Thanks!

I gave this a try but it didn’t work reliably. It was hit and miss. I believe using Bluetooth transmitter such as this one…

http://amzn.to/2wHMidq

…is more reliable and easier.

1 Like

I can’t get pulseaudio to install. I keep getting this error.

pi@hassbian:~ $ sudo apt-get install pulseaudio pulseaudio-module-bluetooth bluez mplayer sox libsox-fmt-mp3
Reading package lists… Done
Building dependency tree
Reading state information… Done
Note, selecting ‘mplayer2’ instead of ‘mplayer’
pulseaudio is already the newest version.
bluez is already the newest version.
bluez set to manually installed.
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
pulseaudio-module-bluetooth : Depends: libpulse0 (= 5.0-13) but 7.1-2~bpo8+1 is to be installed
Depends: pulseaudio (= 5.0-13) but 7.1-2~bpo8+1 is to be installed
E: Unable to correct problems, you have held broken packages.

The first thing to try is to make sure you have the latest list of packages, and have the packages from that list installed.

sudo apt-get update
sudo apt-get upgrade

Then try installing what you need again.

I tried that but I’m still getting

Failed to connect: org.bluez.Error.Failed

when I try to connect to the speaker

UPDATE: So I found out that the Jesse Backports was missing some keys. Got them added, updated and now the speaker connects. One thing though is I’m not getting any sound coming out of it when I call it in the services.

UPDATE 2: So I still can’t get any sound out of the speaker. I’ve tried two different bluetooth speakers just to make sure. I can get my fire tv to speak using the tts. I’m starting to think the issue might be pulseaudio. When I run pulseaudio --start I get this back.

pi@hassbian:~ $ pulseaudio --start
E: [pulseaudio] main.c: Daemon startup failed.

How do you do that? I have to manually hit pulseaudio --start for it to connect to any device .

@JuliusLedoux

Can you please post the instructions on how you got it working?

I cannot pair my speaker until I hit pulseaudio --start manually. Even after doing that I cannot play and song from my pi it gives me errors.

Thanks