Pi audio component

@Pantomax ciao, volevo chiedereti di aggiungerti al mio gruppo facebook per creare una comunità di supporto italiana di HA, visto il poco materiale reperibile nella nostra lingua, ciao e grazie

Ciao @Domo, in realtà non ho nessun profilo Facebook, magari più avanti me ne faccio uno. Se ti può interessare sto scrivendo un piccolo tutorial su Linkedin:

magari a qualcuno può servire :wink:
Max

1 Like

perfetto, grazie, se non dispiace condivido sul gruppo.
Inoltre ti volevo chiedere maggiori informazioni riguardo l’audio dal jack, ho seguito le tue istruzioni e dal log risulta che la musica e in esecuzione ma dalla cassa non esce alcun suono,
questo e il log che ricevo: riesci ad aiutarmi a capire come mai non funziona?grazie
Immagine

Certo, condividi pure. Prova con l’indirizzo di Radio Rai ( http://icestreaming.rai.it/1.mp3 ) che sono sicuro sia compatibile con il player utilizzato. Sei sicuro che il jack funzioni? Hai mai sentito altri suoni uscire da lì? Se nemmeno quello funziona ne riparliamo :wink:

Funzionaaa, il problema era che prima di provare la tua guida,avevo fatto delle prove e avevo collegato l HDMI di raspberry alla TV, cosi ho letto un antro post dove un utente aveva il mio stesso problema e staccando HDMI e riavviando il PI e partito l’audio dal jack alla cassa. funziona sia con mopidy che con audio_player, pero vedo che non funziona il TTS, conosci qualche soluzione?

(Per quanto riguarda il tts lo scrivo in inglese, magari può far comodo anche ad altri.)
So, if you guys want to use the TTS on this player, I made a little workaround. I hope it will work correctly also on your system.

First of all you need to make a directory called tts inside the /config/www/ directory and set this dir as the google tts cache, like this:

tts:
  - platform: google
    cache: true
    cache_dir: /config/www/tts

Now, you have to set these three elements:

  1. a fake media player
media_player:
  - platform: universal
    name: hassio
  1. a command used to clean the directory after every usage
shell_command:
  remove_old_mp3_files: rm /config/www/tts/*.mp3
  1. a sensor used to sense when Google TTS writes the TTS mp3 in my directory
sensor:
- platform: command_line
  name: "last tts"
  command: "ls /config/www/tts/ -1t | head -1"
  scan_interval: 5

I will call this script to generate the mp3 file:

script:
  hassio_talk:
    alias: Hassio talk script
    sequence:
      - alias: Hassio Talk 
        service: tts.google_say
        entity_id: media_player.hassio
        data_template: 
          message: >
            '{{ message }}'
          language: en
          cache: True

and this automation will play the file as soon as the mp3 file will be transferred on the hassio (don’t forget to replace the IP address of your RPi):

automation:
  - alias: "Read TTS"
    trigger:
    - platform: state
      entity_id: sensor.last_tts
    action:
    - service: hassio.addon_stdin
      data_template:
        addon: de3cd379_audio_player
        input: "http://192.168.1.100:8123/local/tts/{{ states('sensor.last_tts') }}"
    - delay: '00:00:05'
    - service: tts.clear_cache

so, if you want to call the script, just use this service:

  - service: script.hassio_talk
    data:
      message: "Hello world!"

for example when the hassio starts:

  - alias: "TTS message at start"
    trigger:
      - platform: homeassistant
        event: start
    action:
      - service: shell_command.remove_old_mp3_files
      - service: script.hassio_talk
        data:
          message: "Server on line"
1 Like

If you are not using hass.io, just install VLC media player component. It can play local MP3 and TTS.

Before that, you need to run this…

sudo apt-get install vlc-nox
1 Like

Hey there @masterkenobi, thank you for the hint.
Do you have any idea on how to set the volume level on Hassio?

why does this happen if I try to install VLC?

@Pantomax volevo chiederti se hai idea di come poter installare un microfono per usare i comandi vocali sul RPi con Hass.io, sul web non ho trovato risposte.

Because you are on Hass.io, there is no access the the underlying OS.

Is there a way to choose between the audio jack or have the raspi transmit the signal via Bluetooth, allowing cable free connection to my Bluetooth speaker.

Hello,

I had a question, if you wouldn’t mind answering

I tried to install the addon locally but I’m getting this error.

starting version 3.2.4
/usr/bin/entry.sh: /run.sh: /bin/bash^M: bad interpreter: No such file or directory
/usr/bin/entry.sh: line 9: /run.sh: No error information

do you know what is causing it?

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" ] 

{

  "name": "Audio Player",

  "version": "1.55",

  "slug": "audio_player",

  "description": "Play audio files",

  "startup": "before",

  "boot": "auto",

  "stdin": true,

  "audio": true,

  "hassio_api": true,

  "options": {},

  "schema": {},

  "host_network": true

}

#!/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

I’m still trying to learn all this stuff.

Thanks very much!

After i test this in the developer tools > services in the log i get this message, any idea why?

[Info] Read alias: http://192.168.1.13:8123/local/alarm.mp3
ALSA lib conf.c:1876:(snd_config_load1) toplevel:1:2:Unexpected char
ALSA lib conf.c:5017:(snd_config_expand) Parse arguments error: Invalid argument
ALSA lib pcm.c:2501:(snd_pcm_open_noupdate) Unknown PCM hw:{0,0}
[Error] Playing failed ->

Great Addon-on, thank you.
Is there a way to set the volume?

@Pantomax I installed the add-on in ver 0.80 and am unable to get any audio output from the 3.5mm jack. I followed your code above. Have you tried it on Hassio ver 0.80 yet? is it working?

tested on version Home Assistant
0.82.1 working good! Nice Skill ! Grazie Mille!

your add-on is not working…

The add-on is not working anymore.
HASSIO 0.106.5

I get this error message:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
starting!
[Info] Read alias: http://localhost:8123/local/doorbell_sound_2.mp3
ALSA lib dlmisc.c:283:(snd_dlobj_cache_get0) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so ((null): Error loading shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so: No such file or directory)
[Error] Playing failed -> 
[Info] Read alias: http://localhost:8123/local/doorbell_sound_2.mp3
ALSA lib dlmisc.c:283:(snd_dlobj_cache_get0) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so ((null): Error loading shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so: No such file or directory)
[Error] Playing failed -> 

Hello, is this add ons still working? Thanks

1 Like