Hev832 commited on
Commit
4f9c71b
·
verified ·
1 Parent(s): 2475d74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -26
app.py CHANGED
@@ -1,32 +1,28 @@
1
  import gradio as gr
2
- from edge_tts import Communicate
 
3
 
4
- # Define a function to convert text to speech
5
- async def text_to_speech(text):
6
- communicate = Communicate()
7
- await communicate.run(text, "output_audio.wav")
8
- return "output_audio.wav"
9
 
10
- # Create the Gradio interface
11
- def create_interface():
12
- # Define the Gradio interface components
13
- with gr.Blocks() as demo:
14
- gr.Markdown("# Text to Speech with Edge TTS")
15
-
16
- text_input = gr.Textbox(label="Enter text here:")
17
- output_audio = gr.Audio(label="Generated Speech")
18
-
19
- def generate_speech(text):
20
- # Run the text_to_speech function and get the output file path
21
- import asyncio
22
- output_path = asyncio.run(text_to_speech(text))
23
- return output_path
24
-
25
- generate_button = gr.Button("Generate Speech")
26
- generate_button.click(generate_speech, inputs=text_input, outputs=output_audio)
27
 
28
- return demo
29
 
30
- # Create and launch the interface
31
- demo = create_interface()
32
  demo.launch()
 
1
  import gradio as gr
2
+ import edge_tts
3
+ import asyncio
4
 
5
+ async def tts(text):
6
+ communicate = edge_tts.Communicate(text, 'en-US-JennyNeural')
7
+ result = await communicate.save("output.mp3")
8
+ return "output.mp3"
 
9
 
10
+ def tts_sync(text):
11
+ loop = asyncio.new_event_loop()
12
+ asyncio.set_event_loop(loop)
13
+ return loop.run_until_complete(tts(text))
14
+
15
+ with gr.Blocks() as demo:
16
+ gr.Markdown("## Text-to-Speech with Edge TTS")
17
+
18
+ with gr.Row():
19
+ with gr.Column():
20
+ text_input = gr.Textbox(label="Enter Text", placeholder="Type something here...")
21
+ submit_button = gr.Button("Convert to Speech")
22
+
23
+ with gr.Column():
24
+ audio_output = gr.Audio(label="Output Audio")
 
 
25
 
26
+ submit_button.click(fn=tts_sync, inputs=text_input, outputs=audio_output)
27
 
 
 
28
  demo.launch()