Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,57 +2,9 @@ import gradio as gr
|
|
| 2 |
import edge_tts
|
| 3 |
import asyncio
|
| 4 |
import tempfile
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
# -----------------------------
|
| 8 |
-
#
|
| 9 |
-
# -----------------------------
|
| 10 |
-
async def get_voices():
|
| 11 |
-
voices = await edge_tts.list_voices()
|
| 12 |
-
# Keep label style similar to ElevenLabs voice list (clean, informative)
|
| 13 |
-
voice_labels = [
|
| 14 |
-
f"{v['ShortName']} - {v['Locale']} ({v['Gender']})"
|
| 15 |
-
for v in voices
|
| 16 |
-
]
|
| 17 |
-
# Sort alphabetically for nicer UI
|
| 18 |
-
voice_labels.sort()
|
| 19 |
-
return voice_labels
|
| 20 |
-
|
| 21 |
-
async def text_to_speech(text, voice, rate, pitch):
|
| 22 |
-
if not text.strip():
|
| 23 |
-
return None, "Please enter some text to synthesize."
|
| 24 |
-
|
| 25 |
-
if not voice:
|
| 26 |
-
return None, "Please select a voice."
|
| 27 |
-
|
| 28 |
-
# Voice label is like: "en-US-AriaNeural - en-US (Female)"
|
| 29 |
-
voice_short_name = voice.split(" - ")[0].strip()
|
| 30 |
-
|
| 31 |
-
rate_str = f"{rate:+d}%"
|
| 32 |
-
pitch_str = f"{pitch:+d}Hz"
|
| 33 |
-
|
| 34 |
-
communicate = edge_tts.Communicate(
|
| 35 |
-
text=text,
|
| 36 |
-
voice=voice_short_name,
|
| 37 |
-
rate=rate_str,
|
| 38 |
-
pitch=pitch_str,
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
# Save to temporary MP3 file
|
| 42 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 43 |
-
tmp_path = tmp_file.name
|
| 44 |
-
await communicate.save(tmp_path)
|
| 45 |
-
|
| 46 |
-
return tmp_path, None
|
| 47 |
-
|
| 48 |
-
async def tts_interface(text, voice, rate, pitch):
|
| 49 |
-
audio, warning = await text_to_speech(text, voice, rate, pitch)
|
| 50 |
-
if warning:
|
| 51 |
-
return audio, gr.Warning(warning)
|
| 52 |
-
return audio, None
|
| 53 |
-
|
| 54 |
-
# -----------------------------
|
| 55 |
-
# Eburon Speech – ElevenLabs-like UI
|
| 56 |
# -----------------------------
|
| 57 |
EBURON_CSS = """
|
| 58 |
body {
|
|
@@ -235,12 +187,64 @@ select, input[type="range"] {
|
|
| 235 |
}
|
| 236 |
"""
|
| 237 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
async def create_demo():
|
| 239 |
voices = await get_voices()
|
| 240 |
|
|
|
|
| 241 |
with gr.Blocks(
|
| 242 |
analytics_enabled=False,
|
| 243 |
-
css=EBURON_CSS,
|
| 244 |
title="Eburon Speech Studio"
|
| 245 |
) as demo:
|
| 246 |
# Header
|
|
@@ -356,15 +360,22 @@ async def create_demo():
|
|
| 356 |
generate_btn.click(
|
| 357 |
fn=tts_interface,
|
| 358 |
inputs=[text_input, voice_dropdown, rate_slider, pitch_slider],
|
| 359 |
-
outputs=[audio_output, warning_md]
|
| 360 |
)
|
| 361 |
|
| 362 |
return demo
|
| 363 |
|
|
|
|
| 364 |
async def main():
|
| 365 |
demo = await create_demo()
|
| 366 |
demo.queue(default_concurrency_limit=50)
|
| 367 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
|
| 369 |
if __name__ == "__main__":
|
| 370 |
asyncio.run(main())
|
|
|
|
| 2 |
import edge_tts
|
| 3 |
import asyncio
|
| 4 |
import tempfile
|
|
|
|
| 5 |
|
| 6 |
# -----------------------------
|
| 7 |
+
# Custom CSS for Eburon Speech UI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# -----------------------------
|
| 9 |
EBURON_CSS = """
|
| 10 |
body {
|
|
|
|
| 187 |
}
|
| 188 |
"""
|
| 189 |
|
| 190 |
+
# -----------------------------
|
| 191 |
+
# Core TTS helpers
|
| 192 |
+
# -----------------------------
|
| 193 |
+
async def get_voices():
|
| 194 |
+
voices = await edge_tts.list_voices()
|
| 195 |
+
voice_labels = [
|
| 196 |
+
f"{v['ShortName']} - {v['Locale']} ({v['Gender']})"
|
| 197 |
+
for v in voices
|
| 198 |
+
]
|
| 199 |
+
voice_labels.sort()
|
| 200 |
+
return voice_labels
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
async def text_to_speech(text, voice, rate, pitch):
|
| 204 |
+
if not text.strip():
|
| 205 |
+
return None, "Please enter some text to synthesize."
|
| 206 |
+
|
| 207 |
+
if not voice:
|
| 208 |
+
return None, "Please select a voice."
|
| 209 |
+
|
| 210 |
+
# Voice label: "en-US-AriaNeural - en-US (Female)"
|
| 211 |
+
voice_short_name = voice.split(" - ")[0].strip()
|
| 212 |
+
|
| 213 |
+
rate_str = f"{rate:+d}%"
|
| 214 |
+
pitch_str = f"{pitch:+d}Hz"
|
| 215 |
+
|
| 216 |
+
communicate = edge_tts.Communicate(
|
| 217 |
+
text=text,
|
| 218 |
+
voice=voice_short_name,
|
| 219 |
+
rate=rate_str,
|
| 220 |
+
pitch=pitch_str,
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
# Save to temporary MP3 file
|
| 224 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 225 |
+
tmp_path = tmp_file.name
|
| 226 |
+
await communicate.save(tmp_path)
|
| 227 |
+
|
| 228 |
+
return tmp_path, None
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
async def tts_interface(text, voice, rate, pitch):
|
| 232 |
+
audio, warning = await text_to_speech(text, voice, rate, pitch)
|
| 233 |
+
if warning:
|
| 234 |
+
# Gradio 6: Warning modal object
|
| 235 |
+
return audio, gr.Warning(warning)
|
| 236 |
+
return audio, None
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
# -----------------------------
|
| 240 |
+
# Eburon Speech – ElevenLabs-like UI
|
| 241 |
+
# -----------------------------
|
| 242 |
async def create_demo():
|
| 243 |
voices = await get_voices()
|
| 244 |
|
| 245 |
+
# Gradio 6: do NOT pass css to Blocks, move it to demo.launch()
|
| 246 |
with gr.Blocks(
|
| 247 |
analytics_enabled=False,
|
|
|
|
| 248 |
title="Eburon Speech Studio"
|
| 249 |
) as demo:
|
| 250 |
# Header
|
|
|
|
| 360 |
generate_btn.click(
|
| 361 |
fn=tts_interface,
|
| 362 |
inputs=[text_input, voice_dropdown, rate_slider, pitch_slider],
|
| 363 |
+
outputs=[audio_output, warning_md],
|
| 364 |
)
|
| 365 |
|
| 366 |
return demo
|
| 367 |
|
| 368 |
+
|
| 369 |
async def main():
|
| 370 |
demo = await create_demo()
|
| 371 |
demo.queue(default_concurrency_limit=50)
|
| 372 |
+
|
| 373 |
+
# Gradio 6: css + footer_links go in launch(), show_api is removed
|
| 374 |
+
demo.launch(
|
| 375 |
+
css=EBURON_CSS,
|
| 376 |
+
footer_links=["gradio", "settings"], # hides API link (like show_api=False)
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
|
| 380 |
if __name__ == "__main__":
|
| 381 |
asyncio.run(main())
|