@jruben4 and @oakbrad did you ever figure it out? I have the same problem:
pi@hassbian:~ $ mplayer -ao pulse::bluez_sink.68_37_E9_91_15_DD -volume 50 /tmp/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 /tmp/crowd.mp3.
Detected file format: MP2/3 (MPEG audio layer 2/3) (libavformat)
[mp3 @ 0x75be15b8]max_analyze_duration 5000000 reached
[mp3 @ 0x75be15b8]Estimating duration from bitrate, this may be inaccurate
[lavf] stream 0: audio (mp3), -aid 0
Load subtitles in /tmp/
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.68_37_E9_91_15_DD'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video
@eiolos Nope I never could get the notification to work through a bluetooth speaker. I could get it to play audio via mplayer but not through the TTS notification.
@pkozul thanks a lot for the post! really helpful. just wondering if there is a way to install pulseaudio for Hass.io? Iām really new to HA and raspberry pi and cant really tell the difference between hassio and hassbian. I installed hassio for my machine since its easier to set up. thanks much!
Hi,
Iām trying to run tts_bluetooth_speaker.
2017-09-25 03:53:23 ERROR (MainThread) [homeassistant.loader] Unable to find component media_player.tts_ bluetooth_speaker
return this message.
my tts_bluetooth_speaker.py is at /home/homeassistant/.homeassistant/custom_components/media_player
Any suggestion?
should it go somewhere else?
After much finagling, I can get mplayer to manually play the mp3 generated in /tmp/tts but itās still not happening automatically.
The Logbook shows the bluetooth tracker going off and then on, but thereās now mention of trying to play the file in between or otherwise.
Systemctl status check on HA shows:
AO: [pulse] Init failed: Access denied
Failed to initialize audio driver 'pulse::bluez_sink.FC_58_FA_D0_1C_CA'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video
Exiting... (End of file)
pactl stat shows:
Default Sink: bluez_sink.FC_58_FA_D0_1C_CA
When I try to run pacmd commands I get:
No PulseAudio daemon running, or not running as session daemon.
syslog has:
hassbian pulseaudio[423]: W: [pulseaudio] protocol-native.c: Denied access to client with invalid authorization data.
Added homeassistant to audio group (was using pi). Voila!
You did a absolute great work. I had no problem with your solution on raspbian jessi. Only the bcm chip bug ( Bluetooth audio stutters when using internal WiFi and Bluetooth) on the pi3 sucks a bit. I found a info in the relnotes of stretch that the problem is fixed, so I did upgrade to stretch. Now the pairing wonāt work automatically and hass donāt push the tts to the Bluetooth speaker. It looks like there is a conflict with pulseaudio and the new included bluezalsa. Can you check what I have to change in your code to use bluezalsa.
Ok a little confusion. Currently have a raspberry pi running mpd via the connected through the 3,5 jack speakers.
Want to add a bluetooth TTS. But iām confused. Pulse will become the default audio device so mpd will play through the 3,5 jack and bluetooth at the same time? Ot it is possible to let MPD continue playing through the jack and the announcements to go through the bluetooth?
I wound up running into the issue where mplayer spawned by hass would fail with the following, but the manually run command would work:
MPlayer 1.3.0-7 (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 /tmp/tts_c913a0cada7c35997625389957af03316efe6334_en_-_google.mp3.
libavformat version 57.71.100 (external)
Audio only file format detected.
Load subtitles in /tmp/
==========================================================================
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] Init failed: No such entity
Failed to initialize audio driver 'pulse::bluez_sink.< bluetooth address >'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video
Exiting... (End of file)
āpactl list sinksā showed the device name as ābluez_sink.< bluetooth address >.a2dp_sinkā, so I worked around this by simply adding ā.a2dp_sinkā to the address in the configuration file.
- platform: tts_bluetooth_speaker
address: < bluetooth address >.a2dp_sink
volume: 0.45
pre_silence_duration: 1 # Optional - No. of seconds silence before the TTS (default is 0)
post_silence_duration: 0.5 # Optional - No. of seconds silence after the TTS (default is 0)
cache_dir: /home/homeassistant/.homeassistant/tts # Optional - make sure it matches the same setting in TTS config
I realize this is an older post, but I ran into the same problem with my paired Echo where it suddenly stopped playing after working for a couple of weeks. I havenāt figured out how to fix it but thought Iād post in case someone else runs into the same issue.
Essentially what has happened is the speaker is now being identified as a source (input) and not a sink (output). Therefore mplayer canāt play to it.
In my case, whenever I previously connected to my Echo, only the bluez_card would show (i.e., no sources or sinks). I could enable a sink by āpactl set-card-profile [index] a2dpā. Now, when I try to change the profile to a2dp I get a āFailure: Input/Output errorā and a pulseaudio log of āmodule-bluez5-device.c: Refused to switch profile to a2dp: Not connectedā
For the failing Echo case, it appears after connecting it is defaulting to a2dp_source which does not create a sink and effectively pipes the Echo speakers to the RPi (instead of the other way). Thus the Echo wonāt respond to voice command as itās piping its output to the RPiās input. Here is a link where I found it reported without a solution beyond buying a bluetooth dongle.
For those that it helps, I downgraded my pulseaudio to the 7.1 in jesse-backports and can now access my Amazon Echo again as a sink. Apparently when I updated my RPi to stretch it moved me up to 10.0.
EDIT: So I did a little more testing and itās not related to the version. Iām now back to pulseaudio in stretch and got it working. Apparently, it makes a difference on how you connect to the Echo. I found that if you ever use the Alexa app to connect to the RaspberryPi using a dongle or the native bluetooth, it will result in the a2dp_source behavior. However, if you only connect from the RPI using bluetoothctl only, then it results in the a2dp_sink being available.
Would be awesome to have it as a wakeup-light with colors and also have some tts or some other tune
Edit: I tested with a bluetooth headset (Sony SBH20), then your adress in HA-conf need to be address: 00:2F:AD:12:0D:42.headset_head_unit, can be fixed in code but seems unnecessary.
Can be found with below, then you just test the sinkās and chose one. pactl list short | grep bluez
the test: mplayer -ao pulse::bluez_sink.00_2F_AD_12_0D_42.headset_head_unit sometest.mp3
Dec 16 12:38:11 hassbian hass[1203]: 2017-12-16 12:38:11 INFO (Thread-9) [custom_components.media_player.tts_bluetooth_speaker] play_media: http://192.168.0.119:8123/api/tts_proxy/7d385d128cc4a59fa5ddb0211327c11b3f70f113_zh_-_baidu.mp3
Dec 16 12:38:11 hassbian hass[1203]: MPlayer 1.3.0 (Debian), built with gcc-6.2.1 (C) 2000-2016 MPlayer Team
Dec 16 12:38:11 hassbian hass[1203]: do_connect: could not connect to socket
Dec 16 12:38:11 hassbian hass[1203]: connect: No such file or directory
Dec 16 12:38:11 hassbian hass[1203]: Failed to open LIRC support. You will not be able to use your remote control.
Dec 16 12:38:11 hassbian hass[1203]: Terminal type `unknownā is not defined.
Dec 16 12:38:11 hassbian hass[1203]: Playing /home/homeassistant/.homeassistant/tts/7d385d128cc4a59fa5ddb0211327c11b3f70f113_zh_-_baidu.mp3.
Dec 16 12:38:11 hassbian hass[1203]: libavformat version 57.56.101 (external)
Dec 16 12:38:11 hassbian hass[1203]: Mismatching header version 57.56.100
Dec 16 12:38:11 hassbian hass[1203]: Audio only file format detected.
Dec 16 12:38:11 hassbian hass[1203]: Load subtitles in /home/homeassistant/.homeassistant/tts/
Dec 16 12:38:11 hassbian hass[1203]: ==========================================================================
Dec 16 12:38:11 hassbian hass[1203]: Opening audio decoder: [mpg123] MPEG 1.0/2.0/2.5 layers I, II, III
Dec 16 12:38:11 hassbian hass[1203]: AUDIO: 16000 Hz, 2 ch, s16le, 16.0 kbit/3.12% (ratio: 2000->64000)
Dec 16 12:38:11 hassbian hass[1203]: Selected audio codec: [mpg123] afm: mpg123 (MPEG 1.0/2.0/2.5 layers I, II, III)
Dec 16 12:38:11 hassbian hass[1203]: ==========================================================================
Dec 16 12:38:11 hassbian hass[1203]: AO: [pulse] Init failed: No such entity
Dec 16 12:38:11 hassbian hass[1203]: Failed to initialize audio driver āpulse::bluez_sink.96_13_5A_00_4E_1B.a2dp_sinkā
Dec 16 12:38:11 hassbian hass[1203]: Could not open/initialize audio device ā no sound.
Dec 16 12:38:11 hassbian hass[1203]: Audio: no sound
Dec 16 12:38:11 hassbian hass[1203]: Video: no video
Dec 16 12:38:11 hassbian hass[1203]: Exitingā¦ (End of file)
ā pulseaudio.service - Pulse Audio
Loaded: loaded (/etc/systemd/system/pulseaudio.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2017-12-21 20:52:00 +07; 4min 28s ago
Main PID: 342 (pulseaudio)
CGroup: /system.slice/pulseaudio.service
āā342 /usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1
Dec 21 20:52:01 rha pulseaudio[342]: W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set.
Dec 21 20:52:01 rha pulseaudio[342]: W: [pulseaudio] main.c: OK, so you are running PA in system mode. Please make sure that you actually do want to do that.
Dec 21 20:52:01 rha pulseaudio[342]: W: [pulseaudio] main.c: Please read http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/
Dec 21 20:52:01 rha pulseaudio[342]: W: [pulseaudio] authkey.c: Failed to open cookie file ā/var/run/pulse/.config/pulse/cookieā: No such file or directory
Dec 21 20:52:01 rha pulseaudio[342]: W: [pulseaudio] authkey.c: Failed to load authentication key ā/var/run/pulse/.config/pulse/cookieā: No such file or directory
Dec 21 20:52:01 rha pulseaudio[342]: W: [pulseaudio] authkey.c: Failed to open cookie file ā/var/run/pulse/.pulse-cookieā: No such file or directory
Dec 21 20:52:01 rha pulseaudio[342]: W: [pulseaudio] authkey.c: Failed to load authentication key ā/var/run/pulse/.pulse-cookieā: No such file or directory
Dec 21 20:52:01 rha pulseaudio[342]: E: [pulseaudio] main.c: Failed to acquire org.pulseaudio.Server: org.freedesktop.DBus.Error.AccessDenied: Connection ā:1.3ā is not al
Dec 21 20:52:05 rha pulseaudio[342]: E: [pulseaudio] bluez5-util.c: Found duplicated D-Bus path for adapter /org/bluez/hci0
Dec 21 20:52:05 rha pulseaudio[342]: E: [pulseaudio] bluez5-util.c: Found duplicated D-Bus path for device /org/bluez/hci0/dev_30_22_00_13_88_59
It connected the first time then after reboot like duplicate
pi@rha:~ $ pactl list short | grep bluez
11 module-bluez5-discover