import gradio as gr import subprocess import os import uuid def tts_tibetan(text): if not text.strip(): return "Vui lòng nhập văn bản." output_path = f"/tmp/{uuid.uuid4().hex}.wav" try: result = subprocess.run( ["espeak-ng", "-v", "bo", "-s", "140", "-w", output_path, text], check=True, stderr=subprocess.PIPE ) if not os.path.exists(output_path): return "Không tạo được file âm thanh." return output_path except subprocess.CalledProcessError as e: return f"Lỗi khi gọi espeak-ng: {e.stderr.decode()}" 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="Kết quả giọng đọc"), title="TTS tiếng Tây Tạng với eSpeak NG", description="Tạo giọng đọc tiếng Tây Tạng sử dụng eSpeak NG (nếu hỗ trợ)" ) iface.launch()