File size: 775 Bytes
d5436e0
 
9b0d264
4bb9300
 
5d817ad
 
558fcff
 
 
d2150bd
5d817ad
558fcff
d5436e0
d2150bd
 
558fcff
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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") -> None:
        
        if input_text is not None:
            if isinstance(input_text, str):
                audio = text_to_audio(input_text, language=lang)
                auto_play(audio)
            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)