File size: 1,247 Bytes
e2270b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
import gradio as gr
from transformers import AutoProcessor, BarkModel
import torch
import uuid
import os
from datasets import load_dataset
from scipy.io.wavfile import write

from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline

model_id = "facebook/mms-tts-bo"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id)

device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)

def tts_tibetan(text):
    if not text.strip():
        return "Vui lòng nhập văn bản."
    
    inputs = processor(text=text, return_tensors="pt").to(device)
    with torch.no_grad():
        generated = model.generate(**inputs)
    
    speech = processor.decode(generated[0])
    output_path = f"/tmp/{uuid.uuid4().hex}.wav"
    processor.save_wav(speech, output_path)
    
    return output_path

iface = gr.Interface(
    fn=tts_tibetan,
    inputs=gr.Textbox(label="Nhập văn bản tiếng Tây Tạng (Unicode)"),
    outputs=gr.Audio(type="filepath", label="Giọng đọc Tây Tạng (MMS)"),
    title="TTS tiếng Tây Tạng bằng Facebook MMS",
    description="Sử dụng mô hình MMS để tạo giọng đọc tiếng Tây Tạng"
)

iface.launch()