Implementation of /api/stop-wav

Hello everybody,

I hope everyone is well and I wish you and your friends and family health and well-being!

Now to my question: Is it possible to implement a corresponding /api/stop-wav in addition to the /api/play-wav to stop the currently playing wav file?

I use Rhasspy to alert me to incoming calls. So far I had used mpd. This does not work after moving to another Pi. I think mpd can’t address the speaker anymore because it seems to be in use.

If there is a solution to stop playing the wav on Rhasspy it would be amazing because the ring tone of the caller should stop as soon as you pick up or the caller hangs up. Otherwise the complete file will be played.

I have done it this way so far:

- alias: rhasspy_notify_caller_ringtone_play
  initial_state: true
    - platform: template
      value_template: '{{states.sensor.fritzbox_callmonitor.state == "ringing"}}'
        seconds: 3
    condition: and
      # Nur im erlaubten Zeitraum
      - condition: template
        value_template: '{{states.binary_sensor.parents_awake_time.state|replace("on","True")|replace("off","False")}}'

      # Nur Anrufer mit bekannter Nummer
      - condition: template
        value_template: '{{ states.sensor.fritzbox_callmonitor.attributes.from != "" }}'
      - condition: template
        value_template: '{{ states.sensor.fritzbox_callmonitor.attributes.from_name != "" }}'
      - condition: template
        value_template: '{{ states.sensor.fritzbox_callmonitor.attributes.from_name != empty }}'
      - condition: template
        value_template: '{{ states.sensor.fritzbox_callmonitor.attributes.from_name != "unknown" }}'

      # Nur wenn einer von beiden zu Hause ist
      - condition: or
          - condition: template
            value_template: "{{ states.device_tracker.SMARTPHONE1.state == 'home' }}"
          - condition: template
            value_template: "{{ states.device_tracker.SMARTPHONE2.state == 'home' }}"

    - service_template: >
          {%- if states.sensor.fritzbox_callmonitor.attributes.from_name == "CALLER_NO_RINGTONE" -%}
          {%- elif states.sensor.fritzbox_callmonitor.attributes.from_name == "WIFE" -%}
          {%- else -%}
          {% endif %}

shell command:

call_teddy_caique: "curl -X POST 'http://IP:PORT/api/play-wav' -H 'Content-Type: audio/wav' --data-binary @'/config/wav/call_teddy_caique.wav'"
call_legend_of_zelda: "curl -X POST 'http://IP:PORT/api/play-wav' -H 'Content-Type: audio/wav' --data-binary @'/config/wav/call_legend_of_zelda.wav'"

Wav files must be located in …HomeAssistant/wav

To stop the ringtone I used the following automation (as I said before, I lack the possibility for this now)

- alias: rhasspy_notify_caller_ringtone_stop
  initial_state: true
    - platform: template
      value_template: '{{states.sensor.fritzbox_callmonitor.state != "ringing"}}'

    - service: shell_command.Please_make_it_possible_to_stop_playing_the_wav

Just use pulseaudio - I had a lot of trouble with rhasspy on the pi in venv without pulseadio (still having regular segfaults when restarting).

I followed this reference:

However, I work with another person using rhasspy and he menaged to just start pulseaudio as user as daemon right beofer launching rhasspy - so installing pulseaudio and wrapping this into a script might be all that’s needed.

And yes, I also kind of run mpd through snapcast ( on my pi (if you use the second solution, make sure to run mpd as the same user as rhasspy and pulseaudio).

It might be better if Rhasspy implemented the playBytesStreaming Hermes message. Then you could stream audio in and simply stop it on demand.