Hassio and local audio

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?

Yeah, that works. If I add that URL into the configuration, it gives me the exact same error (but localhost swapped with the duckdns URL, obviously).

Sounds like a network issue with the addon. Can you try the actual ip address instead of the duckdns url?

According to this thread it could be an issue with the DNS setup in your internal network.

Otherwise, I have no clue, I’m sorry. Still pretty new to this as well.

Dingle, do all audio files need to be in mp3 format? Is there a specific bit-rate?

I just attempted to play one of the files by calling the service. Tell me if I did it right.

From the services under developer tools:

  • Called domain hassio
  • Service addon_stdin
  • Service Data (tell me if this is correct):

{ "addon" : "local_audio_player", "input" : https://mysite.duckdns.org:8123/local/audio/chime_1.aif" }

I’m starting to get the hang of this JSON syntax. I think this is right as I did receive an error as defined in the run.sh portion of the add-on.

[Info] Read alias: https://smashcrashboing.duckdns.org:8123/local/sounds/chime_1.aif
play WARN alsa: can't encode 0-bit Unknown or not applicable
wget: error getting response: Connection reset by peer
play FAIL formats: can't open input file URL `https://smashcrashboing.duckdns.org:8123/local/sounds/chime_1.aif': AIFF header does not begin with magic word `FORM'
[Error] Playing failed -> 

now this looks exactly like the error that charstring posted, with one exception. The part that reads “AIFF header etc.”

When I address the location of the media file via a web browser through https with a local IP or a DuckDNS address, Chrome immediately downloads the audio file to my downloads folder. It does not play it…so at the very least, I know it’s accessible. But, the Pi3 isn’t playing it.

any ideas?

I’m stuck.

Did you ever figure out how to make this work?

Richard…what exactly is the mopidy add-on’s purpose?

My goal is to be able to trigger an audio file stored on the Pi3 with automation. I was doing it when I had HASS installed on my mac through a shell command, but I can’t figure it out, even with the add-on that dingle posted below.