Spaces:
Running
Running
File size: 2,143 Bytes
04f3f01 19293b4 04f3f01 19293b4 fcbbf4a 19293b4 fcbbf4a 19293b4 fcbbf4a 04f3f01 19293b4 04f3f01 19293b4 04f3f01 19293b4 04f3f01 19293b4 04f3f01 fcbbf4a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import tempfile
import edge_tts
import gradio as gr
import asyncio
language_dict = {
"Amharic": {
"Ameha": "am-ET-AmehaNeural",
"Mekdes": "am-ET-MekdesNeural"
}
}
async def text_to_speech_edge(text, speaker):
voice = language_dict["Amharic"][speaker]
try:
communicate = edge_tts.Communicate(text, voice)
# Create temp file with increased timeout
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
tmp_path = tmp_file.name
await asyncio.wait_for(communicate.save(tmp_path), timeout=30)
return tmp_path
except asyncio.TimeoutError:
error_msg = "α΅α
α°α΅: αα α αααα’ α₯α£αα α₯αα°αα αααα©α’ (Timeout)"
raise gr.Error(error_msg)
except Exception as e:
error_msg = f"α΅α
α°α΅: α΅αα
ααα α α αα°α»ααα’\nError: {str(e)}"
raise gr.Error(error_msg)
with gr.Blocks(title="Amharic TTS") as demo:
gr.HTML("""
<style>
h1 { color: #FF007F; text-align: center; }
.gradio-button { background-color: #FF007F !important; color: white !important; }
.gradio-textbox, .gradio-dropdown { border-color: #FF007F !important; }
</style>
<center><h1>Amharic Text-to-Speech</h1></center>
""")
with gr.Row():
with gr.Column():
input_text = gr.Textbox(lines=5, label="α¨α ααα α½αα",
placeholder="α΅αα
αααα α α½αα α«α΅αα‘...")
speaker = gr.Dropdown(
choices=["Ameha", "Mekdes"],
value="Ameha",
label="α αα²α΅α΅"
)
run_btn = gr.Button(value="α΅αα
αα α", variant="primary")
with gr.Column():
output_audio = gr.Audio(type="filepath", label="α¨α΅αα
αα€α΅")
run_btn.click(
text_to_speech_edge,
inputs=[input_text, speaker],
outputs=output_audio
)
if __name__ == "__main__":
demo.launch(server_port=7860, share=False) |