hamza2923 commited on
Commit
c5eb336
·
verified ·
1 Parent(s): 1ef6c73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -43
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  import edge_tts
3
  import asyncio
4
- import os
5
  from typing import Dict
6
 
7
  async def generate_speech(text: str, voice: str) -> str:
@@ -108,54 +107,32 @@ VOICES: Dict[str, str] = {
108
  "Sofie (Female, NL)": "nl-NL-SofieNeural",
109
  }
110
 
111
- def text_to_speech(text: str, voice: str) -> tuple:
112
- """Wrapper function to run async code and return audio file and download button state"""
113
  if not text or not voice:
114
- return None, {"visible": False}
115
- output_file = asyncio.run(generate_speech(text, VOICES.get(voice, VOICES["Jenny (Female, US)"])))
116
- return output_file, {"visible": True} if output_file else (None, {"visible": False})
117
 
118
- with gr.Blocks(title="Multi-Voice Text-to-Speech", theme="soft") as demo:
119
- gr.Markdown("""
120
- # 🎤 Advanced Text-to-Speech Converter
121
- ### With 100+ Voices
122
- """)
123
-
124
- with gr.Row():
125
- with gr.Column():
126
- text_input = gr.Textbox(
127
- label="Enter your text",
128
- placeholder="Type or paste your text here...",
129
- lines=5,
130
- max_lines=10
131
- )
132
-
133
- voice_dropdown = gr.Dropdown(
134
- choices=list(VOICES.keys()),
135
- label="Select Voice",
136
- value="Jenny (Female, US)"
137
- )
138
-
139
- generate_btn = gr.Button("Generate Speech", variant="primary")
140
-
141
- with gr.Column():
142
- audio_output = gr.Audio(label="Generated Speech", autoplay=True)
143
- download_btn = gr.DownloadButton(
144
- label="Download Audio",
145
- visible=False
146
- )
147
 
148
- # Interactive components
149
  generate_btn.click(
150
  fn=text_to_speech,
151
  inputs=[text_input, voice_dropdown],
152
- outputs=[audio_output, download_btn]
153
- )
154
-
155
- audio_output.change(
156
- fn=lambda x: {"visible": bool(x)},
157
- inputs=audio_output,
158
- outputs=download_btn
159
  )
160
 
161
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import edge_tts
3
  import asyncio
 
4
  from typing import Dict
5
 
6
  async def generate_speech(text: str, voice: str) -> str:
 
107
  "Sofie (Female, NL)": "nl-NL-SofieNeural",
108
  }
109
 
110
+ def text_to_speech(text: str, voice: str) -> str:
111
+ """Wrapper function to run async code and return audio file"""
112
  if not text or not voice:
113
+ return None
114
+ return asyncio.run(generate_speech(text, VOICES.get(voice, VOICES["Jenny (Female, US)"])))
 
115
 
116
+ with gr.Blocks(title="Text-to-Speech", theme="soft") as demo:
117
+ gr.Markdown("## Text-to-Speech Converter")
118
+ text_input = gr.Textbox(
119
+ label="Enter your text",
120
+ placeholder="Type or paste your text here...",
121
+ lines=5,
122
+ max_lines=10
123
+ )
124
+ voice_dropdown = gr.Dropdown(
125
+ choices=list(VOICES.keys()),
126
+ label="Select Voice",
127
+ value="Jenny (Female, US)"
128
+ )
129
+ generate_btn = gr.Button("Generate Speech", variant="primary")
130
+ audio_output = gr.Audio(label="Listen to Speech", autoplay=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
 
132
  generate_btn.click(
133
  fn=text_to_speech,
134
  inputs=[text_input, voice_dropdown],
135
+ outputs=audio_output
 
 
 
 
 
 
136
  )
137
 
138
  if __name__ == "__main__":