From ae0d291d33046eaca0368cb8a61b512a7043badc Mon Sep 17 00:00:00 2001 From: dKosarevsky <36589322+dKosarevsky@users.noreply.github.com> Date: Wed, 8 Mar 2023 16:07:09 +0300 Subject: [PATCH] Update tts.py add err handler --- src/utils/tts.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/utils/tts.py b/src/utils/tts.py index 4df0f97..1d638ad 100644 --- a/src/utils/tts.py +++ b/src/utils/tts.py @@ -1,5 +1,5 @@ from typing import Any, Dict, Optional -from gtts import gTTS, lang +from gtts import gTTS, gTTSError, lang from io import BytesIO import streamlit as st @@ -39,7 +39,10 @@ def speech_speed_radio() -> bool: def show_player(ai_content: str, lang_code: str, is_speech_slow: bool) -> None: sound_file = BytesIO() - tts = gTTS(text=ai_content, lang=lang_code, slow=is_speech_slow) - tts.write_to_fp(sound_file) - st.write("To hear the voice of AI, press the play button.") - st.audio(sound_file) + try: + tts = gTTS(text=ai_content, lang=lang_code, slow=is_speech_slow) + tts.write_to_fp(sound_file) + st.write("To hear the voice of AI, press the play button.") + st.audio(sound_file) + except gTTSError as err: + st.error(err)