TTS on Bluetooth speaker via Raspberry Pi

pi@rha:~ $ pactl list short | grep bluez
11 module-bluez5-discover
pi@rha:~ $ bluetoothctl
[bluetooth]# agent on
Agent registration enabled
[bluetooth]# scan on
No default controller available
[bluetooth]#

please help. No sound and cannot play anything.

pi@rha:~ $ pactl list short | grep bluez
11 module-bluez5-discover
13 module-bluez5-device path=/org/bluez/hci0/dev_30_22_00_13_88_59
2 bluez_card.30_22_00_13_88_59 module-bluez5-device.c
pi@rha:~ $ mplayer -ao pulse::bluez_sink.30_22_00_13_88_59 -volume 50 /home/pi/tmp/crowd-excited.mp3
MPlayer 1.3.0 (Debian), built with gcc-6.2.1 © 2000-2016 MPlayer Team

Playing /home/pi/tmp/crowd-excited.mp3.
libavformat version 57.56.101 (external)
Mismatching header version 57.56.100
Audio only file format detected.
Load subtitles in /home/pi/tmp/

Opening audio decoder: [mpg123] MPEG 1.0/2.0/2.5 layers I, II, III
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)
Selected audio codec: [mpg123] afm: mpg123 (MPEG 1.0/2.0/2.5 layers I, II, III)

AO: [pulse] Init failed: No such entity
Failed to initialize audio driver ‘pulse::bluez_sink.30_22_00_13_88_59’
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video

Got it done successfully. my headless rp3 with bluetooth speaker.

after reboot. it wont sink to bluetooth speaker

there is no sound come out from tts.google_say
I can play the music normally through command mplayer.
Please advice.

Thanks for this excellent work, very helpful, all up and running on hassbian 0.60.0, I struggled somewhat with the installation locations filenames but sorted in the end, for those on a learning curve as I am all went well once installed to the directory where you have your .yaml’s for config and so on, a folder created in here for scripts with the file pair_bluetooth.sh and the tts_bluetooth speaker.py also in this directory in these folders for me /home/homeassistant/.homeassistant/custom_components/media_player/ I’m not sure if it helped in my case but also ran the sudo adduser homeassistant pulse-access, ran sudo chmod a+x /home/homeassistant/.homeassistant/scripts/pair_bluetooth.sh, also created a /tmp/tts folder and included this parameter in the config for google tts and tts_bluetooth_speaker in the configuration.yaml as per the guide on HA for tts. I’ve not included any of the device tracker set up for the time being. I also found these useful; https://www.cnet.com/uk/how-to/how-to-setup-bluetooth-on-a-raspberry-pi-3/ and https://www.raspberrypi.org/forums/viewtopic.php?t=53299 for getting the devices paired in the Pi. It’s going to be a bit of a pain identifying when I get to multiple speakers.
I already have a load of notifications from the speaker jack on the Pi (via vlc) that works great and annoys the wife along with Alexa bespoke intents/responses so ill be working on a input_boolean to flick between these speakers and my Bluetooth speaker/s depending where I want the sound. I have speakers all over the house so this Bluetooth is great with the Bluetooth amp they are connected to (turned on via HA and set to Bluetooth via the broadlink IR). WinSCP was great for quick editing. Thanks Again.

2 Likes

may I ask regarding the bluetooth. Did you use the default bluetooth from rp3 or external bluetooth and if you use the default bluetooth of rp3, did you also connect the internet via lan or wifi?

For me, it work great but not automatically connected to the bluetooth once restart rp3. and seem I have to bluetoothctl everytime to see the sink_bluetooth speaker to connect.

Hi

If I recall I spent quite some time on this same issue but got it to connect permanent in the end, Ill see if I can put a post together with the files I changed, it was in the pulse system and default ones and there was a few others with idle times just to be sure. Mine stays connected for good generally but will reconnect if turned on (either pi or speaker). I have file play audio from the 3.5mm jack on omxplayer and Bluetooth vlc, run from shell_command and tts from this script/post on Bluetooth and tts from 3.5 jack on vlc tts. I’ll put something together and post for the disconnection issue as soon as I can with the ones I altered.

Thanks

2 Likes

hy. i tried the guide for enabling TTS via bluetooth, but no matter what I do, pulseaudio service is still failed. I’m using Hassbian

pi@hassbian:~ $ sudo systemctl --system status pulseaudio.service
● pulseaudio.service - Pulse Audio
Loaded: loaded (/etc/systemd/system/pulseaudio.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2018-02-03 18:26:14 EET; 46min ago
Process: 1180 ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1 --daemonize=no (code=exited, status=1/FAILURE)
Main PID: 1180 (code=exited, status=1/FAILURE)

Feb 03 18:26:14 hassbian systemd[1]: Started Pulse Audio.
Feb 03 18:26:14 hassbian pulseaudio[1180]: W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set.
Feb 03 18:26:14 hassbian pulseaudio[1180]: W: [pulseaudio] main.c: OK, so you are running PA in system mode. Please make sure that you actually do want to do that.
Feb 03 18:26:14 hassbian pulseaudio[1180]: W: [pulseaudio] main.c: Please read http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/ for
Feb 03 18:26:14 hassbian pulseaudio[1180]: E: [pulseaudio] main.c: Unknown command: I also had to load in the bluez5 modules in my pulseaudio config (default.pa or system.pa). Here
Feb 03 18:26:14 hassbian pulseaudio[1180]: E: [pulseaudio] main.c: Failed to initialize daemon.
Feb 03 18:26:14 hassbian systemd[1]: pulseaudio.service: Main process exited, code=exited, status=1/FAILURE
Feb 03 18:26:14 hassbian systemd[1]: pulseaudio.service: Unit entered failed state.
Feb 03 18:26:14 hassbian systemd[1]: pulseaudio.service: Failed with result ‘exit-code’.

Hello I am not sure what i am doing wrong i have everything working i believe and my Echo speaker is paired and connected. However i cant get audio playback ive tired volume and pre_silence_duration in the config and did not help. Any ideas? when i grep for bluez i see SUSPENDED… any help guys I would appropriate it ! @pkozul @alandtse

pi@hassbian:~ $  ps aux | grep pulse
pulse      355  0.0  0.9  93680  8864 ?        S<sl 02:16   0:00 /usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1
pi        1113  0.0  0.9 103672  9024 ?        Sl   02:17   0:00 pulseaudio --start
pi        1432  0.0  0.0   4372   540 pts/0    R+   02:33   0:00 grep --color=auto pulse
pi@hassbian:~ $ pactl list short | grep bluez
21      module-bluez5-discover
22      module-bluez5-device    path=/org/bluez/hci0/dev_4C_EF_C0_F1_8C_81
1       bluez_sink.4C_EF_C0_F1_8C_81.a2dp_sink  module-bluez5-device.c  s16le 2ch 44100Hz       SUSPENDED
1       bluez_sink.4C_EF_C0_F1_8C_81.a2dp_sink.monitor  module-bluez5-device.c  s16le 2ch 44100Hz       SUSPENDED
1       bluez_card.4C_EF_C0_F1_8C_81    module-bluez5-device.c

Suspended is normal when not playing. Have you tried running the mplayer command manually? You’ll need to find an actual mp3 on your system.

mplayer -ao pulse::bluez_sink.4C_EF_C0_F1_8C_81.a2dp_sink -quiet -channels 2 -volume 100.0 whatever.mp3

Which should result in this in a succesful run:

MPlayer 1.3.0 (Debian), built with gcc-6.2.1 (C) 2000-2016 MPlayer Team
do_connect: could not connect to socket
connect: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing whatever.mp3.
libavformat version 57.56.101 (external)
Mismatching header version 57.56.100
Audio only file format detected.
Load subtitles in tts/
==========================================================================
Opening audio decoder: [mpg123] MPEG 1.0/2.0/2.5 layers I, II, III
AUDIO: 24000 Hz, 2 ch, s16le, 32.0 kbit/4.17% (ratio: 4000->96000)
Selected audio codec: [mpg123] afm: mpg123 (MPEG 1.0/2.0/2.5 layers I, II, III)
==========================================================================
AO: [pulse] 24000Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...


Exiting... (End of file)

di someone already try to get this running with intel NUC ?

Thanks at this point I’ve abandoned this my TTS Polly service never went through the Bluetooth. Either did the mplayer commands.

What helped me to finally get this working on Raspbian Stretch is this:

  1. Make sure your bluetooth device is paired successfully

  2. Enable a2dp sink in pulse audio

pactl list cards short
0       alsa_card.platform-soc_audio    module-alsa-card.c
1       bluez_card.xx_xx_xx_xx_xx_xx    module-bluez5-device.c

# Grab the card number and enable a2dp sink
pactl set-card-profile 1 a2dp_sink
  1. Set this sink as default
pactl set-default-sink bluez_sink.xx_xx_xx_xx_xx_xx.a2dp_sink
  1. Now address the device with the .a2dp_sink suffix in the bluetooth tts script

Hope it helps someone else.

@oakbrad did you ever get this to work?

1 Like

Any chances for an update? Seems this component relies on HA but there was a breaking change in 0.76

I’m not sure exactly what you want to do with this but you might want to check out the following and see if it meets your needs:

How is it related?
pkozul wrote a great component that uses Bluetooth speakers for tts. It has nothing to do with alexa.

Read the reply from freekeys. They were asking about tts on echo. I might have misunderstood what you were asking about. If I did then ignore my post.

Hi All,

I am nowhere close to getting the Bluetooth speaker added, I just came close to detecting the Bluetooth device in known devices.yaml. I want to use the bluetooth speaker for google home sdk on hassio.

The instructions provided requires a hassbian os, i am directly running my hassio on the raspberry 3 B+. Any addons that can help me with in setting this up ?

Bluetooth device: Zoook Jazz Blaster 30W Bluetooth Speakers (with mic)