Update audio_processing/T2A.py
Browse files- audio_processing/T2A.py +33 -34
audio_processing/T2A.py
CHANGED
@@ -1,56 +1,55 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
from io import BytesIO
|
4 |
from typing import Optional
|
5 |
|
6 |
-
import librosa
|
7 |
-
import soundfile as sf
|
8 |
from streamlit_TTS import auto_play, text_to_audio
|
9 |
|
10 |
from .config import pipe_tts
|
11 |
|
12 |
-
SAMPLING_RATE = 16_000
|
13 |
|
14 |
|
15 |
class T2A:
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
28 |
if isinstance(self.text, str):
|
29 |
-
audio = text_to_audio(
|
30 |
auto_play(audio)
|
31 |
-
else:
|
32 |
text = f"Text you provide is {type(self.text)} accepted only string type"
|
33 |
audio = text_to_audio(text, language=lang)
|
34 |
auto_play(audio)
|
35 |
else:
|
36 |
-
|
37 |
|
38 |
-
def get_audio(self) -> tuple[bytes, int, float]:
|
39 |
-
|
40 |
-
|
41 |
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
|
48 |
-
|
49 |
|
50 |
-
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
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 text is not None:
|
27 |
if isinstance(self.text, str):
|
28 |
+
audio = text_to_audio(text, language=lang)
|
29 |
auto_play(audio)
|
30 |
+
else:
|
31 |
text = f"Text you provide is {type(self.text)} accepted only string type"
|
32 |
audio = text_to_audio(text, language=lang)
|
33 |
auto_play(audio)
|
34 |
else:
|
35 |
+
auto_play("Please check the input text you have provided, it has a value of None")
|
36 |
|
37 |
+
# def get_audio(self) -> tuple[bytes, int, float]:
|
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)
|