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
181 stars 13 forks source link

chime_tts.say - Error when cache option is enabled. #105

Closed rhyswaywood closed 5 months ago

rhyswaywood commented 6 months ago

System Health details

System Information

version core-2024.4.0
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.20-haos
arch x86_64
timezone Australia/Perth
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 4604 Installed Version | 1.34.0 Stage | running Available Repositories | 1403 Downloaded Repositories | 32
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | June 30, 2024 at 8:00 AM relayer_connected | true relayer_region | ap-southeast-1 remote_enabled | true remote_connected | true alexa_enabled | false google_enabled | true remote_server | ap-southeast-1-1.ui.nabu.casa certificate_status | ready instance_id | 8dda903fdfef472c96b8ec807a70c988 can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 12.1 -- | -- update_channel | stable supervisor_version | supervisor-2024.03.1 agent_version | 1.6.0 docker_version | 24.0.7 disk_total | 30.8 GB disk_used | 12.4 GB healthy | true supported | true board | ova supervisor_api | ok version_api | ok installed_addons | Terminal & SSH (9.10.0), File editor (5.8.0), Spotify Connect (0.13.0), Mosquitto broker (6.4.0), Zigbee2MQTT (1.36.1-1), Node-RED (17.0.11), Matter Server (5.5.1), eufy-security-ws (1.8.0-2), ESPHome (2024.3.1), Assist Microphone (2.2.3), Samba share (12.3.1), openWakeWord (1.10.0), snapcast-server (dev), Music Assistant BETA (2.0.0b129), PS5 MQTT (1.3.3)
Dashboards dashboards | 4 -- | -- resources | 17 views | 25 mode | storage
Recorder oldest_recorder_run | March 28, 2024 at 2:44 AM -- | -- current_recorder_run | April 4, 2024 at 10:03 AM estimated_db_size | 363.66 MiB database_engine | sqlite database_version | 3.44.2
Spotify api_endpoint_reachable | ok -- | --

Checklist

Describe the issue

When using the chime_tts.say service I get an error if I enable the cache option, but no error if I disable the cache option.

Reproduction steps

This service call succeeds and audio plays:

service: chime_tts.say
target:
  entity_id: media_player.homepod_mini
data:
  chime_path: bright
  offset: 450
  final_delay: 0
  tts_speed: 100
  tts_pitch: 0
  volume_level: 0.7
  message: Test audio message
  tts_platform: cloud

This service call fails:

service: chime_tts.say
target:
  entity_id: media_player.homepod_mini
data:
  chime_path: bright
  offset: 450
  final_delay: 0
  tts_speed: 100
  tts_pitch: 0
  volume_level: 0.7
  message: Test audio message
  tts_platform: cloud
  cache: true

The only difference is the cache option is enabled.

Debug logs

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/chime_tts/__init__.py:1267
integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 10:13:46 AM (6 occurrences)
Last logged: 10:43:24 AM

[139794035877184] Error handling message: Unknown error (unknown_error) Rhys from 127.0.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 794, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1650, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 454, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 506, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 536, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 504, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 733, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 696, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2542, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2579, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/chime_tts/__init__.py", line 116, in async_say
    result = await queue.add_to_queue(async_say_execute, service, is_say_url)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/chime_tts/queue_manager.py", line 33, in async_process_queue
    result = await asyncio.wait_for(
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
  File "/config/custom_components/chime_tts/__init__.py", line 138, in async_say_execute
    audio_dict = await async_get_playback_audio_path(params, options)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/chime_tts/__init__.py", line 716, in async_get_playback_audio_path
    audio_dict = await async_get_cached_audio_data(hass, filepath_hash)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/chime_tts/__init__.py", line 1287, in async_get_cached_audio_data
    audio_dict = await async_retrieve_data(hass, filepath_hash)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/chime_tts/__init__.py", line 1267, in async_retrieve_data
    return _data[DATA_STORAGE_KEY].get(key, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'

Logger: homeassistant.helpers.script.websocket_api_script
Source: helpers/script.py:504
First occurred: 10:13:46 AM (6 occurrences)
Last logged: 10:43:24 AM

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'NoneType' object has no attribute 'get'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 504, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 733, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 696, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2542, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2579, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/chime_tts/__init__.py", line 116, in async_say
    result = await queue.add_to_queue(async_say_execute, service, is_say_url)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/chime_tts/queue_manager.py", line 33, in async_process_queue
    result = await asyncio.wait_for(
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
  File "/config/custom_components/chime_tts/__init__.py", line 138, in async_say_execute
    audio_dict = await async_get_playback_audio_path(params, options)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/chime_tts/__init__.py", line 716, in async_get_playback_audio_path
    audio_dict = await async_get_cached_audio_data(hass, filepath_hash)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/chime_tts/__init__.py", line 1287, in async_get_cached_audio_data
    audio_dict = await async_retrieve_data(hass, filepath_hash)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/chime_tts/__init__.py", line 1267, in async_retrieve_data
    return _data[DATA_STORAGE_KEY].get(key, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'

Logger: homeassistant.core
Source: core.py:2558
First occurred: 10:30:01 AM (2 occurrences)
Last logged: 10:30:18 AM

Error executing service: <ServiceCall media_player.play_media (c:01HTKF1TGSRDF9HSNM07X2MSD0): entity_id=['media_player.homepod_mini'], extra=, media_type=music, media_id=media-source://media_source/local/casita_media/sounds/temp/chime_tts/ij5fk91i.mp3>
Error executing service: <ServiceCall media_player.play_media (c:01HTKF2B5SYXMWSA6MRXAQX2HQ): entity_id=['media_player.homepod_mini'], extra=, media_type=music, media_id=media-source://media_source/local/casita_media/sounds/temp/chime_tts/icb2kvpz.mp3>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 2558, in _run_service_call_catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 2579, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 971, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1043, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/apple_tv/media_player.py", line 346, in async_play_media
    await self.atv.stream.stream_file(media_id)
  File "/usr/local/lib/python3.12/site-packages/pyatv/core/facade.py", line 371, in stream_file
    await self.relay("stream_file")(
  File "/usr/local/lib/python3.12/site-packages/pyatv/protocols/raop/__init__.py", line 360, in stream_file
    audio_file = await open_source(
                 ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyatv/protocols/raop/audio_source.py", line 729, in open_source
    return await InternetSource.open(source, sample_rate, channels, sample_size)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyatv/protocols/raop/audio_source.py", line 597, in open
    stream_generator = await loop.run_in_executor(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/miniaudio.py", line 1268, in stream_any
    raise DecodeError("failed to init decoder", result)
miniaudio.DecodeError: ('failed to init decoder', -1)

This error originated from a custom integration.

Logger: custom_components.chime_tts
Source: custom_components/chime_tts/__init__.py:304
integration: Chime TTS (documentation, issues)
First occurred: 10:13:07 AM (1 occurrences)
Last logged: 10:13:07 AM

Timed out waiting for playback to complete

Diagnostics dump

home-assistant_chime_tts_2024-04-04T02-18-27.999Z.log

pepe59 commented 6 months ago

Similar problem here

Settings

service: chime_tts.say
target:
  entity_id: media_player.picore_tts
data:
  chime_path: ding_dong
  offset: 450
  tts_speed: 106
  tts_pitch: 0
  volume_level: 0.74
  message: Dobré ráno
  tts_platform: cloud

warning

Tato chyba pochází z vlastní integrace.

Logger: custom_components.chime_tts
Zdroj: custom_components/chime_tts/__init__.py:304
integrace: Chime TTS (dokumentace, problémy)
První výskyt: 22:15:20 (1 výskyty)
Naposledy logováno: 22:15:20

Timed out waiting for playback to complete

Everything plays correctly

nimroddolev commented 5 months ago

Thanks @rhyswaywood & @pepe59 for bringing this to my attention.

I just released a new beta which hopefully addresses the issue. I'd appreciate it if you could please install the new version and let me know if it's working for you, as well as any other feedback you might have 👍

To install the new beta version:

  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 (it may take a moment to update the list)
  5. Select version v1.0.1-beta2 from the updated version drop-down list
  6. Restart Home Assistant
pepe59 commented 5 months ago

I installed v1.0.1-beta2. The warning is still there just changed init.py:303

Tato chyba pochází z vlastní integrace.

Logger: custom_components.chime_tts
Zdroj: custom_components/chime_tts/__init__.py:303
integrace: Chime TTS (dokumentace, problémy)
První výskyt: 12:27:51 (2 výskyty)
Naposledy logováno: 12:29:49

Timed out waiting for playback to complete
nimroddolev commented 5 months ago

@pepe59, I am not sure from your messages whether you're experiencing an issue besides receiving this warning (which just tells us that the speaker took longer than expected to complete playback). Are you having any issues hearing cached/uncached Chime TTS announcements?

For comparison: it appears that @rhyswaywood experienced an error that prevented playback.

pepe59 commented 5 months ago

With this setting, playback works fine (cache: true/ false) there is only the warning that was not in 0.13.0

service: chime_tts.say
target:
  entity_id: media_player.picore_tts
data:
  chime_path: bells
  offset: 450
  final_delay: 0
  tts_speed: 106
  tts_pitch: 0
  volume_level: 0.76
  message: Test test test
  tts_platform: cloud
  cache: true
nimroddolev commented 5 months ago

Ok great, thanks @pepe59 🙏

rhyswaywood commented 5 months ago

Thank you @nimroddolev, I have installed v1.0.1-beta2 and the cache works for me now.

nimroddolev commented 5 months ago

Great, happy to hear the fix is working for you 👍