CineAI's picture
Update audio_processing/T2A.py
64b7c62 verified
raw
history blame
1.27 kB
from typing import Optional
from streamlit_TTS import auto_play, text_to_audio
class T2A:
def autoplay(self, input_text: Optional[str] = None, lang: str = "en", just_once: bool = True) -> None:
"""
Plays audio once based on the provided input text.
Args:
input_text (Optional[str], optional): Text to convert to audio. Defaults to None.
lang (str, optional): Language for text-to-speech conversion. Defaults to "en".
just_once (bool, optional): Flag to control whether audio plays only once. Defaults to False.
"""
if input_text is not None:
if isinstance(input_text, str):
audio = text_to_audio(input_text, language=lang)
if just_once:
auto_play(audio)
just_once = False
else:
text = f"The text you provided is of data type {type(input_text)}, only string type is accepted"
audio = text_to_audio(text, language=lang)
auto_play(audio)
else:
text = "Please check the input text you have provided, it has a value of None"
audio = text_to_audio(text, language=lang)
auto_play(audio)