Pi audio component

Is there a current component which will play an MP3 over the raspberry pi 3.5mm audio jack?
I guess I could use a command line switch. Alternatively, is this a feature people would like?
The component would enable an audio file on disk or from URL to be played over 3.5mm jack.

Is it something like this that you are asking about?

Thanks! Looks like a powerful tool - if I had multiple instances of HASS on multiple pi’s, all connected via Gstreamer I could have an automation to have them all play an audio file in synchrony?

As I interpret it you can send signals to other devices from one instance of hass

Practically, this means you can play audio directly on the computer running Home Assistant. It is particularly suited for playing TTS. Advanced users can specify a pipeline to transform the audio stream and/or redirect it elsewhere.

1 Like

Did anyone figure out a simple way to do this?

There is a very simple way, but using Hassio and installing an addon. @Dingle made the addon, and I have a copy on my git repository here:

it’s called “audio player”. You can invoke it with just a command like:

      - service: hassio.addon_stdin     
          addon: local_audio_player          
          input: ""

for example when my hassio starts:

  - alias: Startup Notification
      - platform: homeassistant
        event: start
      - service: hassio.addon_stdin
          addon: local_audio_player
          input: ""

just copy your mp3s in your www folder under the config directory

if you install the addon from the repository, replace “local” in “local_audio_player” with the number you see in the url, like:

in this case:

      - service: hassio.addon_stdin     
          addon: de3cd379_audio_player          
          input: ""

Awesome thank you so much!

1 Like

It is possible to use text to speech (tts) too? Using the audio jack output

I have installed the add-on, and I can call the function in my browser but can’t seem to make this work in Hassio, I have tried your start notification, but it just gives me errors, also you didn’t say whether it went into the configuration yaml or automation yaml.

hello there @Andy_Nunes, well, you can place the service wherever you need it… and the startup notification it’s in automations.yaml.
I updated my Hass.io to the latest release and it still works, so it should work on yours too.
This is how my addon looks like in my Hassio section:

Is it the same on yours?

1 Like

oh wait… on my hassio is installed locally, let me install the one on github and see if it still works…

Actually you’re right, it works if the addon is local, but doesn’t work if installed using the repository.
I’ll try to understand why, meanwhile you can follow these instructions:

to make it work on your system.

1 Like

ok, I found out where is the problem.
If you create the addon locally then you have to use the command addon: local_audio_player, like

      - service: hassio.addon_stdin     
          addon: local_audio_player          
          input: ""

but if you install it from the repository, you’ll have to modify the line replacing “local” with the number you see in the url:

so, in this case it will be:

      - service: hassio.addon_stdin     
          addon: de3cd379_audio_player          
          input: ""
1 Like

Okay that works fine, but I still can’t get any audio playback via the pi this is what is in the log :

starting version 3.2.4
[Info] Read alias: https://my.duckdns.org/local/MrDJ.mp3
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://my.duckdns.org/local/MrDJ.mp3’:
[Error] Playing failed ->

Any ideas?
I am also getting this error in main log:

Log Details (WARNING)
Thu Feb 08 2018 12:55:38 GMT+0000 (GMT)

Unable to find service hassio/addon_stdin

Try using the internal ip like:
Or changing the mp3 file and tell me if something changes.

This is what you should see in the addon log:

[Info] Read alias:
play WARN alsa: can't encode 0-bit Unknown or not applicable
 File Size: 0         
  Encoding: MPEG audio    
  Channels: 2 @ 16-bit   
Samplerate: 48000Hz      
Replaygain: off         
  Duration: unknown      

In:0.00% 00:00:00.00 [00:00:00.00] Out:0     [      |      ]        Clip:0    
In:0.00% 00:00:00.51 [00:00:00.00] Out:20.5k [      |      ]        Clip:0    
In:0.00% 00:00:00.60 [00:00:00.00] Out:28.7k [      |      ]        Clip:0    
In:0.00% 00:00:00.77 [00:00:00.00] Out:36.9k [      |      ]        Clip:0    
In:0.00% 00:00:00.94 [00:00:00.00] Out:45.1k [      |      ]        Clip:0    
In:0.00% 00:00:01.11 [00:00:00.00] Out:53.2k [      |      ]        Clip:0    
In:0.00% 00:00:01.28 [00:00:00.00] Out:61.4k [      |      ]        Clip:0    
In:0.00% 00:00:01.37 [00:00:00.00] Out:65.5k [      |      ]        Clip:0    
In:0.00% 00:00:01.54 [00:00:00.00] Out:73.7k [      |      ]        Clip:0    
In:0.00% 00:00:01.71 [00:00:00.00] Out:81.9k [      |      ]        Clip:0    
In:0.00% 00:00:01.73 [00:00:00.00] Out:82.9k [      |      ]        Clip:0    

Still no joy changed IP, changed MP3 but still get the same errors.

I think my problem with this may stem from using SSL

Can this also be a streaming mp3 file?

Apparently yes, I just made this script:

      - service: hassio.addon_stdin
          addon: de3cd379_audio_player
          input: "http://icestreaming.rai.it/1.mp3"

…and it works. So, yes, you can stream your favourite radios directly on the raspberry pi 3.5mm audio jack :wink: