lodhrangpt commited on
Commit
5091aa5
·
verified ·
1 Parent(s): e478b84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -5
app.py CHANGED
@@ -1,8 +1,40 @@
1
- async def create_demo():
2
- voices = await get_voices()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- # Remove the description or replace it with a custom message
5
- description = "" # Set to an empty string if you don't want any description
6
 
7
  demo = gr.Interface(
8
  fn=tts_interface,
@@ -17,9 +49,14 @@ async def create_demo():
17
  gr.Markdown(label="Warning", visible=False)
18
  ],
19
  title="Edge TTS Text-to-Speech",
20
- description=description, # Updated to remove unwanted content
21
  article="Experience the power of Edge TTS for text-to-speech conversion!",
22
  analytics_enabled=False,
23
  allow_flagging="manual"
24
  )
25
  return demo
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import edge_tts
3
+ import asyncio
4
+ import tempfile
5
+ import os
6
+
7
+ # Get all available voices
8
+ def get_voices():
9
+ voices = asyncio.run(edge_tts.list_voices())
10
+ return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
11
+
12
+ # Text-to-speech function
13
+ async def text_to_speech(text, voice, rate, pitch):
14
+ if not text.strip():
15
+ return None, gr.Warning("Please enter text to convert.")
16
+ if not voice:
17
+ return None, gr.Warning("Please select a voice.")
18
+
19
+ voice_short_name = voice.split(" - ")[0]
20
+ rate_str = f"{rate:+d}%"
21
+ pitch_str = f"{pitch:+d}Hz"
22
+ communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
23
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
24
+ tmp_path = tmp_file.name
25
+ await communicate.save(tmp_path)
26
+ return tmp_path, None
27
+
28
+ # Synchronous wrapper for text_to_speech
29
+ def tts_interface(text, voice, rate, pitch):
30
+ audio, warning = asyncio.run(text_to_speech(text, voice, rate, pitch))
31
+ return audio, warning
32
+
33
+ # Create Gradio application
34
+ def create_demo():
35
+ voices = get_voices()
36
 
37
+ description = "Convert text to speech using Microsoft Edge TTS. Adjust speech rate and pitch: 0 is default, positive values increase, negative values decrease."
 
38
 
39
  demo = gr.Interface(
40
  fn=tts_interface,
 
49
  gr.Markdown(label="Warning", visible=False)
50
  ],
51
  title="Edge TTS Text-to-Speech",
52
+ description=description,
53
  article="Experience the power of Edge TTS for text-to-speech conversion!",
54
  analytics_enabled=False,
55
  allow_flagging="manual"
56
  )
57
  return demo
58
+
59
+ # Run the application
60
+ if __name__ == "__main__":
61
+ demo = create_demo()
62
+ demo.launch()