Required a step-by-step guide on how to play sounds and media through a 3.5mm audio jack

For your second question
aplay and paplay, both commands are working fine. I don’t know wich one is better?

There is a further alternative, compared to aplay or paplay, and it is notifier (which uses Sox’s play command internally)

  • you can adjust the volume for each music file
  • you can listen to mp3 as well as wav

The music files must be in media / www, without having to indicate the folder each time.
Take your example of the notifier for the TTS and replace
input:
volume: 99
message: “TEST”
with
input:
volume: 99
music: “gong-school-bell-hit-3.wav”

Hello @guido-syseng!

Thanks for creating this great addon. I was wondering: does it work with any TTS provider? I’m using Amazon Polly for the moment.

Also, I have a suggestion, not sure if possible: would be nice to use both left and right channels as a single, individual, mono output for different speakers, on different rooms :slight_smile:

Thanks!

Thanks Guido ! Works great :slight_smile:

Eddy

Hello,
I have a problem with notifier on my second HA instance: tts works fine but not mp3
My second instance is on port 8124 because i had problems with upnp conflict: both HA wanted to map port 8123 on my router…
So so the problem is that notifier add-on does not permit to select port…
Here is the log:
wget: can’t connect to remote host (127.0.0.1): Connection refused
play FAIL formats: can’t open input file URL `http://localhost:8123/local/Volume_du_haut-parleur_modifie.mp3’:
[21:48:53] ERROR: Invalid audio
[EDIT]: Change port of my remote HA instance to 8123 and Notifier is now working perfectly :slight_smile:
Conclusion: If someone is using another port (other than 8123), Notifier won’t work… :japanese_ogre:

@guido-syseng , does Notifier only work with RaspberryPi or should it work any hardware running HA? I use a NUC and could not get Notifier working. The configuration screen only has output options for “Default” and “Dummy Output”. Any advice?

Thanks.

1 Like

Hi, same issue here on Intel NUC :

EDIT : Solved by settings 8.8.8.8 as default DNS in the HAOS Supervisor.

@guido-syseng Thanks for your great addon! Got it working on my RPI 3+ and am finally able to play MP3’s and send messages to my connected speaker.

What is wrong with the auto generated automation script?
System sound working just fine.
Absolute directory is '/media/file.mp3
Card on Dashboard shows file playing, but no sound.

 action:
  - service: media_player.play_media
    target:
      entity_id: media_player.vlc_telnet
    data:
      media_content_id: '/media/classic-door-bell.mp3'
      media_content_type: music
    metadata: {}
  mode: single
1 Like

I use this and it works fine:

  - service: media_player.play_media
    target:
      entity_id: media_player.vlc_telnet
    data:
      media_content_id: http://IP.OFY.OUR.HA:8123/local/ns-ding-dong.mp3
      media_content_type: music

My mp3’s are stored in config/www/

https://thehelpfulidiot.com/playing-a-sound-directly-from-home-assistant-operating-system#comment-3820

I want to use the 3.5mm jack on the Rpi 4 I have and followed this how to I linked. But it didn’t work for me. not sure what I am doing wrong…

I am posting it here because maybe it can help someone else.

I was eventually able to get it to work using the link I sent earlier, but I found a better way

install local vlc then install telnet. Follow the instructions from the thread Iinked

1 Like

This addon works perfect!
Thank you!

Dear Guido, I get an error when I start an automation with local audio play:
wget: error getting response: Invalid argument
play FAIL formats: can’t open input file URL `http://localhost:8123/local/beep.mp3’:
[12:35:44] ERROR: Invalid audio

I don’t configure the path for audio files, only copied mp3 to config/www folder.
Could you help me?

I tried the VLC addon a while ago, and found that it would often fail to play my audio, or be very choppy in its play back and never found a solution. Its possible its better now, or something specific in my setup caused the issue (virtual box on windows running HAOS) and how audio is passed through.

In the end I went a different direction using an old mobile phone I had lying around using the bubbleupnp app. I can now select the phone as a media player, and use its 3.5mm jack to output the audio to any connected speaker.

1 Like

Dear Hakos, you should in the Notifier addon options check the music-test option, stop and restart the addon and send me the result

It’s worked, played the test song.
I think the issue is with source path: I use DuckDNS add-on and I can’t acces with local IP for HA, only with Duckdns. So this path: (`http://localhost:8123/local/beep.mp3’:slight_smile: isn’t correct.
How can I configure this correctly?

Dear Hakos, to be sure that the problem is in the path you should temporarily remove duchdns addon and check if the error is still there.

yes, the problem is the local access. I changed configuration.yaml and removed duckdns registry and installed and configured nginx. After that everything works fine! Thank you!

This solution is not good for me. I need DuckDNS, but with dnsmasq I can access in local network only with https. So this path is not good for me: http://localhost:8123/local/
could I change it?

At the moment (April 2024) the following setup works without any add-ons:

  • You will need Pulse Audio client binaries (pacat, paplay, pactl). They used to be present in the main HA container, but were removed. However, all libraries required by those binaries are still present in the main container
  • Take those binaries from the hassio_audio container and copy them to /media as follows:
docker cp hassio_audio:/usr/bin/pacat /media/
docker cp hassio_audio:/usr/bin/paplay /media/
docker cp hassio_audio:/usr/bin/pactl /media/

These commands can be run either from the host OS (if you have access to it, e.g. you are running HA supervised) or from the Advanced Terminal add-on. While doing this, you can verify whether HA would send the sound to the sound card you are expecting: run pactl info and verify whether “Default sink” is showing what you are expecting. If you have access to the host OS, the command would be: docker exec -it hassio_audio /usr/bin/pactl info.

  • Now you can define something like this:
shell_command:
    play_sound_file: "/media/paplay /media/myfile.ogg"

and use this as a service in automations. One downside: PulseAudio libraries in HA do not support MP3 files. WAV, OGG, FLAC is ok, but not MP3.

I’ve opened a feature request for a proper implementation of the local playback. Consider voting for it: click

1 Like