xome commited on
Commit
42d1f2f
·
verified ·
1 Parent(s): 25b6308

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +79 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import edge_tts
3
+ import asyncio
4
+ import tempfile
5
+ import os
6
+
7
+ async def get_voices():
8
+ voices = await edge_tts.list_voices()
9
+ return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
10
+
11
+ async def text_to_speech(text, voice, rate, pitch):
12
+ if not text.strip():
13
+ return None, "Please enter text to convert."
14
+ if not voice:
15
+ return None, "Please select a voice."
16
+
17
+ voice_short_name = voice.split(" - ")[0]
18
+ rate_str = f"{rate:+d}%"
19
+ pitch_str = f"{pitch:+d}Hz"
20
+ communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
21
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
22
+ tmp_path = tmp_file.name
23
+ await communicate.save(tmp_path)
24
+ return tmp_path, None
25
+
26
+ async def tts_interface(text, voice, rate, pitch):
27
+ audio, warning = await text_to_speech(text, voice, rate, pitch)
28
+ if warning:
29
+ return audio, gr.Warning(warning)
30
+ return audio, None
31
+
32
+ async def create_demo():
33
+ voices = await get_voices()
34
+
35
+ description = """
36
+ Convert text to speech using Microsoft Edge TTS. Adjust speech rate and pitch: 0 is default, positive values increase, negative values decrease.
37
+
38
+ 🎥 **Exciting News: Introducing our Text-to-Video Converter!** 🎥
39
+
40
+ Take your content creation to the next level with our cutting-edge Text-to-Video Converter!
41
+ Transform your words into stunning, professional-quality videos in just a few clicks.
42
+
43
+ ✨ Features:
44
+ • Convert text to engaging videos with customizable visuals
45
+ • Choose from 40+ languages and 300+ voices
46
+ • Perfect for creating audiobooks, storytelling, and language learning materials
47
+ • Ideal for educators, content creators, and language enthusiasts
48
+
49
+ Ready to revolutionize your content? [Click here to try our Text-to-Video Converter now!](https://text2video.wingetgui.com/)
50
+ """
51
+
52
+ demo = gr.Interface(
53
+ fn=tts_interface,
54
+ inputs=[
55
+ gr.Textbox(label="Input Text", lines=5),
56
+ gr.Dropdown(choices=[""] + list(voices.keys()), label="Select Voice", value=""),
57
+ gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1),
58
+ gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)
59
+ ],
60
+ outputs=[
61
+ gr.Audio(label="Generated Audio", type="filepath"),
62
+ gr.Markdown(label="Warning", visible=False)
63
+ ],
64
+ title="Edge TTS Text-to-Speech",
65
+ description=description,
66
+ 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!",
67
+ analytics_enabled=False,
68
+ allow_flagging="manual",
69
+ api_name=None
70
+ )
71
+ return demo
72
+
73
+ async def main():
74
+ demo = await create_demo()
75
+ demo.queue(default_concurrency_limit=5)
76
+ demo.launch(show_api=False)
77
+
78
+ if __name__ == "__main__":
79
+ asyncio.run(main())
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ edge_tts==6.1.12
2
+ gradio==4.36.1