Playing a wave file

I am trying to get a wave file or TTS to play though the speaker. I can play the wave via aplay

aplay -D hw:0,0  chime.wav 
Playing WAVE 'chime.wav' : Unsigned 8 bit, Rate 22000 Hz, Mono

My configuration file looks like this:

media_player:
  - platform: vlc
    name: speaker
    arguments: '--alsa-audio-device=hw:0,0'

My scripts.yaml shows up on the overview page with a play button:

test_wave:
  sequence:
  - service: media_player.play_media
    data:
      entity_id: media_player.speaker
      media_content_id: /home/homeassistant/chime.wav
      media_content_type: 'music'

I think everything look right in the log file says:

2018-03-10 22:07:37 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 1576840016: Received {'service': 'turn_on', 'id': 18, 'type': 'call_service', 'service_data': {'entity_id': 'script.test_wave'}, 'domain': 'script'}

2018-03-10 22:07:37 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service=turn_on, service_call_id=1972144752-26, service_data=entity_id=script.test_wave, domain=script>

2018-03-10 22:07:37 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service=test_wave, service_call_id=1972144752-27, service_data=None, domain=script>

2018-03-10 22:07:37 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1972144752-26>

2018-03-10 22:07:37 INFO (MainThread) [homeassistant.helpers.script] Script test_wave: Running script

2018-03-10 22:07:37 INFO (MainThread) [homeassistant.helpers.script] Script test_wave: Executing step call service

2018-03-10 22:07:37 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service=play_media, service_call_id=1972144752-28, service_data=media_content_id=/home/homeassistant/chime.wav, entity_id=media_player.speaker, media_content_type=music, domain=media_player>

2018-03-10 22:07:37 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1972144752-28>

2018-03-10 22:07:37 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 1576840016: Sending {'id': 18, 'success': True, 'type': 'result', 'result': None}

2018-03-10 22:07:37 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1972144752-27>

2018-03-10 22:07:37 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=script.test_wave, old_state=<state script.test_wave=off; last_triggered=2018-03-10T17:07:25.503100-05:00, friendly_name=test_wave @

2018-03-10T17:03:36.476021-05:00>, new_state=<state script.test_wave=off; last_triggered=2018-03-10T17:07:37.246492-05:00, friendly_name=test_wave @ 2018-03-10T17:03:36.476021-05:00>>

2018-03-10 22:07:37 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 1576840016: Sending {'id': 2, 'type': 'event', 'event': {'origin': 'LOCAL', 'time_fired': datetime.datetime(2018, 3, 10, 22, 7, 37, 278040, tzinfo=<UTC>), 'event_type': 'state_changed', 'data': {'entity_id': 'script.test_wave', 'old_state': <state script.test_wave=off; last_triggered=2018-03-10T17:07:25.503100-05:00, friendly_name=test_wave @ 2018-03-10T17:03:36.476021-05:00>, 'new_state': <state script.test_wave=off; last_triggered=2018-03-10T17:07:37.246492-05:00, friendly_name=test_wave @

2018-03-10T17:03:36.476021-05:00>}}}

I have fought this for a few days, what did I miss?

Two things I checked when I set mine up like yours:

  1. I was on Rasp Pi, so I made sure the default audio output was the speaker, not the HDMI.

  2. I made sure the volume is loud enough both on the speaker dial and from HA before playing wave files:

    • service: media_player.volume_set
      data_template:
      entity_id: media_player.speaker
      volume_level: ‘9’

Also, I put the wave files I use under a sub-folder in /home/homeassistant/.homeassistant/www to be sure frontend can find them.

Hope that helps.

Did not work. :frowning:
new Scripts:

test_wave:
  sequence:
  - service: media_player.play_media
    data_template:
       entity_id: media_player.speaker
       volume_level: ‘9’
    data:
      entity_id: media_player.speaker
      media_content_id: /home/homeassistant/data/chime.wav
      media_content_type: 'music'

Should be the right device

root@hassbian:/home/homeassistant/data# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

It did set it to plug output in Pi

Sorry to dredge this up but did you ever get the audio output of the Pi working with the built in jack ?

1 Like