Update tts.py
add err handler
This commit is contained in:
parent
8e6811f41f
commit
ae0d291d33
@ -1,5 +1,5 @@
|
|||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
from gtts import gTTS, lang
|
from gtts import gTTS, gTTSError, lang
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import streamlit as st
|
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:
|
def show_player(ai_content: str, lang_code: str, is_speech_slow: bool) -> None:
|
||||||
sound_file = BytesIO()
|
sound_file = BytesIO()
|
||||||
tts = gTTS(text=ai_content, lang=lang_code, slow=is_speech_slow)
|
try:
|
||||||
tts.write_to_fp(sound_file)
|
tts = gTTS(text=ai_content, lang=lang_code, slow=is_speech_slow)
|
||||||
st.write("To hear the voice of AI, press the play button.")
|
tts.write_to_fp(sound_file)
|
||||||
st.audio(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)
|
||||||
|
Loading…
Reference in New Issue
Block a user