Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with chime_tts:play_url #57

Closed
3 tasks done
dbullendsl opened this issue Dec 15, 2023 · 12 comments
Closed
3 tasks done

Problem with chime_tts:play_url #57

dbullendsl opened this issue Dec 15, 2023 · 12 comments

Comments

@dbullendsl
Copy link

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

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

using the say_url function doesn't appear to work. I only have access to Amazon echos and only get an output that says "sorry can't access your simon says..."

First I'm running HassOS on an Intel mini PC

Here's what I'm doing. Execute a script that takes an input for the message and calls the chime_tts:say_url service then sends the output to the echos:

Here's the script and trace.


alias: aa chime
sequence:
  - service: chime_tts.say_url
    data:
      chime_path: bells
      tts_platform: google_translate
      message: "{{message}}"
    response_variable: chime_tts
    enabled: true
  - service: notify.alexa_media
    data:
      message: |
        <audio src='{{chime_tts.url}}'/>
      target:
        - media_player.kitchen_echo_show
        - media_player.office_echo_dot
      data:
        type: tts
mode: single
fields:
  message:
    selector:
      text: null
    name: message


Executed: December 14, 2023 at 10:52:45 AM
Result:
params:
  domain: chime_tts
  service: say_url
  service_data:
    chime_path: bells
    tts_platform: google_translate
    message: Testing Amazon Echo output
  target: {}
running_script: false

Executed: December 14, 2023 at 10:52:45 AM
Result:
params:
  domain: notify
  service: alexa_media
  service_data:
    message: <audio src='https://[myserver.url]/local/chime_tts/x0ekdd_7.mp3'/>
    target:
      - media_player.kitchen_echo_show
      - media_player.office_echo_dot
    data:
      type: tts
  target: {}
running_script: false

and here's the log:


2023-12-14 10:46:31.381 INFO (MainThread) [homeassistant.components.script.aa_chime] aa chime: Running script sequence
2023-12-14 10:46:31.381 INFO (MainThread) [homeassistant.components.script.aa_chime] aa chime: Executing step call service
2023-12-14 10:46:31.382 DEBUG (MainThread) [custom_components.chime_tts] Calling chime_tts.say_url...
2023-12-14 10:46:31.382 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say Called. Version v0.10.1 -----
2023-12-14 10:46:31.382 DEBUG (MainThread) [custom_components.chime_tts] Service call #0 was added to the queue.
2023-12-14 10:46:31.382 DEBUG (MainThread) [custom_components.chime_tts] Executing queued job #0
2023-12-14 10:46:31.383 DEBUG (MainThread) [custom_components.chime_tts] ----- General Parameters -----
2023-12-14 10:46:31.383 DEBUG (MainThread) [custom_components.chime_tts]  * entity_ids = []
2023-12-14 10:46:31.383 DEBUG (MainThread) [custom_components.chime_tts]  * hass = <HomeAssistant RUNNING>
2023-12-14 10:46:31.383 DEBUG (MainThread) [custom_components.chime_tts]  * chime_path = custom_components/chime_tts/mp3s/bells.mp3
2023-12-14 10:46:31.383 DEBUG (MainThread) [custom_components.chime_tts]  * end_chime_path = 
2023-12-14 10:46:31.383 DEBUG (MainThread) [custom_components.chime_tts]  * cache = False
2023-12-14 10:46:31.383 DEBUG (MainThread) [custom_components.chime_tts]  * delay = 450.0
2023-12-14 10:46:31.383 DEBUG (MainThread) [custom_components.chime_tts]  * message = Testing Amazon Echo output
2023-12-14 10:46:31.384 DEBUG (MainThread) [custom_components.chime_tts]  * tts_platform = google_translate
2023-12-14 10:46:31.384 DEBUG (MainThread) [custom_components.chime_tts]  * tts_playback_speed = 100.0
2023-12-14 10:46:31.384 DEBUG (MainThread) [custom_components.chime_tts]  * announce = False
2023-12-14 10:46:31.384 DEBUG (MainThread) [custom_components.chime_tts]  * volume_level = -1.0
2023-12-14 10:46:31.384 DEBUG (MainThread) [custom_components.chime_tts]  * join_players = False
2023-12-14 10:46:31.384 DEBUG (MainThread) [custom_components.chime_tts]  * unjoin_players = False
2023-12-14 10:46:31.384 DEBUG (MainThread) [custom_components.chime_tts] ----- TTS-Specific Params -----
2023-12-14 10:46:31.384 DEBUG (MainThread) [custom_components.chime_tts] -------------------------------
2023-12-14 10:46:31.384 DEBUG (MainThread) [custom_components.chime_tts] async_get_playback_audio_path
2023-12-14 10:46:31.384 DEBUG (MainThread) [custom_components.chime_tts] get_audio_from_path("custom_components/chime_tts/mp3s/bells.mp3", 0, audio)
2023-12-14 10:46:31.384 DEBUG (MainThread) [custom_components.chime_tts]  - Retrieving audio from path: "custom_components/chime_tts/mp3s/bells.mp3"...
2023-12-14 10:46:31.475 DEBUG (MainThread) [custom_components.chime_tts]    - ...audio with duration 0.944s retrieved successfully
2023-12-14 10:46:31.475 DEBUG (MainThread) [custom_components.chime_tts] async_request_tts_audio(hass, tts_platform = google_translate, message = Testing Amazon Echo output, tts_playback_speed = 100.0, cache = False, language = None)
2023-12-14 10:46:31.475 DEBUG (MainThread) [custom_components.chime_tts]  - Generating TTS audio...
2023-12-14 10:46:32.008 DEBUG (MainThread) [custom_components.chime_tts]  - ...TTS audio completed in 533.045 ms
2023-12-14 10:46:32.010 DEBUG (MainThread) [custom_components.chime_tts]  - Final audio created:
2023-12-14 10:46:32.010 DEBUG (MainThread) [custom_components.chime_tts]    - Duration = 3.698s
2023-12-14 10:46:32.010 DEBUG (MainThread) [custom_components.chime_tts] new_audio_folder = /www/chime_tts/
2023-12-14 10:46:32.010 DEBUG (MainThread) [custom_components.chime_tts] Audio folder exists: /www/chime_tts/
2023-12-14 10:46:32.010 DEBUG (MainThread) [custom_components.chime_tts]  - Creating mp3 file...
2023-12-14 10:46:32.010 DEBUG (MainThread) [custom_components.chime_tts]    - Filepath = '/www/chime_tts/9m11150t.mp3'
2023-12-14 10:46:32.079 DEBUG (MainThread) [custom_components.chime_tts]    - Non-relative filepath = '/www/chime_tts/9m11150t.mp3'
2023-12-14 10:46:32.079 DEBUG (MainThread) [custom_components.chime_tts]    - File saved successfully
2023-12-14 10:46:32.079 DEBUG (MainThread) [custom_components.chime_tts]  - audio_dict = {'audio_path': '/www/chime_tts/9m11150t.mp3', 'audio_duration': 3.698}
2023-12-14 10:46:32.079 DEBUG (MainThread) [custom_components.chime_tts] Saving to chime_tts storage:
2023-12-14 10:46:32.079 DEBUG (MainThread) [custom_components.chime_tts]  - key:   "5e4d304a4875a6bb88f69a6e3ed3a06cee39b720bb9b8eaadedd7d2045177056"
2023-12-14 10:46:32.079 DEBUG (MainThread) [custom_components.chime_tts]  - value: "{'audio_path': '/www/chime_tts/9m11150t.mp3', 'audio_duration': 3.698}"
2023-12-14 10:46:32.082 DEBUG (MainThread) [custom_components.chime_tts] Final URL = https://[myhass.url]/local/chime_tts/9m11150t.mp3
2023-12-14 10:46:32.082 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say Completed in 699.518 ms -----
2023-12-14 10:46:32.083 DEBUG (MainThread) [custom_components.chime_tts] Removing current queued service call.
2023-12-14 10:46:32.083 DEBUG (MainThread) [custom_components.chime_tts] Queue emptied. Reinitializing values.
2023-12-14 10:46:32.083 INFO (MainThread) [homeassistant.components.script.aa_chime] aa chime: Executing step call service

so far what I've done

  1. I have several scripts and automations that output text and prerecorded .mp3 to amazon echos - no problems
  2. made sure that the local media directory is pointing to /media - ok
  3. looked for the .mp3 sounds in custom_components/mp3s - ok
  4. looked for the www/chime_tts folder - doesn't exist
  5. created the www/chime_tts folder - problem persists
  6. looked for creation of output .mp3 files - none seen - why?

I ssh into the server and found there is no folder /www/chime_tts, I've tried directly accessing the URL on the server and get a 404 error
I manually created the /www/chime_tts folder and nothing is written there
I looked for any new mp3s that were created and found none.

Describe the solution you'd like

locate the issues

Describe alternatives you've considered

stick with my existing solutions

Additional context

none

@nimroddolev
Copy link
Owner

Hi @dbullendsl. I'm sorry to hear you're having issues.

Thank you for the detailed log and the list of your troubleshooting steps!

I think that your issue might be due to an incorrect public mp3 folder path in the integration's configuration.
Can you please check that the public mp3 folder path is a full path and not relative?

You can access the integration's configuration by navigating to Settings --> Devices & services --> Chime TTS --> CONFIGURE

@dbullendsl
Copy link
Author

dbullendsl commented Dec 17, 2023

I thought of that too and did change it at one time to /homeassistant/www/chime_tts I also changed it to /local/chime_tts but that didn't change anything either.

If I manually create the /www/chime_tts folder and drop a known good mp3 into it I can reference it from the outside with a browser.

I've set things back to the default and here's a screen shot.
'''
image
'''
I also noticed that even though the chime_tts.play function isn't expected to run with Amazon devices that it also doesn't produce any mp3 output.

@nimroddolev
Copy link
Owner

nimroddolev commented Dec 17, 2023

As I’m not familiar with your setup I can’t know what are the correct paths are but I still think that the lack of mp3 files is due to an issue with the paths, probably for both the service calls.
Note that the MP3s generated from the chime_tts.say service only persist if the cache parameter is set to true.

@dbullendsl
Copy link
Author

ok, I'll check that

@dbullendsl
Copy link
Author

I think I found the problem, by executing the chime_tts:say_url function in the developer's console I get a return result of

url: https://[server.url]/local/chime_tts/zfijllg7.mp3

but I think the result should be https://[server.url]/www/chime_tts/zfijllg7.mp3

Elsewhere in comments in other issues there were instructions to make sure that /local pointed to /media, but that's not a public path for web connections. From running the chime_tts:say fuction with the cache parameter set to true results from the TTS service end up in /media/sounds/temp/chime_tts which is the same as /local/sounds/temp/chime_tts and is not accessible externally. Your code should then move the result to /homeassistant/www/chime_tts which would be accessible as https://[server.url]/www/chime_tts/tts_file.mp3

@nimroddolev
Copy link
Owner

nimroddolev commented Dec 18, 2023

You described exactly what the code does (chime_tts.say saves to media and chime_tts.say_url saves to www).
In Home Assistant the www folder is accessible publicly as https://[server.url]/local/ so the URL from your last comment is correct. The issue is that the file is not being saved in the right folder, and therefore cannot be found at that address.
I can confirm that it works correctly in both my docker development environment and my HAOS Raspberry Pi 4 production environment.

It is for these reasons that I feel the problem lies in the public mp3 folder path defined in your configuration.

@nimroddolev
Copy link
Owner

Could you please try setting the public mp3 folder path to: /config/www/chime_tts ?

@dbullendsl
Copy link
Author

Excellent! That was it.

the intigration is working and I'm getting the mp3 in the www/chime_tts folder, and can paste the URL into a browser and it'll play.

Amazon is still throwing an error but I've seen that before when the audio file didn't match Amazon's specifications, so it's not a problem with the integration.

If you've got any suggestions on fixing that I'd appreciate it. Can the options field be used to do anything like calling ffmpeg to format the output?

@nimroddolev
Copy link
Owner

I’m glad it is now working for you!

I would be happy to add support for encoding with ffmpeg. I can add a checkbox specifically for Amazon’s requirements and also a text field to pass ffmpeg parameters for other use cases.

@dbullendsl
Copy link
Author

That would be great, meanwhile I do have it working using a shell command to ffmpeg with the parameters specified on Amazon's AWS SML page. I'll post everything here soon.

@dbullendsl
Copy link
Author

here's my solution, not completely refined, but it works.
It consists of 3 parts, 2 scripts and a shell command.

The set up looks like this:

Edit configuration.yaml to add the following

# Add ffmpeg to the configuration to format audio
# output to play on Amazon Echos
ffmpeg:

shell_command:
  amazon_level_up: ffmpeg -i '{{input_url}}' -y -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 -write_xing 0 '{{output_url}}'

the first script calls chime_tts.say_url, then sends the output to the shell command with another script

alias: aa chime
sequence:
  - service: chime_tts.say_url
    data:
      chime_path: bells
      end_chime_path: bells 2
      delay: 0
      final_delay: 0
      tts_playback_speed: 100
      message: "{{message}}"
      tts_platform: google_translate
      cache: false
    response_variable: chime_tts
  - service: script.aa_ffmpeg_convert
    data:
      input_url: "{{chime_tts.url}}"
      output_url: /config/www/chime_tts/output.mp3
  - service: notify.alexa_media
    data:
      message: |
        <audio src="https://[your_server.url]/local/chime_tts/output.mp3"/>
      target:
        - media_player.office_echo_dot
      data:
        type: tts
mode: single
fields:
  message:
    selector:
      text: null
    name: message

second script:

alias: aa ffmpeg_convert
sequence:
  - service: shell_command.amazon_level_up
    data:
      input_url: "{{input_url}}"
      output_url: "{{output_url}}"
mode: single
fields:
  input_url:
    selector:
      text: null
    name: input_url
    required: true
  output_url:
    selector:
      text: null
    name: output_url
    required: true

I probably could have gotten by with one script, but I decided to split out the ffmpeg part in case I needed it for some other use case when sending audio to amazon echoes.

the only variables are the input message and the resultant url supplied by chime_tts.say_url, the output.mp3 from the shell command is overwritten each time it's run so is a fixed name. I'll be changing the inputs so that I can supply the sounds to play before / after the announcements. Haven't tried changing the voice yet, but for now this is it.

Thanks for the assistance, great idea.

@nimroddolev
Copy link
Owner

Hey @dbullendsl, I added a new FFmpeg Arguments parameter to the chime_tts.say and chime_tts.say_url services, allowing you to list the conversion parameters you want to use for an FFmpeg conversion on the generated audio:

Screenshot 2023-12-19 at 15 21 34

I created a discussion here, and it would be great if you could please test it out and let me know if it works for your use case.

I created a new beta version with the changes. Please follow these steps to install it:

  1. Open the Chime TTS repository in HACS
  2. Click on the button in the top right
  3. Select the ↻ Redownload option
  4. Enable the Show beta versions option
  5. Select version v0.10.2-beta1 from the updated version drop-down list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants