Solving the TTS Error: A Smooth Solution

Hey everyone, I wanted to share a quick fix for an issue I encountered with the Text-to-Speech (TTS) feature in Home Assistant. I noticed that every time I restarted my system, an error message popped up in my logs: ‘TTS error: xxx.mp3 not recognised’. While it didn’t affect the functionality of TTS, it was a bit annoying to see these errors cluttering up my log files.

After a bit of research and some trial and error, I found that the issue was related to cached TTS files that weren’t being properly cleared during a restart. To resolve this, I decided to automate the cleanup process using a simple script. Here’s how I did it:

  1. Identify the Cache Directory: Locate where the TTS files are stored. This is usually in a directory like /.homeassistant/tts_cache/.
  2. Create a Cleanup Script: I wrote a small Python script that deletes all files in the cache directory. Here’s a snippet of the script:
    python
    import os
    import shutil

cache_dir = ‘/home/homeassistant/.homeassistant/tts_cache/’
if os.path.exists(cache_dir):
for filename in os.listdir(cache_dir):
file_path = os.path.join(cache_dir, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
print(f’Failed to delete {file_path}. Reason: {e}')

  1. Integrate the Script into Home Assistant: I added the script to my configuration.yaml under the automation section so it runs automatically on startup.

This solution has been working perfectly for me, and I no longer see those pesky error messages. It’s a simple fix that makes a big difference in keeping my logs clean and my system running smoothly.

If anyone else has encountered this issue or has other TTS-related problems, feel free to reach out! I’d be happy to help troubleshoot or share more tips. Happy automating! :rocket: