Inial commited on
Commit
1c95d80
·
verified ·
1 Parent(s): c14e7c1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
3
+ import gradio as gr
4
+ import scipy.io.wavfile
5
+
6
+ # Load processor & model
7
+ processor = AutoProcessor.from_pretrained("facebook/mms-tts-bod")
8
+ model = AutoModelForSpeechSeq2Seq.from_pretrained("facebook/mms-tts-bod")
9
+
10
+ # Chuyển văn bản thành tiếng nói
11
+ def tts(text):
12
+ inputs = processor(text=text, return_tensors="pt")
13
+ with torch.no_grad():
14
+ waveform = model.generate(**inputs)
15
+ waveform = waveform.squeeze().cpu().numpy()
16
+ # Trả về sóng âm, mẫu 16000 Hz
17
+ return (16000, waveform)
18
+
19
+ # Giao diện Gradio
20
+ demo = gr.Interface(
21
+ fn=tts,
22
+ inputs=gr.Textbox(label="Nhập văn bản tiếng Tây Tạng"),
23
+ outputs=gr.Audio(label="Kết quả TTS", type="numpy"),
24
+ title="MMS TTS - Tây Tạng"
25
+ )
26
+
27
+ demo.launch()