Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse files- README.md +23 -7
- app.py +139 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,13 +1,29 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.29.1
|
| 8 |
-
python_version: '3.12'
|
| 9 |
app_file: app.py
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: EMA Lightning
|
| 3 |
+
emoji: ⚡
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.29.1
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
+
short_description: Turkish TTS from an 8.6M-param flow-matching model
|
| 10 |
+
python_version: "3.12"
|
| 11 |
+
startup_duration_timeout: 30m
|
| 12 |
---
|
| 13 |
|
| 14 |
+
Turkish text-to-speech with **EMA Lightning** — a 5.6M-parameter DiT acoustic
|
| 15 |
+
model plus a 3M-parameter vocoder: 8.6M parameters in total, about 34 MB,
|
| 16 |
+
Apache-2.0. It reads Turkish characters directly, expands digits, dates,
|
| 17 |
+
times and currency to spoken Turkish, and synthesizes 48 kHz speech in four
|
| 18 |
+
ODE steps. 0.92% WER on Freya-TR-Eval, the lowest of every system measured,
|
| 19 |
+
including ElevenLabs v4, Gemini 3.8 and the 2.38B-parameter Trendyol-TTS.
|
| 20 |
+
|
| 21 |
+
The Space runs the authors' own [`ema-lightning`](https://pypi.org/project/ema-lightning/)
|
| 22 |
+
pip package against the checkpoint at
|
| 23 |
+
[canberkkkkkk/ema-lightning](https://huggingface.co/canberkkkkkk/ema-lightning).
|
| 24 |
+
One fixed voice, no cloning. Example sentences are the authors' own
|
| 25 |
+
showcase texts from the model card.
|
| 26 |
+
|
| 27 |
+
- [Model card](https://huggingface.co/canberkkkkkk/ema-lightning)
|
| 28 |
+
- [GitHub](https://github.com/canberk7/ema-lightning)
|
| 29 |
+
- [Text frontend: normalizer-tr](https://github.com/erdemtuna/normalizer-tr)
|
app.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""EMA Lightning — tiny, fast and accurate Turkish text-to-speech on ZeroGPU.
|
| 2 |
+
|
| 3 |
+
The model authors' own pip package (`ema-lightning`) provides the whole
|
| 4 |
+
inference path: the text frontend (normalizer-tr), the 5.6M-parameter DiT
|
| 5 |
+
acoustic model and the 3M-parameter decoder, both read from the Apache-2.0
|
| 6 |
+
checkpoint at canberkkkkkk/ema-lightning. 48 kHz speech in four ODE steps.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import spaces # MUST come before torch / any CUDA-touching import
|
| 10 |
+
|
| 11 |
+
import time
|
| 12 |
+
|
| 13 |
+
import gradio as gr
|
| 14 |
+
import numpy as np
|
| 15 |
+
from ema_lightning import EMA
|
| 16 |
+
|
| 17 |
+
MAX_CHARS = 1200 # keeps the whole request well inside a few seconds of GPU
|
| 18 |
+
|
| 19 |
+
# Module-scope load: ZeroGPU intercepts .to("cuda") and packs the ~34 MB of
|
| 20 |
+
# weights to disk, streaming them into VRAM on the first @spaces.GPU call.
|
| 21 |
+
tts = EMA()
|
| 22 |
+
SAMPLE_RATE = 48000
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@spaces.GPU(duration=30)
|
| 26 |
+
def synthesize(text: str, speed: float = 1.0, seed: int = 0, sample_rate: int = 48000):
|
| 27 |
+
"""Synthesize Turkish speech from text with EMA Lightning.
|
| 28 |
+
|
| 29 |
+
Args:
|
| 30 |
+
text: Turkish text to read. Digits, dates, times, currency and
|
| 31 |
+
percentages are expanded to spoken Turkish automatically; any
|
| 32 |
+
written Turkish is accepted and text never raises.
|
| 33 |
+
speed: Speaking rate, from 0.25 (four times slower) to 4 (four
|
| 34 |
+
times faster). 1.0 is the natural pace.
|
| 35 |
+
seed: Fixes the noise draw for a reproducible result. The voice is
|
| 36 |
+
fixed regardless of seed.
|
| 37 |
+
sample_rate: Output audio rate: 48000, 24000, 16000 or 8000 Hz.
|
| 38 |
+
|
| 39 |
+
Returns:
|
| 40 |
+
A tuple of (sample_rate, waveform) for Gradio's Audio component.
|
| 41 |
+
"""
|
| 42 |
+
text = (text or "").strip()
|
| 43 |
+
if not text:
|
| 44 |
+
raise gr.Error("Lütfen okunacak bir metin girin. / Please enter some text.")
|
| 45 |
+
if len(text) > MAX_CHARS:
|
| 46 |
+
raise gr.Error(
|
| 47 |
+
f"Metin çok uzun ({len(text)} karakter). Lütfen {MAX_CHARS} karakterin "
|
| 48 |
+
f"altına indirin. / Text too long ({len(text)} chars); keep it under "
|
| 49 |
+
f"{MAX_CHARS}."
|
| 50 |
+
)
|
| 51 |
+
speed = float(speed)
|
| 52 |
+
if not 0.25 <= speed <= 4:
|
| 53 |
+
speed = 1.0
|
| 54 |
+
seed = max(0, int(seed))
|
| 55 |
+
sample_rate = int(sample_rate) if int(sample_rate) in (48000, 24000, 16000, 8000) else 48000
|
| 56 |
+
t0 = time.perf_counter()
|
| 57 |
+
speech = tts.say(text, speed=speed, seed=seed, sample_rate=sample_rate)
|
| 58 |
+
print(
|
| 59 |
+
f"[ema-lightning] {len(text)} chars, speed={speed}, seed={seed} -> "
|
| 60 |
+
f"{time.perf_counter() - t0:.2f}s synth, {speech.duration:.2f}s audio",
|
| 61 |
+
flush=True,
|
| 62 |
+
)
|
| 63 |
+
return (speech.sample_rate, np.asarray(speech.audio, dtype=np.float32))
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
CSS = """
|
| 67 |
+
#col-container { max-width: 900px; margin: 0 auto; }
|
| 68 |
+
.dark .gradio-container { color: var(--body-text-color); }
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
|
| 72 |
+
gr.Markdown(
|
| 73 |
+
"# ⚡ EMA Lightning — Turkish Text-to-Speech\n"
|
| 74 |
+
"An 8.6M-parameter (34 MB) flow-matching TTS that reads Turkish "
|
| 75 |
+
"characters directly and synthesizes 48 kHz speech in four ODE steps — "
|
| 76 |
+
"**0.92% WER on "
|
| 77 |
+
"[Freya-TR-Eval](https://huggingface.co/datasets/freyavoice/freya-tr-eval)**, "
|
| 78 |
+
"the lowest of every system measured, including ElevenLabs v4, Gemini 3.8 "
|
| 79 |
+
"and the 2.38B-parameter Trendyol-TTS. One fixed voice, no cloning, "
|
| 80 |
+
"Apache-2.0.\n\n"
|
| 81 |
+
"[Model card](https://huggingface.co/canberkkkkkk/ema-lightning) · "
|
| 82 |
+
"[PyPI package](https://pypi.org/project/ema-lightning/) · "
|
| 83 |
+
"Numbers, dates, times and currency are expanded to spoken Turkish "
|
| 84 |
+
"before the model reads them."
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
with gr.Column(elem_id="col-container"):
|
| 88 |
+
text_input = gr.Textbox(
|
| 89 |
+
label="Turkish text",
|
| 90 |
+
placeholder="Merhaba, size nasıl yardımcı olabilirim?",
|
| 91 |
+
lines=4,
|
| 92 |
+
value="Merhaba, size nasıl yardımcı olabilirim?",
|
| 93 |
+
)
|
| 94 |
+
run_btn = gr.Button("Generate Speech", variant="primary")
|
| 95 |
+
audio_output = gr.Audio(label="Generated speech", type="numpy")
|
| 96 |
+
|
| 97 |
+
with gr.Accordion("Advanced settings", open=False):
|
| 98 |
+
speed_slider = gr.Slider(
|
| 99 |
+
minimum=0.25, maximum=4.0, value=1.0, step=0.05,
|
| 100 |
+
label="Speed",
|
| 101 |
+
info="Speaking rate. 1.0 is the natural pace.",
|
| 102 |
+
)
|
| 103 |
+
seed_input = gr.Number(
|
| 104 |
+
label="Seed",
|
| 105 |
+
value=0, precision=0,
|
| 106 |
+
info="Fixes the noise draw for a reproducible result. "
|
| 107 |
+
"The voice is fixed regardless of seed.",
|
| 108 |
+
)
|
| 109 |
+
rate_dropdown = gr.Dropdown(
|
| 110 |
+
choices=[48000, 24000, 16000, 8000],
|
| 111 |
+
value=48000,
|
| 112 |
+
label="Sample rate (Hz)",
|
| 113 |
+
info="The model generates at 48 kHz and resamples cleanly.",
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
gr.Examples(
|
| 117 |
+
examples=[
|
| 118 |
+
["Model sadece sekiz 8.6 milyon parametre ve çok hızlı.", 1.0, 0, 48000],
|
| 119 |
+
["15 Ekim 2026 Çarşamba günü saat 14:30'da, 1.250.000 TL "
|
| 120 |
+
"tutarındaki ödemeniz hesabınıza yatırılacak.", 1.0, 0, 48000],
|
| 121 |
+
["Sabahın erken saatlerinde liman henüz uyanmamıştı. "
|
| 122 |
+
"Balıkçılar ağlarını sessizce topluyor, martılar ise "
|
| 123 |
+
"teknelerin etrafında dönerek şanslarını deniyordu.", 1.0, 0, 48000],
|
| 124 |
+
],
|
| 125 |
+
inputs=[text_input, speed_slider, seed_input, rate_dropdown],
|
| 126 |
+
outputs=[audio_output],
|
| 127 |
+
fn=synthesize,
|
| 128 |
+
cache_examples=True,
|
| 129 |
+
cache_mode="lazy",
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
run_btn.click(
|
| 133 |
+
fn=synthesize,
|
| 134 |
+
inputs=[text_input, speed_slider, seed_input, rate_dropdown],
|
| 135 |
+
outputs=[audio_output],
|
| 136 |
+
api_name="synthesize",
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ema-lightning
|
| 2 |
+
numpy
|