First commit
Browse files- README.md +1 -1
- app.py +140 -0
- requirements.txt +2 -0
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: π
|
|
4 |
colorFrom: indigo
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
short_description: Simple text to speech Edge
|
|
|
4 |
colorFrom: indigo
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.36.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
short_description: Simple text to speech Edge
|
app.py
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import edge_tts
|
3 |
+
import asyncio
|
4 |
+
import tempfile
|
5 |
+
import os
|
6 |
+
|
7 |
+
# Custom CSS for clean, modern appearance
|
8 |
+
CUSTOM_CSS = """
|
9 |
+
body {
|
10 |
+
background-color: #ffffff; /* White background */
|
11 |
+
color: #333333; /* Dark text */
|
12 |
+
font-family: 'Poppins', sans-serif;
|
13 |
+
}
|
14 |
+
|
15 |
+
.gradio-container {
|
16 |
+
background-color: #ffffff;
|
17 |
+
border-radius: 15px;
|
18 |
+
padding: 20px;
|
19 |
+
border: 1px solid #e0e0e0;
|
20 |
+
}
|
21 |
+
|
22 |
+
.gr-button {
|
23 |
+
background-color: #FFA500 !important; /* Orange buttons */
|
24 |
+
border: none !important;
|
25 |
+
color: #ffffff !important; /* White text */
|
26 |
+
font-size: 16px;
|
27 |
+
font-weight: bold;
|
28 |
+
border-radius: 8px;
|
29 |
+
padding: 10px 20px;
|
30 |
+
transition: all 0.3s ease-in-out;
|
31 |
+
}
|
32 |
+
|
33 |
+
.gr-button:hover {
|
34 |
+
background-color: #ff8c00 !important; /* Darker orange on hover */
|
35 |
+
}
|
36 |
+
|
37 |
+
.gr-slider, .gr-dropdown, .gr-textbox {
|
38 |
+
background-color: #f9f9f9 !important; /* Light input background */
|
39 |
+
border-color: #d1d1d1 !important;
|
40 |
+
color: #333333 !important;
|
41 |
+
}
|
42 |
+
|
43 |
+
.gr-slider .gr-label, .gr-dropdown .gr-label, .gr-textbox .gr-label {
|
44 |
+
color: #333333 !important; /* Darker labels */
|
45 |
+
}
|
46 |
+
|
47 |
+
h1, h2, h3, p, label {
|
48 |
+
color: #333333 !important;
|
49 |
+
}
|
50 |
+
|
51 |
+
a {
|
52 |
+
color: #FFA500;
|
53 |
+
text-decoration: none;
|
54 |
+
font-weight: bold;
|
55 |
+
}
|
56 |
+
|
57 |
+
a:hover {
|
58 |
+
color: #ff8c00;
|
59 |
+
}
|
60 |
+
|
61 |
+
footer {
|
62 |
+
display: none; /* Hide default footer */
|
63 |
+
}
|
64 |
+
"""
|
65 |
+
|
66 |
+
async def get_voices():
|
67 |
+
voices = await edge_tts.list_voices()
|
68 |
+
voice_dict = {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
|
69 |
+
return voice_dict
|
70 |
+
|
71 |
+
async def text_to_speech(text, voice, rate, pitch):
|
72 |
+
if not text.strip():
|
73 |
+
return None, "Please enter text to convert."
|
74 |
+
if not voice:
|
75 |
+
return None, "Please select a voice."
|
76 |
+
|
77 |
+
voice_short_name = voice.split(" - ")[0]
|
78 |
+
rate_str = f"{rate:+d}%"
|
79 |
+
pitch_str = f"{pitch:+d}Hz"
|
80 |
+
communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
|
81 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
82 |
+
tmp_path = tmp_file.name
|
83 |
+
await communicate.save(tmp_path)
|
84 |
+
return tmp_path, None
|
85 |
+
|
86 |
+
async def tts_interface(text, voice, rate, pitch):
|
87 |
+
audio, warning = await text_to_speech(text, voice, rate, pitch)
|
88 |
+
if warning:
|
89 |
+
return audio, gr.Warning(warning)
|
90 |
+
return audio, None
|
91 |
+
|
92 |
+
async def create_demo():
|
93 |
+
voices = await get_voices()
|
94 |
+
default_voice = "en-US-AvaNeural - en-US (Female)"
|
95 |
+
|
96 |
+
description = """
|
97 |
+
Convert text to speech using Microsoft Edge TTS. Adjust speech rate and pitch: 0 is default, positive values increase, negative values decrease.
|
98 |
+
|
99 |
+
Take your content creation to the next level with our cutting-edge Text-to-Video Converter!
|
100 |
+
Transform your words into stunning, professional-quality videos in just a few clicks.
|
101 |
+
|
102 |
+
β¨ Features:
|
103 |
+
β’ Convert text to engaging videos with customizable visuals
|
104 |
+
β’ Perfect for creating audiobooks, storytelling, and language learning materials
|
105 |
+
β’ Ideal for educators, content creators, and language enthusiasts
|
106 |
+
|
107 |
+
For mor information [Click here to try our blog now!](https://ruslanmv.com/)
|
108 |
+
"""
|
109 |
+
|
110 |
+
demo = gr.Interface(
|
111 |
+
fn=tts_interface,
|
112 |
+
inputs=[
|
113 |
+
gr.Textbox(label="Input Text", lines=5, placeholder="Type your text here..."),
|
114 |
+
gr.Dropdown(choices=["", default_voice] + list(voices.keys()), label="Select Voice", value=default_voice),
|
115 |
+
gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1),
|
116 |
+
gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)
|
117 |
+
],
|
118 |
+
outputs=[
|
119 |
+
gr.Audio(label="Generated Audio", type="filepath"),
|
120 |
+
gr.Markdown(label="Warning", visible=False)
|
121 |
+
],
|
122 |
+
title="π Edge TTS Text-to-Speech Converter",
|
123 |
+
description=description,
|
124 |
+
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!",
|
125 |
+
analytics_enabled=False,
|
126 |
+
allow_flagging="manual",
|
127 |
+
api_name=None,
|
128 |
+
theme="default"
|
129 |
+
)
|
130 |
+
|
131 |
+
demo.css = CUSTOM_CSS
|
132 |
+
return demo
|
133 |
+
|
134 |
+
async def main():
|
135 |
+
demo = await create_demo()
|
136 |
+
demo.queue(default_concurrency_limit=5)
|
137 |
+
demo.launch(show_api=False)
|
138 |
+
|
139 |
+
if __name__ == "__main__":
|
140 |
+
asyncio.run(main())
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
edge_tts==6.1.12
|
2 |
+
gradio==4.36.1
|