Mynameisju commited on
Commit
989d165
·
verified ·
1 Parent(s): 2b20973

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -24
app.py CHANGED
@@ -2,31 +2,28 @@ import os
2
  import subprocess
3
  import gradio as gr
4
 
5
- def ipa_to_speech(ipa_text):
6
- try:
7
- # Đảm bảo ký hiệu IPA nằm trong dấu / /
8
- if not ipa_text.startswith("/") or not ipa_text.endswith("/"):
9
- ipa_text = "/" + ipa_text.strip("/") + "/"
 
10
 
11
- # Ghi vào file tạm
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
- return wav_path
19
- except subprocess.CalledProcessError as e:
20
- return "Lỗi khi chạy espeak-ng."
21
- except Exception as e:
22
- return f"Lỗi không xác định: {str(e)}"
23
 
24
- demo = gr.Interface(
25
- fn=ipa_to_speech,
26
- inputs=gr.Textbox(label="Nhập IPA (ví dụ: /tɕao1/)"),
27
- outputs=gr.Audio(label="Giọng nói tạo bởi eSpeak NG", type="filepath"),
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
- demo.launch()
 
 
 
 
 
 
 
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()