Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import edge_tts
|
|
3 |
import gradio as gr
|
4 |
import asyncio
|
5 |
|
|
|
6 |
language_dict = {
|
7 |
"Amharic": {
|
8 |
"Ameha": "am-ET-AmehaNeural",
|
@@ -13,18 +14,24 @@ language_dict = {
|
|
13 |
"Clara": "en-CA-ClaraNeural"
|
14 |
},
|
15 |
"Tigrinya": {
|
16 |
-
"Ameha": "am-ET-AmehaNeural",
|
17 |
-
"Mekdes": "am-ET-MekdesNeural"
|
18 |
}
|
19 |
}
|
20 |
|
21 |
async def text_to_speech_edge(text, language, speaker):
|
22 |
-
#
|
23 |
if language == "Tigrinya":
|
24 |
-
|
25 |
-
|
26 |
-
voice = language_dict[language][speaker]
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
try:
|
29 |
communicate = edge_tts.Communicate(text, voice)
|
30 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
@@ -33,25 +40,25 @@ async def text_to_speech_edge(text, language, speaker):
|
|
33 |
return tmp_path
|
34 |
|
35 |
except asyncio.TimeoutError:
|
36 |
-
error_msg = ("α΅α
α°α΅: αα α αααα’ α₯α£αα α₯αα°αα αααα©α’
|
37 |
-
|
38 |
-
|
39 |
raise gr.Error(error_msg)
|
40 |
except Exception as e:
|
41 |
-
error_msg = (f"α΅α
α°α΅:
|
42 |
-
|
43 |
-
|
44 |
raise gr.Error(error_msg)
|
45 |
|
46 |
def update_speakers(language):
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
|
54 |
-
with gr.Blocks(title="Amharic, English & Tigrinya TTS") as demo:
|
55 |
gr.HTML("""
|
56 |
<style>
|
57 |
h1 {
|
@@ -60,16 +67,26 @@ with gr.Blocks(title="Amharic, English & Tigrinya TTS") as demo:
|
|
60 |
background: linear-gradient(45deg, #FF007F, #2E86C1);
|
61 |
-webkit-background-clip: text;
|
62 |
-webkit-text-fill-color: transparent;
|
|
|
63 |
}
|
64 |
-
.
|
65 |
-
|
66 |
-
color:
|
|
|
|
|
|
|
67 |
}
|
68 |
-
.gradio-
|
69 |
-
|
|
|
70 |
}
|
71 |
</style>
|
72 |
-
<center
|
|
|
|
|
|
|
|
|
|
|
73 |
""")
|
74 |
|
75 |
with gr.Row():
|
@@ -80,25 +97,33 @@ with gr.Blocks(title="Amharic, English & Tigrinya TTS") as demo:
|
|
80 |
label="Select Language / ααα ααα¨α‘"
|
81 |
)
|
82 |
input_text = gr.Textbox(
|
83 |
-
lines=5,
|
84 |
label="Enter Text / α½αα α«α΅αα‘",
|
85 |
placeholder="Type your text here... / α½αααα αα»α..."
|
86 |
)
|
87 |
speaker = gr.Dropdown(
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
92 |
)
|
93 |
-
run_btn = gr.Button(value="Generate Audio / α΅αα
αα α", variant="primary")
|
94 |
|
95 |
with gr.Column():
|
96 |
output_audio = gr.Audio(
|
97 |
type="filepath",
|
98 |
-
label="Generated Audio / α¨α°αα α¨ α΅αα
"
|
|
|
99 |
)
|
100 |
|
101 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
language.change(
|
103 |
update_speakers,
|
104 |
inputs=language,
|
@@ -112,4 +137,4 @@ with gr.Blocks(title="Amharic, English & Tigrinya TTS") as demo:
|
|
112 |
)
|
113 |
|
114 |
if __name__ == "__main__":
|
115 |
-
demo.launch(server_port=7860, share=False)
|
|
|
3 |
import gradio as gr
|
4 |
import asyncio
|
5 |
|
6 |
+
# Updated language dictionary with clear voice labeling
|
7 |
language_dict = {
|
8 |
"Amharic": {
|
9 |
"Ameha": "am-ET-AmehaNeural",
|
|
|
14 |
"Clara": "en-CA-ClaraNeural"
|
15 |
},
|
16 |
"Tigrinya": {
|
17 |
+
"Ameha (Amharic Voice)": "am-ET-AmehaNeural",
|
18 |
+
"Mekdes (Amharic Voice)": "am-ET-MekdesNeural"
|
19 |
}
|
20 |
}
|
21 |
|
22 |
async def text_to_speech_edge(text, language, speaker):
|
23 |
+
# Clean speaker name if it's a Tigrinya selection
|
24 |
if language == "Tigrinya":
|
25 |
+
speaker = speaker.replace(" (Amharic Voice)", "")
|
|
|
|
|
26 |
|
27 |
+
try:
|
28 |
+
voice = language_dict[language][speaker]
|
29 |
+
except KeyError:
|
30 |
+
error_msg = (f"α΅α
α°α΅: α΅αα
'{speaker}' αααα '{language}' α αα°αααα’"
|
31 |
+
if language in ["Amharic", "Tigrinya"]
|
32 |
+
else f"Error: Voice '{speaker}' not available for '{language}'")
|
33 |
+
raise gr.Error(error_msg)
|
34 |
+
|
35 |
try:
|
36 |
communicate = edge_tts.Communicate(text, voice)
|
37 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
|
|
40 |
return tmp_path
|
41 |
|
42 |
except asyncio.TimeoutError:
|
43 |
+
error_msg = ("α΅α
α°α΅: αα α αααα’ α₯α£αα α₯αα°αα αααα©α’"
|
44 |
+
if language in ["Amharic", "Tigrinya"]
|
45 |
+
else "Error: Timeout. Please try again.")
|
46 |
raise gr.Error(error_msg)
|
47 |
except Exception as e:
|
48 |
+
error_msg = (f"α΅α
α°α΅: {str(e)}"
|
49 |
+
if language in ["Amharic", "Tigrinya"]
|
50 |
+
else f"Error: {str(e)}")
|
51 |
raise gr.Error(error_msg)
|
52 |
|
53 |
def update_speakers(language):
|
54 |
+
speakers = list(language_dict[language].keys())
|
55 |
+
return gr.Dropdown(
|
56 |
+
choices=speakers,
|
57 |
+
value=speakers[0],
|
58 |
+
label=f"Select Speaker {'(Amharic Voices)' if language == 'Tigrinya' else ''}"
|
59 |
+
)
|
60 |
|
61 |
+
with gr.Blocks(title="Amharic, English & Tigrinya TTS", theme=gr.themes.Soft()) as demo:
|
62 |
gr.HTML("""
|
63 |
<style>
|
64 |
h1 {
|
|
|
67 |
background: linear-gradient(45deg, #FF007F, #2E86C1);
|
68 |
-webkit-background-clip: text;
|
69 |
-webkit-text-fill-color: transparent;
|
70 |
+
margin-bottom: 20px;
|
71 |
}
|
72 |
+
.notice {
|
73 |
+
font-size: 0.9em;
|
74 |
+
color: #666;
|
75 |
+
text-align: center;
|
76 |
+
margin: 10px 0;
|
77 |
+
font-style: italic;
|
78 |
}
|
79 |
+
.gradio-button {
|
80 |
+
background: linear-gradient(45deg, #FF007F, #2E86C1) !important;
|
81 |
+
color: white !important;
|
82 |
}
|
83 |
</style>
|
84 |
+
<center>
|
85 |
+
<h1>Amharic, English & Tigrinya Text-to-Speech</h1>
|
86 |
+
<div class="notice">
|
87 |
+
Note: Tigrinya uses Amharic-accented voices until dedicated models become available
|
88 |
+
</div>
|
89 |
+
</center>
|
90 |
""")
|
91 |
|
92 |
with gr.Row():
|
|
|
97 |
label="Select Language / ααα ααα¨α‘"
|
98 |
)
|
99 |
input_text = gr.Textbox(
|
100 |
+
lines=5,
|
101 |
label="Enter Text / α½αα α«α΅αα‘",
|
102 |
placeholder="Type your text here... / α½αααα αα»α..."
|
103 |
)
|
104 |
speaker = gr.Dropdown(
|
105 |
+
label="Select Speaker / α αα²α΅α΅ ααα¨α‘",
|
106 |
+
interactive=True
|
107 |
+
)
|
108 |
+
run_btn = gr.Button(
|
109 |
+
value="Generate Audio / α΅αα
αα α",
|
110 |
+
variant="primary"
|
111 |
)
|
|
|
112 |
|
113 |
with gr.Column():
|
114 |
output_audio = gr.Audio(
|
115 |
type="filepath",
|
116 |
+
label="Generated Audio / α¨α°αα α¨ α΅αα
",
|
117 |
+
interactive=False
|
118 |
)
|
119 |
|
120 |
+
# Initialize speakers dropdown
|
121 |
+
demo.load(
|
122 |
+
fn=lambda: gr.Dropdown(choices=list(language_dict["Amharic"].keys()),
|
123 |
+
outputs=speaker
|
124 |
+
)
|
125 |
+
|
126 |
+
# Update speakers when language changes
|
127 |
language.change(
|
128 |
update_speakers,
|
129 |
inputs=language,
|
|
|
137 |
)
|
138 |
|
139 |
if __name__ == "__main__":
|
140 |
+
demo.launch(server_port=7860, share=False)
|