hasscc / hass-edge-tts

🗣️ Microsoft Edge TTS for Home Assistant, no need for app_key
357 stars 62 forks source link

MS TTS report an error after restart HA #15

Closed info-path closed 2 years ago

info-path commented 2 years ago

Hello, I have an issue with MS TTS. After restart HA it reports an error and stops working. After starting HA the MS TTS speaks once but when the template is reloaded (after click on reload template button) TTS stops and reports an error in the log. Other TTS voices work fine.

HA: 2022.8.2

my tts config:

# Microsoft Edge TTS
- platform: edge_tts
  service_name: vlasta # service: tts.xiaomo_say
  language: cs-CZ-VlastaNeural
  rate: +5%
  volume: 100.0

tested automation:

- alias: Test MS tts after start or reload template
  trigger:
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
      id: "reload"
  action:
    - service: tts.vlasta  # tts.google_cloud_say
      target:
        entity_id:
          - media_player.google_nest_hub
      data_template:
        cache: false
        message: "Template was reloaded!"

LOG:

Logger: homeassistant.components.automation.test_ms_tts_after_start_or_reload_template
Source: custom_components/edge_tts/tts.py:173
Integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 00:33:03 (2 occurrences)
Last logged: 00:33:03

Test MS tts after start or reload template: Error executing script. Unexpected error for call_service at pos 1: 'text'
While executing automation automation.test_ms_tts_after_start_or_reload_template
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 447, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 680, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/components/tts/__init__.py", line 218, in async_say_handle
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 676, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 713, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/cast/media_player.py", line 628, in async_play_media
    sourced_media = await media_source.async_resolve_media(
  File "/usr/src/homeassistant/homeassistant/components/media_source/__init__.py", line 146, in async_resolve_media
    return await item.async_resolve()
  File "/usr/src/homeassistant/homeassistant/components/media_source/models.py", line 90, in async_resolve
    return await self.async_media_source().async_resolve_media(self)
  File "/usr/src/homeassistant/homeassistant/components/tts/media_source.py", line 62, in async_resolve_media
    url = await manager.async_get_url_path(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/tts/__init__.py", line 419, in async_get_url_path
    filename = await self.async_get_tts_audio(
  File "/usr/src/homeassistant/homeassistant/components/tts/__init__.py", line 439, in async_get_tts_audio
    extension, data = await provider.async_get_tts_audio(message, language, options)
  File "/config/custom_components/edge_tts/tts.py", line 173, in async_get_tts_audio
    async for i in tts.run(
  File "/usr/local/lib/python3.10/site-packages/edge_tts/communicate.py", line 340, in run
    text = metadata["Metadata"][0]["Data"]["text"]["Text"]
KeyError: 'text'

Any idea what could be this error?

info-path commented 2 years ago

With the latest add-on update, the problem disappeared. It's already working!