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

chime_tts.say_url default save folder doesn't seem to exist, but works with modifications #86

Closed DanDixon closed 2 months ago

DanDixon commented 4 months ago

Checklist

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

I'm using v0.13.1-beta3

chime_tts.say_url is set to write to the folder: /www/chime_tts/

But this wasn't working for me. I looked for the output files but couldn't find them. I don't think they were being saved?

I tried editing the configuration, but that wasn't saving for me (a separate issue).

1 So I modified: /config/custom_components/chime_tts/const.py with this change:

WWW_PATH_DEFAULT = "/media/chime_tts/"
# WWW_PATH_DEFAULT = "/www/chime_tts/"

image

After a restart of Home Assistant, the chime_tts configuration was now changed and would write to a folder that exists (I manually created the chime_tts folder in media).

2 Then I used a template in a variable (below) to change the output URL from: chime_tts.url: http://192.168.1.5:8123/media/chime_tts/afx_uhze.mp3 to: fixedurl: media-source://media_source/local/chime_tts/afx_uhze.mp3

Which made it work!

Here are the scripts all together:

  - service: chime_tts.say_url
    data:
      tts_platform: openai_tts
      cache: true
      message:
        - type: chime
          path: "{{chimefile}}"
          audio_conversion: "-filter:a volume=0.8"
        - type: tts
          message: "{{say}}"
          delay: -800
          tld: com.au
          tts_playback_speed: 110
    response_variable: chime_tts

(removed a step where I fade my music to a low volume)

  - variables:
      fixedurl: >-
        {{chime_tts.url|replace('http://192.168.1.5:8123/media/','media-source://media_source/local/')}}

  - service: media_player.play_media
    data:
      media_content_id: "{{fixedurl}}"
      media_content_type: music
    target:
      entity_id:
        - media_player.minis_linked
    alias: Play URL on Minis

It's working for me now, but I'm not sure why the default settings were not (nor why I couldn't change settings with the Configuration dialog)

I saw someone else was having a problem with say_url, so I thought I'd also share my experience.

DanDixon commented 4 months ago

Also, I absolutely love this integration. Thanks again for all your help and for making and maintaining it.

nimroddolev commented 4 months ago

Hey @DanDixon, thanks for the kind words 👍

The chime_tts.say_url was added specifically to save the generated mp3 file in a publicly facing folder that is accessible form the internet. As you found out, you can change the default path to a local & non-public folder (but that defeats the purpose).

I tried editing the configuration, but that wasn't saving for me (a separate issue).

When you enter a folder path in the configuration, Chime TTS tests to see if it can write to that folder, and if it can't it returns an error. Is this the issue you're having when trying to change the configuration? If you are not able to save a folder under the /www folder path, then it seems the issue here is that Chime TTS doesn't have access your www folder specifically. Have you added a www folder to your config folder? See if adding the folder makes a difference.

Otherwise I will need more information. Could you please enable debug logs for Chime TTS? This way I might be able to understand what the issue is and how to solve it.

  1. Turn on debug logging:

    service: logger.set_level
    data:
    custom_components.chime_tts: debug
  2. Call the service chime_tts.say_url again (with the standard default folder path).

  3. Check your log messages in Home Assistant:

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

    and click LOAD FULL LOGS

DanDixon commented 4 months ago

When you enter a folder path in the configuration, Chime TTS tests to see if it can write to that folder, and if it can't it returns an error. Is this the issue you're having when trying to change the configuration?

It was flickering and giving me no error, but just reset the text back like it was. I'm not sure what I did, but this is not happening to me now.

I was not getting this: image

Which I am now, so not sure what happened.


As an asdie: If you type something into Custom 1 and then try and delete it, it reverts back. Doesn't seem to be a way to reset those back to blank. image


If you are not able to save a folder under the /www folder path, then it seems the issue here is that Chime TTS doesn't have access your www folder specifically. Have you added a www folder to your config folder?

Yes


Unfortunately, I still wasn't able to get it to write to: /config/www/chime_tts (I made a folder there)

nimroddolev commented 4 months ago

I still think the main issue is that your HA instance can't write to the folder you specified as the public folder for chime_tts.say_url. Perhaps it has to do with something in your particular setup? Which version of HA are you running and on what hardware?

Regarding the other issue you reported for custom chime paths:

Doesn't seem to be a way to reset those back to blank.

It's an issue with Home Assistant - if the textfield is blank it reverts to using previous value. A workaround is to you use a space " " as the value, which will reset the value. It's not the most elegant solution, but this bug is beyond the scope of Chime TTS. If you like you can open a bug with the Home Assistant developers.

DanDixon commented 4 months ago

The chime_tts.say_url was added specifically to save the generated mp3 file in a publicly facing folder that is accessible form the internet. As you found out, you can change the default path to a local & non-public folder (but that defeats the purpose).

Aside from my original question, I'll share why I'm using say url:

I have a popup that appears on my dashboards when a message is played. Being able to generate the sound file separately from playing it lets me wait to show the popup at the same time as the file is played (instead of showing the popup with the message and there being a several second delay before it starts playing).

Does that use case match your vision for the feature?


I setup a time poem to be read aloud every so often (inspired by this Kickstarter).

But these take about 7 seconds before they start playing. Another use of say_url (that I have yet to implement) would be to generate the files in advance (even 1 minute before) so when it was requested there would be less delay and it could start playing exactly at the start of the event in question.

Here's what my dashboard looks like with a time poem message: image

nimroddolev commented 4 months ago

I never considered your use case or any other which required delayed/scheduled playback of the audio generated by Chime TTS. The time poem is a nice idea 😀

I released a new beta, v0.13.1-beta13 (I'm aiming for a record number of beta releases 🤦‍♂️) which adds support for specifying a local folder path for chime_tts.say_url generated audio in addition to a public directory. With this change you can now set a local folder path as the public folder path in the configuration, and the url output from chime_tts.say_url will work for either scenario - adding the external URL prefix for files located inside the public www folder, or the valid config local path.

Let me know if it's working for you.

DanDixon commented 4 months ago

Cool. That works.

Although, I don't think I fully understand how the paths work in Home Assistant as I still had to modify the output url in order to make it work:

In v0.13.1-beta13:

In the configuration for chime_tts I set the folder path to: /media/chime_tts/ image

Running chime_tts.say_url generates a chime_tts.url that looks like this: /media/chime_tts/jx9x352u.mp3

And before playing the file to my Google minis I did this in the play script:

variables:
  mediafile: |
    {{ chime_tts.url | replace('/media/','media-source://media_source/local/') }}

The mediafile variable now looks like this: media-source://media_source/local/chime_tts/jx9x352u.mp3

I was struggling because I had it like this and it didn't work: media-source://media_source/local/media/chime_tts/jx9x352u.mp3

And then I play the file like this:

service: media_player.play_media
data:
  media_content_id: "{{ mediafile }}"
  media_content_type: music
target:
  entity_id:
    - media_player.minis_linked

Perhaps there's a more elegant solution. Either way, it works, so thank you again!

nimroddolev commented 4 months ago

Perhaps the best solution would be for chime_tts.say_url to return both the local file path and the media_content_id (which is what you did with your script), eg:

media_content_id: media-source://media_source/local/media/chime_tts/f_21f4mz.mp3
filepath: /media/chime_tts/f_21f4mz.mp3
duration: 1.23
success: true
DanDixon commented 4 months ago

That would useful.

I'll note that your example media_content_id: media-source://media_source/local/media/chime_tts/f_21f4mz.mp3

But, at least in my case it should be: media-source://media_source/local/chime_tts/f_21f4mz.mp3

Thank you again!

DanDixon commented 2 months ago

Using v1.0.0 2024-04-02

I had to modify my scripts to work with the new changes and this is working great. (I had to change them to use media_content_id instead of url)

Thank you!

nimroddolev commented 2 months ago

Happy to hear it’s working for you 👍