How to enable TTS in Raspberry Pi and Docker?

Hey guys. I have a RPi 3 hooked to the Router. To have a transplantable dev and production environment, I use docker to deploy the homeassistant, expose 8123 port. Everything works excellent except TTS service. I cannot play any sound using home assistant. Here’s the detail.

I’m using the embedded sound card, the 3.5mm connector. In Raspbian, I can use vlc to play any .mp3 file to the speaker. I use the devices flag in docker-compose.yaml file to mount the sound device to homeassistant container. The docker-compose.yaml is like:

version: '3'
services:
  homeassistant:
    image: ${HOMEASSISTANT_IMAGE}
    container_name: home-assistant
    depends_on:
      - mqtt
    volumes:
    - ./homeassistant/config:/config
    devices:
    - "/dev/snd:/dev/snd"
    ports:
    - "8123:8123"
    environment:
    - TZ=America/New_York
    - MQTT_BROKER=${MQTT_BROKER}
    hostname: homeassistant
    networks:
    - HAS

The tts and mediaplayer homeassistant confirguration.yaml file is:

tts:
  - platform: google
media_player:
  - platform: vlc

After call the tts.google_say service with message text, nothing comes out from the speaker.

Trouble shooting:

  1. In the config/tts folder I found files like 1160265318cfc57fc39224f36ff68a13a652492e_en_-_google.mp3 which means the sound file has been fetched from google API.

  2. Such event is logged, in which the mp3 url is a valid one and can be accessed by any device in the world(also in the LAN, by this vlc server in homeassistant docker container).

Bus:Handling <Event call_service[L]: domain=media_player, service=play_media, 
service_data=media_content_id=http://xxx.xxx.xxx/api/tts_proxy/0448240fad25c776cd56bf074912c7
eaa2b79bf2_en_-_google.mp3, media_content_type=music, service_call_id=1968414384-14>
  1. The user that runs docker deamon in hose is root, and the user that runs homeassistant in container is also root. So they all should have enough privilege to play sound.

Does anyone has idea bout it? Thanks.

I can see in the VLC component page:

This service will control a background VLC instance, therefore you cannot use this to control a VLC instance launched on your desktop, unlike the Kodi media player for example.

Could anyone explain what is a background VLC instance? If I install homeassistant with pip and run it in the Raspbian directly where VLC is running(outside docker), is this what backrodund means?

Have you ever made this working? i have the same issue. I have an Intel NUC and Docker, forwarded - “/dev/snd:/dev/snd” to the HA container but no audio.

No I did not. I eventually run HA out of docker. To be honest, obsession to Docker wasted a lot of time.

I have got it working in the mean time Please check for more details :

You are awesome.

Hi,

I am also running my HA on docker and facing same issue with playing audio from TTS. However your setup is for docker-compose, But I am using portainer to manage my containers.

Can you please help me understand how can I implement this with portainer. Shall I install docker-compose and create a stack newly ?