home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.69k stars 30.82k forks source link

Error on load #123597

Closed paducz closed 3 months ago

paducz commented 3 months ago

The problem

The new Elevenlabs TTS does not work via actions/automations..I am getting the error message bellow

Logger: homeassistant.components.tts Source: components/tts/init.py:1063 integration: Text-to-speech (TTS) (documentation, issues) First occurred: 12:26:20 (36 occurrences) Last logged: 15:04:22

Error on load tts: 7063c57485b24e5ff927013c30e5c93c7a7c3eeben-_tts.elevenlabs not in cache!

What version of Home Assistant Core has the issue?

2024.8.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

ElevenLabs text-to-speech

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 3 months ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (tts) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `tts` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign tts` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


tts documentation tts source (message by IssueLinks)

joostlek commented 3 months ago

Can you share full logs?

home-assistant[bot] commented 3 months ago

Hey there @sorgfresser, mind taking a look at this issue as it has been labeled with an integration (elevenlabs) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `elevenlabs` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign elevenlabs` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


elevenlabs documentation elevenlabs source (message by IssueLinks)

paducz commented 3 months ago

Can you please navigate me where to find full log? This is the only information I found in system logs

paducz commented 3 months ago

When using the TTS manually via Media sources, it works well...but it does not work when using via automation..

Also this issue is related only to Eleventlabs TTS, another ones (such as google TTS) works well

paducz commented 3 months ago

After enabling debug mode I got this:

2024-08-11 16:27:21.688 DEBUG (MainThread) [homeassistant.components.elevenlabs.tts] Getting TTS audio for a 2024-08-11 16:27:21.688 DEBUG (MainThread) [homeassistant.components.elevenlabs.tts] Options: {} 2024-08-11 16:27:21.707 ERROR (MainThread) [homeassistant.components.tts] Error on load tts: 86f7e437faa5a7fce15d1ddcb9eaeaea377667b8en-_tts.elevenlabs not in cache!

sorgfresser commented 3 months ago

Hi @paducz !

This is related to https://github.com/home-assistant/core/blob/dev/homeassistant/components/elevenlabs/tts.py#L103

We set the voice in the supported options, but somehow this is not picked up in the UI (is this normal @joostlek?).

Otherwise we should default to the default voice in this case if options does not have the specific key. You can add the voice id in the automations.yaml (or configurations.yaml) manually under action:data:options:voice like so

- id: 'yourid'
  alias: Autom
  description: ''
  trigger:
  - platform: time
    at: 01:07:00
  condition: []
  action:
  - action: tts.speak
    metadata: {}
    data:
      cache: false
      message: Hello world
      media_player_entity_id: entity_id
      language: de
      options:
        voice: voice_id
    target:
      device_id: target_id
  mode: single

You can obtain the voice id by running a tts manually via Media Sources using debug logging (it will be in the options dict)

sorgfresser commented 3 months ago

Created a PR, thanks for raising this!

paducz commented 3 months ago

Thank you

paducz commented 3 months ago

home-assistant_elevenlabs.log I used the voice as you suggested, but getting the following error now:

2024-08-12 11:06:18.653 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback SpeechManager._async_get_tts_audio.<locals>.handle_error(<Task cancell...nit__.py:745>>) at /usr/src/homeassistant/homeassistant/components/tts/__init__.py:811 (None) Traceback (most recent call last): File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/usr/src/homeassistant/homeassistant/components/tts/__init__.py", line 813, in handle_error if audio_task.exception(): ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/tts/__init__.py", line 755, in get_tts_data extension, data = await engine_instance.internal_async_get_tts_audio( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/tts/__init__.py", line 489, in internal_async_get_tts_audio return await self.async_get_tts_audio( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/elevenlabs/tts.py", line 110, in async_get_tts_audio bytes_combined = b"".join([byte_seg async for byte_seg in audio]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/elevenlabs/text_to_speech/client.py", line 648, in convert async with self._client_wrapper.httpx_client.stream( File "/usr/local/lib/python3.12/contextlib.py", line 210, in __aenter__ return await anext(self.gen) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/elevenlabs/core/http_client.py", line 440, in stream async with self.httpx_client.stream( File "/usr/local/lib/python3.12/contextlib.py", line 210, in __aenter__ return await anext(self.gen) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1617, in stream response = await self.send( ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1661, in send response = await self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1689, in _send_handling_auth response = await self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1726, in _send_handling_redirects response = await self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1763, in _send_single_request response = await transport.handle_async_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 373, in handle_async_request resp = await self._pool.handle_async_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 216, in handle_async_request raise exc from None File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 196, in handle_async_request response = await connection.handle_async_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection.py", line 101, in handle_async_request return await self._connection.handle_async_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 143, in handle_async_request raise exc File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 113, in handle_async_request ) = await self._receive_response_headers(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 186, in _receive_response_headers event = await self._receive_event(timeout=timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 224, in _receive_event data = await self._network_stream.read( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpcore/_backends/anyio.py", line 35, in read return await self._stream.receive(max_bytes=max_bytes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/anyio/streams/tls.py", line 205, in receive data = await self._call_sslobject_method(self._ssl_object.read, max_bytes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/anyio/streams/tls.py", line 147, in _call_sslobject_method data = await self.transport_stream.receive() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 1142, in receive await self._protocol.read_event.wait() File "/usr/local/lib/python3.12/asyncio/locks.py", line 212, in wait await fut asyncio.exceptions.CancelledError

paducz commented 3 months ago

Looks like the problem is caused by the message length...the one I am using has 807 characters...shorter like 167 chars works well

sorgfresser commented 3 months ago

Interesting! Sounds like a separate issue to me. I'll take a look. Is this happening with a text that is 807 characters in an automation or when done manually (not that it is related to either of them necessarily, it might as well be both)?

paducz commented 3 months ago

Yes, this will be a separate issue...short messages works well. This issue occurs only in automation. When I tried the same message manually via Media, It works without any issue

sorgfresser commented 3 months ago

I sadly can't reproduce it. I tried 430, 860 and 1720 characters, all of them worked in an automation for me. Are you able to share the exact text / automation yaml (without voice ids etc. if you don't want to share them here) that results in an error?

paducz commented 3 months ago

Sure, for example (generated by chatgpt): In the quiet of dawn, as the sun starts to glow, Awakens a helper that most don’t yet know. A silent companion, both patient and kind, A home assistant, with tasks well-aligned. With whispers of code and signals unseen, It weaves through our lives in spaces between. Lights flicker on with a soft-spoken cue, The coffee pot brews, and the day feels renewed. “Good morning!” it chimes in a voice warm and clear, Promising comfort and banishing fear. Thermostats shift to the perfect degree, Curtains draw back, revealing the sea. In busy routines, amidst hustle and grind, Devices and gadgets are perfectly timed. Appointments are made, reminders are set, In the dance of the day, no step is forget. But more than its tasks, it brings peace of mind, A comfort and ease, a sense well-defined. For in every command, each whispered request, Lies a touch of the future, in our homes manifest. Evening descends, stars twinkle above, Home assistant glows with a digital love. Soft lullabies play as the world starts to rest, In the heartbeat of homes, it feels truly blessed. So here’s to the friend who’s unseen yet near, Guiding our homes through each month and each year. In its silent embrace, our lives find their rhyme, A symphony gentle, transcending through time.

paducz commented 3 months ago
action: tts.speak
target:
  entity_id: tts.elevenlabs
data:
  cache: true
  media_player_entity_id: media_player.airmusic
  message: >-
    In the quiet of dawn, as the sun starts to glow, Awakens a helper that most
    don’t yet know. A silent companion, both patient and kind, A home assistant,
    with tasks well-aligned. With whispers of code and signals unseen, It weaves
    through our lives in spaces between. Lights flicker on with a soft-spoken
    cue, The coffee pot brews, and the day feels renewed. “Good morning!” it
    chimes in a voice warm and clear, Promising comfort and banishing fear.
    Thermostats shift to the perfect degree, Curtains draw back, revealing the
    sea. In busy routines, amidst hustle and grind, Devices and gadgets are
    perfectly timed. Appointments are made, reminders are set, In the dance of
    the day, no step is forget. But more than its tasks, it brings peace of
    mind, A comfort and ease, a sense well-defined. For in every command, each
    whispered request, Lies a touch of the future, in our homes manifest.
    Evening descends, stars twinkle above, Home assistant glows with a digital
    love. Soft lullabies play as the world starts to rest, In the heartbeat of
    homes, it feels truly blessed. So here’s to the friend who’s unseen yet
    near, Guiding our homes through each month and each year. In its silent
    embrace, our lives find their rhyme, A symphony gentle, transcending through
    time.
  language: en
  options:
    voice: voice_id
enabled: true
paducz commented 3 months ago

to be precise, it is a step in a script running by an automation

paducz commented 3 months ago

I have next observation - if the model is "eleven_turbo_v2_5" all is good, but when I changed it to eleven_multilingual_v2, I got the same error as above.

paducz commented 3 months ago

I think this is more likely issue in TTS, if you agree I will close this issue and create a new one for TTS

paducz commented 3 months ago

Rasing new issue for tts module https://github.com/home-assistant/core/issues/123845