Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,31 +2,28 @@ import os
|
|
| 2 |
import subprocess
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
def ipa_to_speech(
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
wav_path = "output.wav"
|
| 13 |
-
subprocess.run(
|
| 14 |
-
["espeak-ng", "-v", "en", "-q", "-x", ipa_text, "-w", wav_path],
|
| 15 |
-
check=True
|
| 16 |
-
)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
except Exception as e:
|
| 22 |
-
return f"Lỗi không xác định: {str(e)}"
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
title="🗣️ TTS IPA bằng eSpeak NG",
|
| 29 |
-
description="Nhập chuỗi IPA (ký hiệu ngữ âm quốc tế) và nghe giọng nói tương ứng được tạo bằng eSpeak NG"
|
| 30 |
-
)
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import subprocess
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
def ipa_to_speech(ipa_input):
|
| 6 |
+
ipa_input = ipa_input.strip()
|
| 7 |
+
if not ipa_input.startswith("/"):
|
| 8 |
+
ipa_input = "/" + ipa_input
|
| 9 |
+
if not ipa_input.endswith("/"):
|
| 10 |
+
ipa_input = ipa_input + "/"
|
| 11 |
|
| 12 |
+
output_path = "output.wav"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
result = subprocess.run([
|
| 15 |
+
"espeak-ng", "-v", "en", "-q", ipa_input, "-w", output_path
|
| 16 |
+
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
if result.returncode != 0 or not os.path.exists(output_path) or os.path.getsize(output_path) < 500:
|
| 19 |
+
return f"❌ Lỗi tạo âm thanh: {result.stderr.decode()}"
|
| 20 |
+
|
| 21 |
+
return output_path
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
gr.Interface(
|
| 24 |
+
fn=ipa_to_speech,
|
| 25 |
+
inputs=gr.Textbox(label="IPA input (ví dụ: /tɕao1/)"),
|
| 26 |
+
outputs=gr.Audio(type="filepath", label="Giọng đọc"),
|
| 27 |
+
title="TTS IPA bằng eSpeak NG",
|
| 28 |
+
description="Nhập chuỗi IPA để tạo giọng nói bằng eSpeak NG"
|
| 29 |
+
).launch()
|