Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,48 @@
|
|
| 1 |
-
import
|
| 2 |
-
import subprocess
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
def ipa_to_speech(ipa_input):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def ipa_to_speech(ipa_input):
|
| 6 |
+
text = ipa_input.strip().replace("/", "") # Loại dấu / ở đầu và cuối
|
| 7 |
+
|
| 8 |
+
if not text:
|
| 9 |
+
return "Lỗi: Nhập IPA rỗng", None
|
| 10 |
+
|
| 11 |
+
output_path = "output.wav"
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
# Dùng voice test để đọc IPA như là text
|
| 15 |
+
result = subprocess.run(
|
| 16 |
+
["espeak-ng", "-v", "test", "-q", "-w", output_path, text],
|
| 17 |
+
check=True,
|
| 18 |
+
stdout=subprocess.PIPE,
|
| 19 |
+
stderr=subprocess.PIPE
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
if not os.path.exists(output_path):
|
| 23 |
+
return "Lỗi: Không tạo được file âm thanh", None
|
| 24 |
+
|
| 25 |
+
if os.path.getsize(output_path) == 0:
|
| 26 |
+
return "Lỗi: File âm thanh rỗng", None
|
| 27 |
+
|
| 28 |
+
return "✅ Thành công!", output_path
|
| 29 |
+
|
| 30 |
+
except subprocess.CalledProcessError as e:
|
| 31 |
+
return f"Lỗi khi chạy espeak-ng:\n{e.stderr.decode()}", None
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return f"Lỗi không xác định: {str(e)}", None
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
iface = gr.Interface(
|
| 37 |
+
fn=ipa_to_speech,
|
| 38 |
+
inputs=gr.Textbox(label="IPA input (ví dụ: /qazaʃa/)"),
|
| 39 |
+
outputs=[
|
| 40 |
+
gr.Textbox(label="Thông báo"),
|
| 41 |
+
gr.Audio(label="Kết quả")
|
| 42 |
+
],
|
| 43 |
+
title="TTS IPA bằng eSpeak NG",
|
| 44 |
+
description="Nhập chuỗi IPA để tạo giọng nói bằng eSpeak NG"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
iface.launch()
|