Update audio_processing/T2A.py
Browse files- audio_processing/T2A.py +12 -2
audio_processing/T2A.py
CHANGED
@@ -12,6 +12,12 @@ class T2A:
|
|
12 |
def __init__(self, input_text: str):
|
13 |
self.output_model = pipe_tts(input_text)
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def get_audio(self):
|
16 |
try:
|
17 |
synth = self.output_model["audio"][0]
|
@@ -22,8 +28,12 @@ class T2A:
|
|
22 |
sf.write(buffer, synth, SAMPLING_RATE, format='wav')
|
23 |
output = buffer.getvalue() # bytes
|
24 |
|
25 |
-
print(f"
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
return output
|
28 |
except Exception as e:
|
29 |
logging.error(f"Raised an error : {e}")
|
|
|
12 |
def __init__(self, input_text: str):
|
13 |
self.output_model = pipe_tts(input_text)
|
14 |
|
15 |
+
def __get_duration(self, raw: bytes):
|
16 |
+
chunk = io.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 get_audio(self):
|
22 |
try:
|
23 |
synth = self.output_model["audio"][0]
|
|
|
28 |
sf.write(buffer, synth, SAMPLING_RATE, format='wav')
|
29 |
output = buffer.getvalue() # bytes
|
30 |
|
31 |
+
print(f"type : {type(output)}")
|
32 |
+
|
33 |
+
duration = __get_duration(output)
|
34 |
+
|
35 |
+
print(f"duration : {duration}")
|
36 |
|
37 |
+
return output, SAMPLING_RATE, duration
|
38 |
except Exception as e:
|
39 |
logging.error(f"Raised an error : {e}")
|