From a927a18e392619b6d6087130e793929d19c87aba Mon Sep 17 00:00:00 2001 From: tiyn Date: Mon, 22 Apr 2024 02:29:14 +0200 Subject: [PATCH] tts: added error handling --- src/content.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/content.py b/src/content.py index 5ec7cb5..58cd34f 100644 --- a/src/content.py +++ b/src/content.py @@ -8,7 +8,7 @@ from os import path import markdown from bs4 import BeautifulSoup -from gtts import gTTS +from gtts import gTTS, gTTSError import config import search @@ -320,7 +320,12 @@ def prepare_tts(): clean_text = "" for f in files: clean_text = get_text_only(f) - tts = gTTS(clean_text, lang=LANGUAGE.split("-")[0]) _, tail = os.path.split(f) new_filename = "static/tmp/" + os.path.splitext(tail)[0] + ".mp3" - tts.save(new_filename) + try: + tts = gTTS(clean_text, lang=LANGUAGE.split("-")[0]) + tts.save(new_filename) + except gTTSError as e: + print("Too many request to the google servers. Try it again later.") + os.remove(new_filename) + return e