|
|
import torch |
|
|
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq |
|
|
import gradio as gr |
|
|
import scipy.io.wavfile |
|
|
|
|
|
|
|
|
processor = AutoProcessor.from_pretrained("facebook/mms-tts-bod") |
|
|
model = AutoModelForSpeechSeq2Seq.from_pretrained("facebook/mms-tts-bod") |
|
|
|
|
|
|
|
|
def tts(text): |
|
|
inputs = processor(text=text, return_tensors="pt") |
|
|
with torch.no_grad(): |
|
|
waveform = model.generate(**inputs) |
|
|
waveform = waveform.squeeze().cpu().numpy() |
|
|
|
|
|
return (16000, waveform) |
|
|
|
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=tts, |
|
|
inputs=gr.Textbox(label="Nhập văn bản tiếng Tây Tạng"), |
|
|
outputs=gr.Audio(label="Kết quả TTS", type="numpy"), |
|
|
title="MMS TTS - Tây Tạng" |
|
|
) |
|
|
|
|
|
demo.launch() |