nimroddolev / chime_tts

A custom Home Assistant integration to play combined audio files before and/or after text-to-speech (TTS) messages
https://nimroddolev.github.io/chime_tts/
MIT License
149 stars 12 forks source link

How to call from pyscript? #75

Closed ILiveInAHouse closed 5 months ago

ILiveInAHouse commented 5 months ago

Checklist

Is your feature request related to a problem? Please describe.

I can't figure out how to call the chime_tts.say service from within pyscript. I'm not getting any errors, but I'm also not getting any audio from the media_player. Specifically, I don't think I'm indicating the target/entity_id properly. Here is what I've tried:

    service.call("chime_tts", "say",
            data={
            'target':"media_player.entrywalltablet",
            'chime_path':"custom_chime_path_2",
            'end_chime_path':'',
            'offset':'0',
            'final_delay':'0',
            'tts_playback_speed':'100',
            'volume_level':'1',
            'message':"Not Ready",
            'tts_platform':"google_translate",
            'gender':"female",
            'announce':'true'})

This is the yaml in Developer->Services that does work (produces audio):

service: chime_tts.say
target:
  entity_id: media_player.entrywalltablet
data:
  chime_path: custom_chime_path_2
  end_chime_path: ""
  offset: -300
  final_delay: 0
  tts_playback_speed: 100
  volume_level: 1
  message: hello world
  tts_platform: google_translate
  gender: female
  announce: true

Any idea how to make the call from pyscript?

Describe the solution you'd like

I need help with the pyscript call.

Describe alternatives you've considered

I also tried

service.call("chime_tts", "say",
        data={
        'entity_id':"media_player.entrywalltablet",
        'chime_path':"custom_chime_path_2",
        'end_chime_path':'',
        'offset':'0',
        'final_delay':'0',
        'tts_playback_speed':'100',
        'volume_level':'1',
        'message':"Not Ready",
        'tts_platform':"google_translate",
        'gender':"female",
        'announce':'true'})

Additional context

I'm not getting any related errors in the system log.

nimroddolev commented 5 months ago

I am not famliar with pyscript, however I suggest as a starting point that you enable debug logging for Chime TTS in order to review the full logs. This should allow you to understand:

  1. Whether pyscript is actually calling the chime_tts.say service
  2. which parameter values are received by the service, and
  3. if there is any other useful information which might provide more clarity.

To turn on debug logging:

  1. Change the logging level for Chime TTS:

    service: logger.set_level
    data:
    custom_components.chime_tts: debug
  2. With debug logging enabled, call the pyrscript which in turn calls the chime_tts.say service.

  3. Check your log for Chime TTS messages:

    https://{YOUR_HOME_ASSISTANT_ADDRESS}:8123/config/logs?filter=chime_tts

    and click LOAD FULL LOGS

ILiveInAHouse commented 5 months ago

Thanks.. here's the log. I must not be formatting the data section of the service call correctly.

2024-01-29 10:37:45.068 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say Called. Version v0.13.0 ----- 2024-01-29 10:37:45.072 DEBUG (MainThread) [custom_components.chime_tts.helpers] ----- General Parameters ----- 2024-01-29 10:37:45.073 DEBUG (MainThread) [custom_components.chime_tts.helpers] entity_ids = [] 2024-01-29 10:37:45.073 DEBUG (MainThread) [custom_components.chime_tts.helpers] cache = False 2024-01-29 10:37:45.073 DEBUG (MainThread) [custom_components.chime_tts.helpers] offset = 450.0 2024-01-29 10:37:45.073 DEBUG (MainThread) [custom_components.chime_tts.helpers] final_delay = 0.0 2024-01-29 10:37:45.073 DEBUG (MainThread) [custom_components.chime_tts.helpers] tts_playback_speed = 100.0 2024-01-29 10:37:45.073 DEBUG (MainThread) [custom_components.chime_tts.helpers] announce = False 2024-01-29 10:37:45.073 DEBUG (MainThread) [custom_components.chime_tts.helpers] volume_level = -1.0 2024-01-29 10:37:45.073 DEBUG (MainThread) [custom_components.chime_tts.helpers] join_players = False 2024-01-29 10:37:45.073 DEBUG (MainThread) [custom_components.chime_tts.helpers] * unjoin_players = False 2024-01-29 10:37:45.074 DEBUG (MainThread) [custom_components.chime_tts] async_get_playback_audio_path

ILiveInAHouse commented 5 months ago

Now I'm on the right track with some additional debugging I added to helpers.py. This is what the syntax should look like from pyscript:

    service.call("chime_tts", "say",
            entity_id="media_player.entrywalltablet",
            chime_path="custom_chime_path_2",
            offset=0,
            volume_level=1,
            message="Not Ready",
            tts_platform="google_translate",
            gender="female")
ILiveInAHouse commented 5 months ago

Solution found above https://github.com/nimroddolev/chime_tts/issues/75#issuecomment-1915839484