Hassio and local audio

I have a set of USB speakers plugged into my RPi running Hassio. Is there a way to run local announcements through these speakers? ie at 8:00 am every morning have the speakers tell me that it is time to get up. I was able to add an automation to make an announcement through my Google Home, but don’t see what entity_id to use for the local device. I also have seen a few examples of running a command to show your ALSA devices but don’t see how I can run this command on the hassio host.

- alias: test
  trigger:
    platform: time
    at: '23:43:00'
  action:
    service: tts.google_say
    entity_id: media_player.master_bedroom_home
    data_template:
      message: >
        the time is eleven forty-three pm

I’ve managed to find out that the Playback device I want to use is card 1, device 0. How do I configure this to play a message from Google TTS?

Take a look here TTS questions

I did the same and setup VLC to play messages via Google TTS. And as you’ll see you specify the card and device when you setup VLC as a media player

- platform: vlc
  name: "Your Speaker Name"
  arguments: "--alsa-audio-device=hw:0,0"
2 Likes

Unfortunately it appears VLC cannot be run as root and that’s the only user on HASSIO, so I’m going to have to look for another way to make this work.

Right. I was forgetting this was in the Hass.io section :roll_eyes:

could the google assistant component be used for this ? In BRUH’s video, there is a small speaker connected to the PI and it seems that google assistant can use it to speak.

I saw that video and was considering it, but can I use it to make announcements from automations?

Did you ever find a solution to this problem?

I’m now using Chromecast audio for announcements

I was thinking about doing that too, but I didn’t want it to stop whatever is playing on the chromecast. But it is probably the best way to do it right now.

@atomicpapa you can add the modipy addon by adding this repository:

Install the modipy addon, and start the service. It will establish a local modipy server on your home network

Add the below to configuration.yaml, and then you can use media_player.mpd as the entity ID to send TTS audio to.

media_player:

  • platform: mpd
    host: you hassio IP
7 Likes

I have switched to hassio but my set-up used VLC for TTS announcements, so I tried your addon and it worked great thanks for making your addon available. :grinning:

Do you know how to change the output back to the Pi audio jack. It was working fine but now the audio is only coming out of the HDMI output. Can you tell me how to correct this?

I’ve created a local addon to play local audio files. This doesn’t entirely match the question because it won’t be able to play audio from Google Home but I think it’s still on topic.

More about creating addons: https://home-assistant.io/developers/hassio/addon_tutorial/

Dockerfile :

ARG BUILD_FROM
FROM $BUILD_FROM

# Add env
ENV LANG C.UTF-8

# Setup base, install sox package
RUN apk add --no-cache jq sox

# Copy data
COPY run.sh /
RUN chmod a+x /run.sh

CMD [ "/run.sh" ]

config.json :

{
  "name": "Audio Player",
  "version": "1.5",
  "slug": "audio_player",
  "description": "Play audio files",
  "startup": "application",
  "boot": "auto",
  "stdin": true,
  "audio": true,
  "options": {},
  "schema": {},
  "host_network": true
}

run.sh :

#!/bin/bash
set -e

echo "starting!"

# Read from STDIN aliases to play file
while read -r input; do
    # removing JSON stuff
    input="$(echo "$input" | jq --raw-output '.')"
    echo "[Info] Read alias: $input"

    if ! msg="$(play $input)"; then
    	echo "[Error] Playing failed -> $msg"
    fi
done

You can play local audio files by calling the following service, in this case I’ve just put an mp3 in the www folder of my configuration:

service: hassio.addon_stdin
data:
  addon: local_audio_player
  input: "http://localhost:8123/local/doorbell.mp3"
1 Like

Hello there Dingle, thank you for sharing. Just a question. Where should I put the doorbell.mp3 on my sd? May I also use a dir name?

I’ve put them in the config/www folder where you also put the images that need to be available in the webUI. That config/www folder is equal to http://localhost:8123/local/ so you can use subfolders if needed. I don’t know how to set up the addon to also access other files in the config section…

1 Like

oh, really? I didn’t know that. Thank you so much

mopidy is playing fine through my RPI audio jack, but I can’t figure out how to change the output devices. I can see my USB stick:

➜  / hassio host hardware
  "audio": {
    "0": {
      "name": "bcm2835 - bcm2835 ALSA",
      "type": "ALSA",
      "devices": {
        "0": "digital audio playback",
        "1": "digital audio playback"
      }
    },
    "1": {
      "name": "USB-Audio - USB PnP Sound Device",
      "type": "Device",
      "devices": {
        "0": "digital audio capture"
      }
    }
  }
}

And looking at the mpd.conf.example it seems like I should be able to set it in the options using (in the options panel in hass):

  "options": [
    {
      "name": "audio_output/type",
      "value": "alsa"
    },
    {
      "name": "audio_output/device",
      "value": "hw:0,1"
    }
  ]

Tried several things for the value of device and can’t get it to work.

Hey there, thanks so much for this! Been meaning to figure out how to play a locally hosted audio file for awhile, and specifically how to do it over local audio output. This is perfect … EXCEPT I can’t get it to work. :stuck_out_tongue:

I’ve installed the addon in an “audio_player” folder under /addons/. I’ve installed the local addon and that all seems to be working. When I run your test under services, I get the following error in the log for the addon:

[Info] Read alias: http://localhost:8123/local/chime.mp3
play WARN alsa: can't encode 0-bit Unknown or not applicable
wget: error getting response: Invalid argument
play FAIL formats: can't open input file URL `http://localhost:8123/local/chime.mp3': 
[Error] Playing failed -> 

The chime file is in the www folder inside config. I’m using duckdns and LetsEncrypt, so not sure if there’s some formatting I need for that. Any ideas?

Are you able to access that chime file through your browser? (replace localhost with the ip address of course)
And does it work when you refer to that ip address from the configuration?