VuTQ15 commited on
Commit
74ba86b
·
verified ·
1 Parent(s): c2e7497
Files changed (2) hide show
  1. app.py +27 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoProcessor, AutoModelForTextToSpeech
2
+ import torch
3
+ import soundfile as sf
4
+ import gradio as gr
5
+
6
+ # Tải mô hình TTS tiếng Việt
7
+ model_id = "facebook/mms-tts-vie"
8
+ processor = AutoProcessor.from_pretrained(model_id)
9
+ model = AutoModelForTextToSpeech.from_pretrained(model_id)
10
+
11
+ # Hàm chuyển văn bản thành âm thanh
12
+ def tts(text):
13
+ inputs = processor(text, return_tensors="pt")
14
+ with torch.no_grad():
15
+ output = model(**inputs).waveform
16
+ audio = output.squeeze().cpu().numpy().astype("float32")
17
+ sf.write("output.wav", audio, samplerate=model.config.sampling_rate, format='WAV', subtype='PCM_16')
18
+ return "output.wav"
19
+
20
+ # Giao diện Gradio
21
+ gr.Interface(
22
+ fn=tts,
23
+ inputs=gr.Textbox(label="Nhập văn bản tiếng Việt"),
24
+ outputs=gr.Audio(type="filepath", label="Kết quả âm thanh"),
25
+ title="Vietnamese Text-to-Speech",
26
+ description="Ứng dụng chuyển văn bản tiếng Việt thành giọng nói bằng mô hình MMS của Facebook."
27
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ soundfile
4
+ gradio