Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -18,9 +18,9 @@ async def get_voices():
|
|
18 |
# Text-to-speech function
|
19 |
async def text_to_speech(text, voice, rate, pitch):
|
20 |
if not text.strip():
|
21 |
-
return None, "Please enter text to convert."
|
22 |
if not voice:
|
23 |
-
return None, "Please select a voice."
|
24 |
|
25 |
# Очистка текста
|
26 |
text = clean_text(text)
|
@@ -34,76 +34,19 @@ async def text_to_speech(text, voice, rate, pitch):
|
|
34 |
try:
|
35 |
await communicate.save(tmp_path)
|
36 |
except Exception as e:
|
37 |
-
return None, f"An error occurred during text-to-speech conversion: {str(e)}"
|
38 |
return tmp_path, None
|
39 |
# Gradio interface function
|
40 |
-
def tts_interface(
|
41 |
-
|
42 |
-
|
43 |
-
audio, warning = loop.run_until_complete(text_to_speech(*args))
|
44 |
-
loop.close()
|
45 |
-
if warning:
|
46 |
-
return None, gr.update(value=f"<span style='color:red;'>{warning}</span>", visible=True)
|
47 |
-
return audio, gr.update(visible=False)
|
48 |
-
# Custom CSS
|
49 |
-
custom_css = """
|
50 |
-
body {
|
51 |
-
background: linear-gradient(45deg, #ff7e5f, #feb47b);
|
52 |
-
animation: gradient 15s ease infinite;
|
53 |
-
font-family: 'Arial', sans-serif;
|
54 |
-
}
|
55 |
-
@keyframes gradient {
|
56 |
-
0% { background-position: 0% 50%; }
|
57 |
-
50% { background-position: 100% 50%; }
|
58 |
-
100% { background-position: 0% 50%; }
|
59 |
-
}
|
60 |
-
.gradio-container {
|
61 |
-
background-color: rgba(255, 255, 255, 0.1);
|
62 |
-
border-radius: 10px;
|
63 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
64 |
-
padding: 20px;
|
65 |
-
}
|
66 |
-
button {
|
67 |
-
background: linear-gradient(45deg, #ff7e5f, #feb47b);
|
68 |
-
border: none;
|
69 |
-
color: white;
|
70 |
-
padding: 10px 20px;
|
71 |
-
text-align: center;
|
72 |
-
text-decoration: none;
|
73 |
-
display: inline-block;
|
74 |
-
font-size: 16px;
|
75 |
-
margin: 4px 2px;
|
76 |
-
cursor: pointer;
|
77 |
-
border-radius: 5px;
|
78 |
-
transition: background 0.3s;
|
79 |
-
}
|
80 |
-
button:hover {
|
81 |
-
background: linear-gradient(45deg, #feb47b, #ff7e5f);
|
82 |
-
}
|
83 |
-
textarea, select, input[type="range"] {
|
84 |
-
background-color: rgba(255, 255, 255, 0.2);
|
85 |
-
border: 1px solid rgba(255, 255, 255, 0.3);
|
86 |
-
color: white;
|
87 |
-
padding: 10px;
|
88 |
-
border-radius: 5px;
|
89 |
-
transition: background 0.3s;
|
90 |
-
}
|
91 |
-
textarea:focus, select:focus, input[type="range"]:focus {
|
92 |
-
background-color: rgba(255, 255, 255, 0.3);
|
93 |
-
}
|
94 |
-
.warning {
|
95 |
-
color: red;
|
96 |
-
}
|
97 |
-
"""
|
98 |
# Create Gradio application
|
99 |
async def create_demo():
|
100 |
voices = await get_voices()
|
101 |
|
102 |
description = """
|
103 |
-
<p style="color: white;">This is a simple text-to-speech application using Microsoft Edge TTS.</p>
|
104 |
-
<p style="color: white;">You can enter any text and select the voice you want to use.</p>
|
105 |
-
<p style="color: white;">Adjust the speech rate and pitch according to your preference.</p>
|
106 |
"""
|
|
|
107 |
demo = gr.Interface(
|
108 |
fn=tts_interface,
|
109 |
inputs=[
|
@@ -114,14 +57,13 @@ async def create_demo():
|
|
114 |
],
|
115 |
outputs=[
|
116 |
gr.Audio(label="Generated Audio", type="filepath"),
|
117 |
-
gr.
|
118 |
],
|
119 |
title="Edge TTS Text-to-Speech",
|
120 |
description=description,
|
121 |
article="",
|
122 |
analytics_enabled=False,
|
123 |
-
allow_flagging="manual"
|
124 |
-
css=custom_css
|
125 |
)
|
126 |
return demo
|
127 |
# Run the application
|
|
|
18 |
# Text-to-speech function
|
19 |
async def text_to_speech(text, voice, rate, pitch):
|
20 |
if not text.strip():
|
21 |
+
return None, gr.Warning("Please enter text to convert.")
|
22 |
if not voice:
|
23 |
+
return None, gr.Warning("Please select a voice.")
|
24 |
|
25 |
# Очистка текста
|
26 |
text = clean_text(text)
|
|
|
34 |
try:
|
35 |
await communicate.save(tmp_path)
|
36 |
except Exception as e:
|
37 |
+
return None, gr.Warning(f"An error occurred during text-to-speech conversion: {str(e)}")
|
38 |
return tmp_path, None
|
39 |
# Gradio interface function
|
40 |
+
def tts_interface(text, voice, rate, pitch):
|
41 |
+
audio, warning = asyncio.run(text_to_speech(text, voice, rate, pitch))
|
42 |
+
return audio, warning
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
# Create Gradio application
|
44 |
async def create_demo():
|
45 |
voices = await get_voices()
|
46 |
|
47 |
description = """
|
|
|
|
|
|
|
48 |
"""
|
49 |
+
|
50 |
demo = gr.Interface(
|
51 |
fn=tts_interface,
|
52 |
inputs=[
|
|
|
57 |
],
|
58 |
outputs=[
|
59 |
gr.Audio(label="Generated Audio", type="filepath"),
|
60 |
+
gr.Markdown(label="Warning", visible=False)
|
61 |
],
|
62 |
title="Edge TTS Text-to-Speech",
|
63 |
description=description,
|
64 |
article="",
|
65 |
analytics_enabled=False,
|
66 |
+
allow_flagging="manual"
|
|
|
67 |
)
|
68 |
return demo
|
69 |
# Run the application
|