aheedsajid commited on
Commit
7e6edcc
·
verified ·
1 Parent(s): 34960c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -23
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import edge_tts
2
  import gradio as gr
3
  import tempfile
4
- import anyio
5
 
6
 
7
  language_dict = {
@@ -50,33 +50,45 @@ language_dict = {
50
  }
51
 
52
  async def text_to_speech_edge(text, language_code):
53
- voice = language_dict.get(language_code, "default_voice")
 
 
 
 
 
 
 
54
  communicate = edge_tts.Communicate(text, voice)
 
55
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
56
  tmp_path = tmp_file.name
57
  await communicate.save(tmp_path)
58
- return f"Speech synthesis completed for: {text}", tmp_path
59
-
60
- input_text = gr.Textbox(lines=5, label="Input Text")
61
- output_text = gr.Textbox(label="Output Text")
62
- output_audio = gr.Audio(type="filepath", label="Exported Audio")
63
- language = gr.Dropdown(choices=list(language_dict.keys()), label="Choose the Voice Model")
64
-
65
 
66
- # Gradio interface
67
- iface = gr.Blocks()
 
68
 
69
- with iface:
70
-
71
- gr.Interface(
72
- fn=text_to_speech_edge,
73
- inputs=[input_text, language],
74
- outputs=[output_text, output_audio],
75
- title="Edge TTS",
76
- description="Microsoft Edge Text-To-Speech (Forked & Fixed Ilaria TTS)",
77
- )
78
-
79
- iface.launch()
 
 
 
 
 
 
 
 
80
 
81
  if __name__ == "__main__":
82
- anyio.run(interface.launch, backend="asyncio")
 
1
  import edge_tts
2
  import gradio as gr
3
  import tempfile
4
+ import asyncio
5
 
6
 
7
  language_dict = {
 
50
  }
51
 
52
  async def text_to_speech_edge(text, language_code):
53
+ """Convert text to speech using Edge TTS"""
54
+ if not text:
55
+ return "Please enter some text", None
56
+
57
+ if not language_code:
58
+ return "Please select a voice model", None
59
+
60
+ voice = language_dict.get(language_code, "en-US-AriaNeural")
61
  communicate = edge_tts.Communicate(text, voice)
62
+
63
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
64
  tmp_path = tmp_file.name
65
  await communicate.save(tmp_path)
66
+
67
+ return f"Speech synthesis completed for: {text[:50]}...", tmp_path
 
 
 
 
 
68
 
69
+ def text_to_speech_sync(text, language_code):
70
+ """Synchronous wrapper for the async function"""
71
+ return asyncio.run(text_to_speech_edge(text, language_code))
72
 
73
+ # Create Gradio interface
74
+ iface = gr.Interface(
75
+ fn=text_to_speech_sync,
76
+ inputs=[
77
+ gr.Textbox(lines=5, label="Input Text", placeholder="Enter the text you want to convert to speech..."),
78
+ gr.Dropdown(choices=list(language_dict.keys()), label="Choose the Voice Model", value="Aria")
79
+ ],
80
+ outputs=[
81
+ gr.Textbox(label="Status"),
82
+ gr.Audio(label="Generated Audio")
83
+ ],
84
+ title="Edge TTS - Text to Speech",
85
+ description="Microsoft Edge Text-To-Speech (Forked & Fixed Ilaria TTS)",
86
+ theme=gr.themes.Soft(),
87
+ examples=[
88
+ ["Hello, this is a test of the text to speech system.", "Aria"],
89
+ ["Welcome to Edge TTS! This is an example.", "Brian"],
90
+ ]
91
+ )
92
 
93
  if __name__ == "__main__":
94
+ iface.launch()