CineAI commited on
Commit
4bb9300
1 Parent(s): cd9b829

Create T2A.py

Browse files
Files changed (1) hide show
  1. audio_processing/T2A.py +24 -0
audio_processing/T2A.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import soundfile as sf
3
+ from .config import model_mms_tts_eng, tokenizer_mms_tts_eng
4
+
5
+ SAMPLING_RATE = 16000
6
+
7
+ class T2A:
8
+ def __init__(self, input_text: str):
9
+ self.inputs = tokenizer_mms_tts_eng(input_text, return_tensors="pt")
10
+
11
+ def __call__(self):
12
+ if self.inputs is not None:
13
+ with torch.no_grad():
14
+ output_model = model_mms_tts_eng(**self.inputs)
15
+
16
+ audio = output_model["audio"][0]
17
+
18
+ with BytesIO() as buffer:
19
+ sf.write(buffer, audio, SAMPLING_RATE, format='wav')
20
+ output = buffer.getvalue() # bytes
21
+
22
+ return output
23
+ else:
24
+ raise Exception("Input text is None. Please provide text")