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

Occasionally getting Message YAML parsing errors #85

Closed DanDixon closed 7 months ago

DanDixon commented 9 months ago

Checklist

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

I'm using v0.13.1-beta3

Now, every ~20 times or so, it's fairly infrequent (it's happened 7 times now), the text converted into speech goes something like this: "type: chime path: media/notify.mp3, audio_conversion: "-filter:a volume=0.8", message: (and then the actual message too)"

Logger: custom_components.chime_tts.helpers
Source: custom_components/chime_tts/helpers.py:162
Integration: Chime TTS ([documentation](https://www.github.com/nimroddolev/chime_tts/wiki), [issues](https://github.com/nimroddolev/chime_tts/issues))
First occurred: February 6, 2024 at 11:42:38 PM (7 occurrences)
Last logged: 12:45:02 PM

Message YAML parsing error at line 1, column 206: while parsing a flow mapping in "<unicode string>", line 1, column 93: ... sion': '-filter:a volume=0.8'}, {'type': 'tts', 'message': 'At t ... ^ expected ',' or '}', but got '<scalar>' in "<unicode string>", line 1, column 206: ... s out, whispers, "Goodnight, I\'ll keep the date."', 'delay': -800}] ^

Since posting about my last issue, I've switched to using OpenAI's TTS instead of Google. Here's the latest service call:

service: chime_tts.say
data:
  tts_platform: openai_tts
  cache: true
  message:
    - type: chime
      path: |
        {% if (not say.startswith("-")) %} 
          {% if states['input_boolean.dog_mode'].state == 'on' %}
          media/ding-sound.mp3
          {% else %} 
          media/notify.mp3
          {% endif %}
        {% endif %}
      audio_conversion: "-filter:a volume=0.8"
    - type: tts
      message: "{{ say }}"
      delay: -800
target:
  entity_id: media_player.minis_linked
enabled: true
alias: "Call a service 'Chime TTS: Say' on Minis Linked - OpenAI"

Any thoughts or things to try? It usually works; unfortunately, it's not clearly reproducible.

Describe the solution you'd like

Not getting those errors :)

Describe alternatives you've considered

I'm using the ability to overlap the chime and the voice mp3s, so using the simpler features might fix this.

Additional context

FYI, it just happened with chime_tts.say_url also.

nimroddolev commented 9 months ago

Hey Dan,

Please try to catch the problem when you have debug logging enabled for Chime TTS:

  1. Turn on debug logging:

    service: logger.set_level
    data:
    custom_components.chime_tts: debug
  2. Call chime_tts.say and reproduce the issue.

  3. Check your log messages in Home Assistant:

    https://{YOUR_HOME_ASSISTANT_ADDRESS}:8123/config/logs?filter=chime_tts

    and click LOAD FULL LOGS

DanDixon commented 9 months ago

I figured out how to make it reproducible. Looks like it's an issue with embedded quote marks:

I am generating strings with ChatGPT (which is why it was sparatic since every string was different) and noticed all the ones with errors included ' marks.

This causes the YAML error

variables:
  say: >-
    "Dans's test of a YAML error"

This works:

variables:
  say: >-
    "Dan is testing a YAML error"

It also works if you remove the -type: chime section.

service: chime_tts.say_url
data:
  tts_platform: openai_tts
  cache: true
  message:
    - type: chime
      path: "{{chimefile}}"
    - type: tts
      message: "{{say}}"
response_variable: chime_tts

Does that help?

nimroddolev commented 9 months ago

Hi @DanDixon,

Using the latest beta of Chime TTS, v0.13.1-beta5, I was able to call the following script without any issues:

sequence:
  - variables:
      say: "Dan's test of a YAML error"
  - service: chime_tts.say
    data:
      chime_path: soft
      offset: -1700
      message:
        - type: tts
          message: "{{ say }}"
      tts_platform: google_translate
    target:
      entity_id: media_player.kitchen

Please let me know if it is still not working for you.

To install the beta:

  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 v0.13.1-beta5 from the updated version drop-down list
  6. Restart Home Assistant
DanDixon commented 9 months ago

In this version: v0.13.1-beta5

That seemed to fix the issue with apostrophes. Thank you!

data:
  tts_platform: openai_tts
  cache: true
  message:
    - type: chime
      path: "{{chimefile}}"
    - type: tts
      message: "{{say}}"
response_variable: chime_tts

I have to remove:

    - type: chime
      path: "{{chimefile}}"

To get it to work.

In this version: v0.13.1-beta8

You forgot to include a TTS platform. Using google_translate

Even though I'm not using TTS:

service: chime_tts.say_url
data:
  cache: true
  message:
    - type: chime
      path: "{{chimefile}}"
    - type: chime
      path: "{{chimefile}}"
      delay: "{{delay}}"
response_variable: chime_tts

I'm doing this to loop chimes to play multiple times in a row (like the chimes of a clock) (as an aside, a loop property would be great, as I'm using a choose with lots of conditionals for each loop.


Also in v0.13.1-beta8:

This is with the script from above.

Here's a log from that:

2024-02-19 22:00:02.622 DEBUG (MainThread) [custom_components.chime_tts] ----- Chime TTS Say URL Called. Version v0.13.1-beta8 -----
2024-02-19 22:00:02.622 DEBUG (MainThread) [custom_components.chime_tts.queue_manager] Adding service call to queue
2024-02-19 22:00:02.626 DEBUG (MainThread) [custom_components.chime_tts.helpers] ----- General Parameters -----
2024-02-19 22:00:02.626 DEBUG (MainThread) [custom_components.chime_tts.helpers] * entity_ids = []
2024-02-19 22:00:02.627 DEBUG (MainThread) [custom_components.chime_tts.helpers] * cache = True
2024-02-19 22:00:02.627 DEBUG (MainThread) [custom_components.chime_tts.helpers] * offset = 450.0
2024-02-19 22:00:02.627 DEBUG (MainThread) [custom_components.chime_tts.helpers] * final_delay = 0.0
2024-02-19 22:00:02.627 DEBUG (MainThread) [custom_components.chime_tts.helpers] * message = [{'type': 'tts', 'message': "Neon glow at ten, city's span,\nYellow bananas, the cyber night began.", 'delay': -2500}]
2024-02-19 22:00:02.627 DEBUG (MainThread) [custom_components.chime_tts.helpers] * tts_platform = openai_tts
2024-02-19 22:00:02.627 DEBUG (MainThread) [custom_components.chime_tts.helpers] * tts_playback_speed = 100.0
2024-02-19 22:00:02.627 DEBUG (MainThread) [custom_components.chime_tts.helpers] * announce = False
2024-02-19 22:00:02.627 DEBUG (MainThread) [custom_components.chime_tts.helpers] * volume_level = -1.0
2024-02-19 22:00:02.627 DEBUG (MainThread) [custom_components.chime_tts.helpers] * join_players = False
2024-02-19 22:00:02.627 DEBUG (MainThread) [custom_components.chime_tts.helpers] * unjoin_players = False
2024-02-19 22:00:02.627 DEBUG (MainThread) [custom_components.chime_tts] - Attempting to retrieve previously cached audio...
2024-02-19 22:00:02.635 DEBUG (MainThread) [custom_components.chime_tts] - No cached audio found with hash cecf948dcba5e123dbb548554c3826ee179b9412e631a616aa085c79c4151420
2024-02-19 22:00:02.636 DEBUG (MainThread) [custom_components.chime_tts] ...no cached audio found
2024-02-19 22:00:02.636 DEBUG (MainThread) [custom_components.chime_tts] - Attempting to retrieve TTS audio from cache...
2024-02-19 22:00:02.639 DEBUG (MainThread) [custom_components.chime_tts] - No cached audio found with hash 73f6a3affcd84bb592011685187007f2d01d8b534a00bf630fcc91cef7a44bc0
2024-02-19 22:00:02.641 DEBUG (MainThread) [custom_components.chime_tts] ...no cached TTS audio found
2024-02-19 22:00:02.641 DEBUG (MainThread) [custom_components.chime_tts] - Generating new TTS audio with parameters:
2024-02-19 22:00:02.641 DEBUG (MainThread) [custom_components.chime_tts] * tts_platform = 'openai_tts'
2024-02-19 22:00:02.641 DEBUG (MainThread) [custom_components.chime_tts] * message = 'Neon glow at ten, city's span,
2024-02-19 22:00:02.641 DEBUG (MainThread) [custom_components.chime_tts] * tts_playback_speed = 100.0
2024-02-19 22:00:02.641 DEBUG (MainThread) [custom_components.chime_tts] * cache = True
2024-02-19 22:00:02.641 DEBUG (MainThread) [custom_components.chime_tts] * language = 'None'
2024-02-19 22:00:02.641 DEBUG (MainThread) [custom_components.chime_tts] * options = {}
2024-02-19 22:00:04.544 DEBUG (MainThread) [custom_components.chime_tts] ...TTS audio completed in 1903.0990000000002 ms
2024-02-19 22:00:04.544 DEBUG (MainThread) [custom_components.chime_tts] - Saving generated TTS audio to cache...
2024-02-19 22:00:04.743 DEBUG (MainThread) [custom_components.chime_tts.helpers] - File saved to path: /media/sounds/temp/chime_tts/sj3lzwjz.mp3
2024-02-19 22:00:04.743 DEBUG (MainThread) [custom_components.chime_tts] - Saving data to chime_tts storage:
2024-02-19 22:00:04.743 DEBUG (MainThread) [custom_components.chime_tts] - key: "73f6a3affcd84bb592011685187007f2d01d8b534a00bf630fcc91cef7a44bc0"
2024-02-19 22:00:04.744 DEBUG (MainThread) [custom_components.chime_tts] - value: "{'local_path': '/media/sounds/temp/chime_tts/sj3lzwjz.mp3', 'audio_duration': 4.176}"
2024-02-19 22:00:04.771 DEBUG (MainThread) [custom_components.chime_tts] ...TTS audio saved to cache
2024-02-19 22:00:04.771 DEBUG (MainThread) [custom_components.chime_tts] - Saving mp3 file to folder: /media/chime_tts/...
2024-02-19 22:00:04.919 DEBUG (MainThread) [custom_components.chime_tts.helpers] - File saved to path: /media/chime_tts/0kxqp2g6.mp3
2024-02-19 22:00:04.927 DEBUG (MainThread) [custom_components.chime_tts] - No cached audio found with hash cecf948dcba5e123dbb548554c3826ee179b9412e631a616aa085c79c4151420
2024-02-19 22:00:04.942 DEBUG (MainThread) [custom_components.chime_tts] - Saving data to chime_tts storage:
2024-02-19 22:00:04.942 DEBUG (MainThread) [custom_components.chime_tts] - key: "cecf948dcba5e123dbb548554c3826ee179b9412e631a616aa085c79c4151420"
2024-02-19 22:00:04.942 DEBUG (MainThread) [custom_components.chime_tts] - value: "{'public_path': '/media/chime_tts/0kxqp2g6.mp3', 'audio_duration': 4.176}"
DanDixon commented 9 months ago

In v0.13.1-beta7:

This doesn't fail, but it doesn't play the chime file anymore.

Some strings (see below) will include this to be included in what is said:

    - type: chime
      path: "{{chimefile}}"
      audio_conversion: "-filter:a volume=0.8"

And will include 'delay' in what's said at the end.

If say is simpler then it doesn't say the extra stuff (but the chime still doesn't work anymore).

This is what I'm calling:

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

Here's what was submitted that generated this problem error (from the trace):

(ChatGPT wrote the text, I'm just passing it through without modification)

Executed: February 19, 2024 at 10:35:18 PM
Result:
params:
  domain: chime_tts
  service: say_url
  service_data:
    tts_platform: openai_tts
    cache: true
    message:
      - type: chime
        path: media/notify.mp3
        audio_conversion: '-filter:a volume=0.8'
      - type: tts
        message: >-
          "In the ever-evolving orbit of Neptune, remember--- it's the journey
          of progress, not the illusion of perfection, that shapes the cosmos.
          Embrace each phase like Neptune's 165-year orbit—constantly moving,
          improving, and discovering."
        delay: -800
  target: {}
running_script: false

And here's the resulting mp3: (download and rename to remove the .txt - Github doesn't support mp3s) opikm2j4.mp3.txt

nimroddolev commented 9 months ago

Thanks for the feedback. I've addressed the issues and released a new beta, v0.13.1-beta9

Can you please verify whether you're still experiencing the issues?

  1. it doesn't seem to work with chimes in the message body anymore

    This issue should have been fixed in v0.13.1-beta8. Is it still happening for you?

  2. I'm getting this warning: You forgot to include a TTS platform. Using google_translate

    This warning now only occurs if TTS is included in the request to Chime TTS

  3. as an aside, a loop property would be great, as I'm using a choose with lots of conditionals for each loop

    In this beta release I added support for using a repeat parameter in message segments, allowing you to specify how many times a segment should be repeated:

    
    service: chime_tts.say
    data:
    message:
    - type: tts
      message: "Sparky, count to 3"
    - type: chime
      path: https://cdn.pixabay.com/audio/2022/03/10/audio_126e737475.mp3
      offset: -250
      repeat: 3
    - type: tts
      message: "Who's a good boy?"
      repeat: 2
    tts_platform: google_translate
    target:
    entity_id: media_player.kitchen
5. >chime.say_url doesn't appear to be sharing the response variable chime_tts.url anymore

   This issue should now be fixed.

6. >It doesn't play the chime file anymore.
    >Some strings (see below) will include this to be included in what is said:
    >    \- type: chime
    >        path: "{{chimefile}}"
    >        audio_conversion: "-filter:a volume=0.8"

    I wrote the following script and it generated audio as expected. Can you please also try it?

alias: Chime TTS Tests description: "" trigger: [] condition: [] action:

DanDixon commented 9 months ago

Overall it looks like the latest beta is working well (except for # 6)

In v0.13.1-beta12:

  1. Fixed

  2. Fixed. Don't see the warning anymore

  3. Yay! The repeat feature really simplifies my code and works great (in my limited testing). And the delay is ignored if repeat ==1, exactly as expected). - Thank you so much for adding that! ✨

Here's how I'm using it:

service: chime_tts.say_url
data:
  cache: true
  message:
    - type: chime
      path: "{{chimefile}}"
      delay: "{{delay}}"
      repeat: "{{repeat}}"
response_variable: chime_tts
  1. There is no spoon (or # 4)

  2. Fixed. chime.say_url is working now!

  3. Unfortunately, I found another edge case where it includes the chime info in the message. That said, the example you shared worked.

Here's a short message that causes the problem:

they said "we're"

Try using this as the message variable in the script:

variables:
  message: |
    they said "we're"

FYI, when I tried your script, after pasting it into Home Assistant, saving it, and reloading the script I got this (it removed the quotes and reformatted it).

variables:
  message: >-
    In the ever-evolving orbit of Neptune, remember--- it's the journey of
    progress, not the illusion of perfection, that shapes the cosmos. Embrace
    each phase like Neptune's 165-year orbit—constantly moving, improving, and
    discovering.

And again, thank you for all the fixes. Being able to mix together mp3s as needed makes the audio experience of my smart home feel really great!

DanDixon commented 7 months ago

Using v1.0.0 2024-04-02

I assume you're aware, but I'm still having this issue when using a message like this: they said "we're"

That aside, so many great changes in v1.0

Thank you again for all of your work on this.

nimroddolev commented 7 months ago

Hi @DanDixon, thanks for your patience & kind words 👍

I have not fixed the issue but I hope to get to it shortly. Once I have a fix available to test I will let you know.

nimroddolev commented 7 months ago

I had an idea for a solution that seems to have fixed the issue. I uploaded a new beta version, v1.0.1-beta2. Could you please upgrade to it and let me know if it resolves the issue for you?

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
DanDixon commented 7 months ago

Using v1.1.0-beta2

Awesome. Looks like it's fixed now.

I tried a number of different phrases that caused problems before, and it all seems to work without issue now!

Thank you again

nimroddolev commented 7 months ago

Great! Happy to hear it’s now working for you 👍