File size: 1,122 Bytes
2684236 6dbe471 d378de6 2684236 d378de6 2684236 d378de6 6dbe471 d378de6 2684236 a3c62ff 2684236 a3c62ff 2684236 a3c62ff 2684236 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import gradio as gr
import torch
import torchaudio
from transformers import VitsModel, VitsTokenizer
def tts_lisu(text):
model_id = "facebook/mms-tts-lis"
try:
tokenizer = VitsTokenizer.from_pretrained(model_id)
model = VitsModel.from_pretrained(model_id)
inputs = tokenizer(text, return_tensors="pt")
with torch.no_grad():
output = model(**inputs)
waveform = output.waveform.squeeze().cpu()
sample_rate = model.config.sampling_rate
path = "lisu.wav"
torchaudio.save(path, waveform.unsqueeze(0), sample_rate)
return "✅ Giọng Lisu (ꓡꓲ-ꓢꓴ)", path
except Exception as e:
return f"❌ Lỗi: {str(e)}", None
with gr.Blocks() as demo:
gr.Markdown("# 🔊 Lisu TTS (ꓡꓲ-ꓢꓴ /lis/)")
text_input = gr.Textbox(label="Nhập văn bản bằng tiếng Lisu")
output_text = gr.Textbox(label="Thông tin")
output_audio = gr.Audio(label="Phát âm", type="filepath")
btn = gr.Button("Phát")
btn.click(fn=tts_lisu, inputs=[text_input], outputs=[output_text, output_audio])
demo.launch() |