| import gradio as gr |
| from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor |
| import torch |
|
|
| device = "cuda" if torch.cuda.is_available() else "cpu" |
| model_id = "facebook/mms-tts-ava" |
|
|
| processor = AutoProcessor.from_pretrained(model_id) |
| model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id).to(device) |
|
|
| def tts_fn(text): |
| inputs = processor(text=text, return_tensors="pt").to(device) |
| with torch.no_grad(): |
| waveform = model.generate(**inputs) |
| audio = waveform.squeeze().cpu().numpy() |
| return (16000, audio) |
|
|
| gr.Interface(fn=tts_fn, |
| inputs=gr.Textbox(label="Nhập văn bản bằng tiếng Avar"), |
| outputs=gr.Audio(label="Âm thanh (16kHz)"), |
| title="Avar TTS - facebook/mms-tts-ava", |
| description="Dùng thử TTS tiếng Avar bằng mô hình MMS từ Meta (facebook/mms-tts-ava). Chỉ để thử nghiệm, không thương mại.").launch() |