walidadebayo commited on
Commit
f870ddf
·
1 Parent(s): 5aaf75f

Add application file

Browse files
Files changed (3) hide show
  1. .gitignore +3 -0
  2. app.py +90 -0
  3. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .venv
2
+ .gradio
3
+ flagged
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import edge_tts
3
+ import asyncio
4
+ import tempfile
5
+ import os
6
+
7
+
8
+ async def get_voices():
9
+ voices = await edge_tts.list_voices()
10
+ return {
11
+ f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v["ShortName"]
12
+ for v in voices
13
+ }
14
+
15
+
16
+ async def text_to_speech(text, voice, rate, pitch):
17
+ if not text.strip():
18
+ return None, "Please enter text to convert."
19
+ if not voice:
20
+ return None, "Please select a voice."
21
+
22
+ voice_short_name = voice.split(" - ")[0]
23
+ rate_str = f"{rate:+d}%"
24
+ pitch_str = f"{pitch:+d}Hz"
25
+ communicate = edge_tts.Communicate(
26
+ text, voice_short_name, rate=rate_str, pitch=pitch_str
27
+ )
28
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
29
+ tmp_path = tmp_file.name
30
+ await communicate.save(tmp_path)
31
+ return tmp_path, None
32
+
33
+
34
+ async def tts_interface(text, voice, rate, pitch):
35
+ audio, warning = await text_to_speech(text, voice, rate, pitch)
36
+ if warning:
37
+ return audio, gr.Warning(warning)
38
+ return audio, None
39
+
40
+
41
+ async def create_demo():
42
+ voices = await get_voices()
43
+
44
+ description = """
45
+ Convert text to speech using Microsoft Edge TTS. Adjust speech rate and pitch: 0 is default, positive values increase, negative values decrease.
46
+
47
+ **Note:** Edge TTS is a cloud-based service and requires an active internet connection."""
48
+
49
+ demo = gr.Interface(
50
+ fn=tts_interface,
51
+ inputs=[
52
+ gr.Textbox(label="Input Text", lines=5, value="Hello, how are you doing!"),
53
+ gr.Dropdown(
54
+ choices=[""] + list(voices.keys()),
55
+ label="Select Voice",
56
+ value=list(voices.keys())[0] if voices else "",
57
+ ),
58
+ gr.Slider(
59
+ minimum=-50,
60
+ maximum=50,
61
+ value=0,
62
+ label="Speech Rate Adjustment (%)",
63
+ step=1,
64
+ ),
65
+ gr.Slider(
66
+ minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1
67
+ ),
68
+ ],
69
+ outputs=[
70
+ gr.Audio(label="Generated Audio", type="filepath"),
71
+ gr.Markdown(label="Warning", visible=False),
72
+ ],
73
+ title="Edge TTS Text-to-Speech",
74
+ description=description,
75
+ article="Experience the power of Edge TTS for text-to-speech conversion, and explore our advanced Text-to-Video Converter for even more creative possibilities!",
76
+ analytics_enabled=False,
77
+ flagging_mode="manual",
78
+ api_name="predict",
79
+ )
80
+ return demo
81
+
82
+
83
+ async def main():
84
+ demo = await create_demo()
85
+ demo.queue(default_concurrency_limit=50)
86
+ demo.launch(show_api=True, show_error=True)
87
+
88
+
89
+ if __name__ == "__main__":
90
+ asyncio.run(main())
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ edge_tts==6.1.12
2
+ gradio==5.24.0
3
+ pydub==0.25.1