Update audio_processing/T2A.py
Browse files- audio_processing/T2A.py +7 -43
audio_processing/T2A.py
CHANGED
@@ -1,55 +1,19 @@
|
|
1 |
-
# from io import BytesIO
|
2 |
from typing import Optional
|
3 |
-
|
4 |
-
# import librosa
|
5 |
-
# import soundfile as sf
|
6 |
from streamlit_TTS import auto_play, text_to_audio
|
7 |
|
8 |
-
from .config import pipe_tts
|
9 |
-
|
10 |
-
# SAMPLING_RATE = 16_000
|
11 |
-
|
12 |
|
13 |
class T2A:
|
14 |
-
|
15 |
-
# def __get_duration(self, raw: bytes) -> float:
|
16 |
-
# chunk = BytesIO(raw)
|
17 |
-
# audio, sample_rate = librosa.load(chunk, sr=SAMPLING_RATE)
|
18 |
-
# duration = librosa.get_duration(y=audio, sr=sample_rate)
|
19 |
-
# return duration
|
20 |
-
|
21 |
def autoplay(self, input_text: Optional[str] = None, lang: str = "en") -> None:
|
22 |
-
|
23 |
-
text = input_text
|
24 |
-
output_model = pipe_tts(input_text)
|
25 |
|
26 |
-
if
|
27 |
-
if isinstance(
|
28 |
-
audio = text_to_audio(
|
29 |
auto_play(audio)
|
30 |
else:
|
31 |
-
text = f"
|
32 |
audio = text_to_audio(text, language=lang)
|
33 |
auto_play(audio)
|
34 |
else:
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
# try:
|
39 |
-
# synth = self.output_model["audio"][0]
|
40 |
-
|
41 |
-
# print(f"synth : {synth}")
|
42 |
-
|
43 |
-
# with BytesIO() as buffer:
|
44 |
-
# sf.write(buffer, synth, SAMPLING_RATE, format='wav')
|
45 |
-
# output = buffer.getvalue() # bytes
|
46 |
-
|
47 |
-
# print(f"type : {type(output)}")
|
48 |
-
|
49 |
-
# duration = self.__get_duration(output)
|
50 |
-
|
51 |
-
# print(f"duration : {duration}")
|
52 |
-
|
53 |
-
# return output, SAMPLING_RATE, duration
|
54 |
-
# except Exception as e:
|
55 |
-
# logging.error(e)
|
|
|
|
|
1 |
from typing import Optional
|
|
|
|
|
|
|
2 |
from streamlit_TTS import auto_play, text_to_audio
|
3 |
|
|
|
|
|
|
|
|
|
4 |
|
5 |
class T2A:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def autoplay(self, input_text: Optional[str] = None, lang: str = "en") -> None:
|
|
|
|
|
|
|
7 |
|
8 |
+
if input_text is not None:
|
9 |
+
if isinstance(input_text, str):
|
10 |
+
audio = text_to_audio(input_text, language=lang)
|
11 |
auto_play(audio)
|
12 |
else:
|
13 |
+
text = f"The text you provided is of data type {type(input_text)}, only string type is accepted"
|
14 |
audio = text_to_audio(text, language=lang)
|
15 |
auto_play(audio)
|
16 |
else:
|
17 |
+
text = "Please check the input text you have provided, it has a value of None"
|
18 |
+
audio = text_to_audio(text, language=lang)
|
19 |
+
auto_play(audio)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|