Sanyam400 commited on
Commit
0cf6e0e
·
verified ·
1 Parent(s): 40ebf5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -9,9 +9,11 @@ async def text_to_speech(text, voice, rate, pitch):
9
  if not voice:
10
  raise gr.Error("Please select a voice.")
11
 
 
12
  rate_str = f"{rate:+d}%"
13
  pitch_str = f"{pitch:+d}Hz"
14
 
 
15
  communicate = edge_tts.Communicate(
16
  text=text,
17
  voice=voice,
@@ -19,34 +21,33 @@ async def text_to_speech(text, voice, rate, pitch):
19
  pitch=pitch_str
20
  )
21
 
 
22
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
23
  tmp_path = tmp_file.name
24
  await communicate.save(tmp_path)
25
 
26
  return tmp_path
27
 
28
-
29
  async def get_voices():
30
  voices = await edge_tts.list_voices()
31
  return sorted([v["ShortName"] for v in voices])
32
 
33
-
34
  async def create_demo():
35
  voices = await get_voices()
36
 
37
  with gr.Blocks() as demo:
38
- gr.Markdown("# 🎙️ Edge TTS API Ready")
39
 
40
  text_input = gr.Textbox(label="Input Text", lines=4)
41
  voice_dropdown = gr.Dropdown(
42
  choices=voices,
43
  label="Voice",
44
- value=voices[0]
45
  )
46
  rate_slider = gr.Slider(-50, 50, value=0, step=1, label="Rate (%)")
47
  pitch_slider = gr.Slider(-20, 20, value=0, step=1, label="Pitch (Hz)")
48
 
49
- generate_btn = gr.Button("Generate")
50
 
51
  audio_output = gr.Audio(type="filepath")
52
 
@@ -58,12 +59,10 @@ async def create_demo():
58
 
59
  return demo
60
 
61
-
62
  async def main():
63
  demo = await create_demo()
64
- demo.queue()
65
- demo.launch(show_api=True) # IMPORTANT
66
-
67
 
68
  if __name__ == "__main__":
69
  asyncio.run(main())
 
9
  if not voice:
10
  raise gr.Error("Please select a voice.")
11
 
12
+ # Adjust rate & pitch
13
  rate_str = f"{rate:+d}%"
14
  pitch_str = f"{pitch:+d}Hz"
15
 
16
+ # Create EdgeTTS communicate object
17
  communicate = edge_tts.Communicate(
18
  text=text,
19
  voice=voice,
 
21
  pitch=pitch_str
22
  )
23
 
24
+ # Save to temp file
25
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
26
  tmp_path = tmp_file.name
27
  await communicate.save(tmp_path)
28
 
29
  return tmp_path
30
 
 
31
  async def get_voices():
32
  voices = await edge_tts.list_voices()
33
  return sorted([v["ShortName"] for v in voices])
34
 
 
35
  async def create_demo():
36
  voices = await get_voices()
37
 
38
  with gr.Blocks() as demo:
39
+ gr.Markdown("# 🎙️ Edge TTS Text-to-Speech API 🚀")
40
 
41
  text_input = gr.Textbox(label="Input Text", lines=4)
42
  voice_dropdown = gr.Dropdown(
43
  choices=voices,
44
  label="Voice",
45
+ value=voices[0] if voices else ""
46
  )
47
  rate_slider = gr.Slider(-50, 50, value=0, step=1, label="Rate (%)")
48
  pitch_slider = gr.Slider(-20, 20, value=0, step=1, label="Pitch (Hz)")
49
 
50
+ generate_btn = gr.Button("Generate Speech")
51
 
52
  audio_output = gr.Audio(type="filepath")
53
 
 
59
 
60
  return demo
61
 
 
62
  async def main():
63
  demo = await create_demo()
64
+ # No show_api argument needed
65
+ demo.launch()
 
66
 
67
  if __name__ == "__main__":
68
  asyncio.run(main())