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
196 stars 14 forks source link

Audio_conversion: "-filter:a volume=0.8" overwrites the original chime file #128

Closed DanDixon closed 5 months ago

DanDixon commented 6 months ago

System Health details

System Information

version core-2024.5.1
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.2
os_name Linux
os_version 6.6.25-haos
arch x86_64
timezone America/Los_Angeles
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 4997 Installed Version | 1.34.0 Stage | running Available Repositories | 1425 Downloaded Repositories | 69 HACS Data | ok
AccuWeather can_reach_server | ok -- | -- remaining_requests | 8
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | May 31, 2024 at 5:00 PM relayer_connected | true relayer_region | us-east-1 remote_enabled | true remote_connected | true alexa_enabled | false google_enabled | true remote_server | us-east-1-7.ui.nabu.casa certificate_status | ready instance_id | b8337d89d1654680a2050a4ab1c65281 can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 12.2 -- | -- update_channel | stable supervisor_version | supervisor-2024.04.4 agent_version | 1.6.0 docker_version | 25.0.5 disk_total | 97.7 GB disk_used | 39.8 GB healthy | true supported | true board | ova supervisor_api | ok version_api | ok installed_addons | File editor (5.8.0), Studio Code Server (5.15.0), Mosquitto broker (6.4.0), Home Assistant Google Drive Backup (0.112.1), Hass Calendar Addon (0.500), Terminal & SSH (9.13.0), PS5 MQTT (1.3.3), Samba share (12.3.1), Zigbee2MQTT (1.37.0-1)
Dashboards dashboards | 19 -- | -- resources | 46 views | 265 mode | storage
Miele component_version | 2024.3.0 -- | -- reach_miele_cloud | ok
Recorder oldest_recorder_run | April 25, 2024 at 11:04 PM -- | -- current_recorder_run | May 3, 2024 at 8:28 PM estimated_db_size | 2210.27 MiB database_engine | sqlite database_version | 3.44.2
Spotify api_endpoint_reachable | ok -- | --

Checklist

Describe the issue

When I use audio_conversion: "-filter:a volume=0.8," it overwrites my notify.mp3 file slowly, making it quieter and quieter until it's totally silent.

chimefile: media/sounds/notify.mp3
say: Start------
delay: -800

service: chime_tts.say_url
data:
  cache: true
  tts_platform: tts.openai_tts
  message:
    - chime: "{{chimefile}}"
      audio_conversion: "-filter:a volume=0.8"
    - tts: "{{say}}"
      offset: "{{delay}}"
response_variable: chime_tts

Using audio_conversion: volume 80% doesn't seem to cause this. (see next reply, this generates an error instead)

Here's the event data from folder_watcher that shows the file being overwritten:

  event:
    event_type: folder_watcher
    data:
      event_type: moved
      path: /media/sounds/notify_converted.mp3
      file: notify_converted.mp3
      folder: /media/sounds
      dest_path: /media/sounds/notify.mp3
      dest_file: notify.mp3
      dest_folder: /media/sounds

Reproduction steps

I'm running v1.1.0-beta4

This didn't happen with older versions of Chime TTS.

As described above, using:

audio_conversion: "-filter:a volume=0.8"

Will cause the original chime mp3 file to be overwritten with notify_converted.mp3

Debug logs

2024-05-04 12:36:04.984 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say URL Called. Version v1.1.0-beta4 -----
2024-05-04 12:36:04.984 DEBUG (MainThread) [custom_components.chime_tts.queue_manager] Adding service call to queue
2024-05-04 12:36:04.990 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] ----- General Parameters -----
2024-05-04 12:36:04.990 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * entity_ids = []
2024-05-04 12:36:04.990 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * cache = True
2024-05-04 12:36:04.990 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * offset = 450.0
2024-05-04 12:36:04.990 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * final_delay = 0.0
2024-05-04 12:36:04.990 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * media_players_array = []
2024-05-04 12:36:04.990 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * message = [{'chime': 'media/sounds/notify.mp3', 'audio_conversion': '-filter:a volume=0.8'}, {'tts': 'Start------', 'offset': -800}]
2024-05-04 12:36:04.990 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * tts_platform = tts.openai_tts
2024-05-04 12:36:04.990 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * tts_speed = 100.0
2024-05-04 12:36:04.991 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * tts_pitch = 0
2024-05-04 12:36:04.991 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * announce = False
2024-05-04 12:36:04.991 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * fade_audio = False
2024-05-04 12:36:04.991 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * volume_level = -1
2024-05-04 12:36:04.991 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * join_players = False
2024-05-04 12:36:04.991 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * unjoin_players = False
2024-05-04 12:36:04.991 DEBUG (MainThread) [custom_components.chime_tts] *** Checking Chime TTS audio cache ***
2024-05-04 12:36:05.009 WARNING (MainThread) [custom_components.chime_tts.helpers.filesystem] Unable to create public URL - File: '/media/chime_tts/js656t3q.mp3' is outside the public folder.
2024-05-04 12:36:05.010 DEBUG (MainThread) [custom_components.chime_tts] ...no cached audio found
2024-05-04 12:36:05.012 DEBUG (MainThread) [custom_components.chime_tts] - Retrieving audio from path: "/media/sounds/notify.mp3"...
2024-05-04 12:36:05.012 DEBUG (MainThread) [custom_components.chime_tts] - Performing FFmpeg audio conversion of audio file...
2024-05-04 12:36:05.012 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] Converting audio: "ffmpeg -i /media/sounds/notify.mp3 -filter:a volume=0.8 /media/sounds/notify_converted.mp3"
2024-05-04 12:36:05.408 DEBUG (MainThread) [custom_components.chime_tts] ...audio retrieved. Duration: 1.536s
2024-05-04 12:36:05.409 DEBUG (MainThread) [custom_components.chime_tts] - Attempting to retrieve TTS audio from cache...
2024-05-04 12:36:05.448 DEBUG (MainThread) [custom_components.chime_tts] - Retrieving audio from path: "/media/temp/chime_tts/anv1wcns.mp3"...
2024-05-04 12:36:05.667 DEBUG (MainThread) [custom_components.chime_tts] ...audio retrieved. Duration: 0.624s
2024-05-04 12:36:05.668 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] Performing overlay of -800.0ms
2024-05-04 12:36:05.671 DEBUG (MainThread) [custom_components.chime_tts] - Saving mp3 file to folder: /media/chime_tts/...
2024-05-04 12:36:05.892 DEBUG (MainThread) [custom_components.chime_tts.helpers.filesystem] - File saved to path: /media/chime_tts/z55qqhtf.mp3
2024-05-04 12:36:06.161 DEBUG (MainThread) [custom_components.chime_tts] - Saving data to chime_tts storage:
2024-05-04 12:36:06.161 DEBUG (MainThread) [custom_components.chime_tts] - key: "2c195657b2da37af1ed43b0d030f84f8eec1e5717d87b48463c9cc23feca5a1b"
2024-05-04 12:36:06.161 DEBUG (MainThread) [custom_components.chime_tts] - value: "{'public_path': '/media/chime_tts/z55qqhtf.mp3', 'audio_duration': 1.536, 'local_path': None}"
2024-05-04 12:36:06.305 WARNING (MainThread) [custom_components.chime_tts.helpers.filesystem] Unable to create public URL - File: '/media/chime_tts/z55qqhtf.mp3' is outside the public folder.
2024-05-04 12:36:06.305 DEBUG (MainThread) [custom_components.chime_tts] - Chime TTS audio generated:
2024-05-04 12:36:06.305 DEBUG (MainThread) [custom_components.chime_tts] - audio_duration = 1.536
2024-05-04 12:36:06.305 DEBUG (MainThread) [custom_components.chime_tts] - local_path = None
2024-05-04 12:36:06.305 DEBUG (MainThread) [custom_components.chime_tts] - public_path = None
2024-05-04 12:36:06.305 DEBUG (MainThread) [custom_components.chime_tts] - media_content_id = "media-source://media_source/local/chime_tts/z55qqhtf.mp3"
2024-05-04 12:36:06.306 DEBUG (MainThread) [custom_components.chime_tts] Final URL = None
2024-05-04 12:36:06.306 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say URL Completed in 1.32 s -----

Diagnostics dump

No response

DanDixon commented 6 months ago

I think the reason that audio_conversion: volume 80% doesn't overwrite the file is because I'm getting this error (just realized):

2024-05-06 17:42:11.128 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] Converting audio: "ffmpeg -i /media/sounds/notify.mp3 volume 80% /media/sounds/notify_converted.mp3"
2024-05-06 17:42:11.266 ERROR (MainThread) [custom_components.chime_tts.helpers.helpers] FFmpeg conversion failed.

Yeah, just confirmed that the volume command isn't changing the volume of the chime.

Full logs for this run:

2024-05-06 17:42:11.083 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say URL Called. Version v1.1.0-beta4 -----
2024-05-06 17:42:11.083 DEBUG (MainThread) [custom_components.chime_tts.queue_manager] Adding service call to queue
2024-05-06 17:42:11.093 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] ----- General Parameters -----
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * entity_ids = []
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * cache = True
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * offset = 450.0
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * final_delay = 0.0
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * media_players_array = []
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * message = [{'chime': 'media/sounds/notify.mp3', 'audio_conversion': 'volume 80%'}, {'tts': 'Start------', 'offset': -800}]
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * tts_platform = tts.openai_tts
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * tts_speed = 100.0
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * tts_pitch = 0
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * announce = False
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * fade_audio = False
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * volume_level = -1
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * join_players = False
2024-05-06 17:42:11.095 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] * unjoin_players = False
2024-05-06 17:42:11.096 DEBUG (MainThread) [custom_components.chime_tts] *** Checking Chime TTS audio cache ***
2024-05-06 17:42:11.126 WARNING (MainThread) [custom_components.chime_tts.helpers.filesystem] Unable to create public URL - File: '/media/chime_tts/dsnq9emr.mp3' is outside the public folder.
2024-05-06 17:42:11.127 DEBUG (MainThread) [custom_components.chime_tts] ...no cached audio found
2024-05-06 17:42:11.128 DEBUG (MainThread) [custom_components.chime_tts] - Retrieving audio from path: "/media/sounds/notify.mp3"...
2024-05-06 17:42:11.128 DEBUG (MainThread) [custom_components.chime_tts] - Performing FFmpeg audio conversion of audio file...
2024-05-06 17:42:11.128 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] Converting audio: "ffmpeg -i /media/sounds/notify.mp3 volume 80% /media/sounds/notify_converted.mp3"
2024-05-06 17:42:11.266 ERROR (MainThread) [custom_components.chime_tts.helpers.helpers] FFmpeg conversion failed.
2024-05-06 17:42:11.469 DEBUG (MainThread) [custom_components.chime_tts] ...audio retrieved. Duration: 1.536s
2024-05-06 17:42:11.470 DEBUG (MainThread) [custom_components.chime_tts] - Attempting to retrieve TTS audio from cache...
2024-05-06 17:42:11.491 DEBUG (MainThread) [custom_components.chime_tts] - Retrieving audio from path: "/media/temp/chime_tts/kkjjpmcg.mp3"...
2024-05-06 17:42:11.717 DEBUG (MainThread) [custom_components.chime_tts] ...audio retrieved. Duration: 0.672s
2024-05-06 17:42:11.718 DEBUG (MainThread) [custom_components.chime_tts.helpers.helpers] Performing overlay of -800.0ms
2024-05-06 17:42:11.718 DEBUG (MainThread) [custom_components.chime_tts] - Saving mp3 file to folder: /media/chime_tts/...
2024-05-06 17:42:11.939 DEBUG (MainThread) [custom_components.chime_tts.helpers.filesystem] - File saved to path: /media/chime_tts/t66ozgz0.mp3
2024-05-06 17:42:12.187 DEBUG (MainThread) [custom_components.chime_tts] - Saving data to chime_tts storage:
2024-05-06 17:42:12.187 DEBUG (MainThread) [custom_components.chime_tts] - key: "374f880cb82a0ac6180a79e9e1f64ce0d015c1f4a78d1405aeeb438dd356d048"
2024-05-06 17:42:12.187 DEBUG (MainThread) [custom_components.chime_tts] - value: "{'public_path': '/media/chime_tts/t66ozgz0.mp3', 'audio_duration': 1.536, 'local_path': None}"
2024-05-06 17:42:12.219 WARNING (MainThread) [custom_components.chime_tts.helpers.filesystem] Unable to create public URL - File: '/media/chime_tts/t66ozgz0.mp3' is outside the public folder.
2024-05-06 17:42:12.219 DEBUG (MainThread) [custom_components.chime_tts] - Chime TTS audio generated:
2024-05-06 17:42:12.219 DEBUG (MainThread) [custom_components.chime_tts] - audio_duration = 1.536
2024-05-06 17:42:12.219 DEBUG (MainThread) [custom_components.chime_tts] - local_path = None
2024-05-06 17:42:12.219 DEBUG (MainThread) [custom_components.chime_tts] - public_path = None
2024-05-06 17:42:12.219 DEBUG (MainThread) [custom_components.chime_tts] - media_content_id = "media-source://media_source/local/chime_tts/t66ozgz0.mp3"
2024-05-06 17:42:12.219 DEBUG (MainThread) [custom_components.chime_tts] Final URL = None
2024-05-06 17:42:12.219 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say URL Completed in 1.13 s -----

Note: I'm also getting this warning:

Unable to create public URL - File: '/media/chime_tts/t66ozgz0.mp3' is outside the public folder.

But I don't need that file to be public, and the notifications work despite this warning.

nimroddolev commented 6 months ago

Thanks Dan.

These issues should be addressed in v1.1.0-beta5. Can you pleease upgrade and let me know if the issue is resolved?

DanDixon commented 5 months ago

Yes! This seems to be fixed. Thank you! (and sorry for the delay)

nimroddolev commented 5 months ago

Great! Thank you for testing the beta version.

nimroddolev commented 5 months ago

The fix has been included in the latest stable release, v1.1.0.