Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def tts_lisu(text):
|
| 5 |
-
model_id = "facebook/mms-tts-lis"
|
| 6 |
try:
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
except Exception as e:
|
| 11 |
return f"❌ Lỗi: {str(e)}", None
|
| 12 |
|
| 13 |
with gr.Blocks() as demo:
|
| 14 |
-
gr.Markdown("# 🔊 Lisu TTS (
|
| 15 |
text_input = gr.Textbox(label="Nhập văn bản bằng tiếng Lisu")
|
| 16 |
output_text = gr.Textbox(label="Thông tin")
|
| 17 |
output_audio = gr.Audio(label="Phát âm", type="filepath")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoProcessor, AutoModelForTextToSpeech
|
| 3 |
+
import torch
|
| 4 |
+
import soundfile as sf
|
| 5 |
+
|
| 6 |
+
model_id = "facebook/mms-tts-lis"
|
| 7 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 8 |
+
model = AutoModelForTextToSpeech.from_pretrained(model_id)
|
| 9 |
|
| 10 |
def tts_lisu(text):
|
|
|
|
| 11 |
try:
|
| 12 |
+
inputs = processor(text=text, return_tensors="pt")
|
| 13 |
+
with torch.no_grad():
|
| 14 |
+
outputs = model(**inputs)
|
| 15 |
+
audio = outputs["waveform"]
|
| 16 |
+
|
| 17 |
+
# Lưu ra file WAV
|
| 18 |
+
sf.write("lisu.wav", audio.squeeze().numpy(), samplerate=16000)
|
| 19 |
+
return f"✅ Giọng Lisu (ꓡꓲ-ꓢꓴ)", "lisu.wav"
|
| 20 |
except Exception as e:
|
| 21 |
return f"❌ Lỗi: {str(e)}", None
|
| 22 |
|
| 23 |
with gr.Blocks() as demo:
|
| 24 |
+
gr.Markdown("# 🔊 Lisu TTS (LI-SU /lis/)")
|
| 25 |
text_input = gr.Textbox(label="Nhập văn bản bằng tiếng Lisu")
|
| 26 |
output_text = gr.Textbox(label="Thông tin")
|
| 27 |
output_audio = gr.Audio(label="Phát âm", type="filepath")
|