Taklaxbr commited on
Commit
2bdc53e
·
verified ·
1 Parent(s): cd298b3

Update README.md via veripazari.com.tr Admin

Browse files
Files changed (1) hide show
  1. README.md +116 -116
README.md CHANGED
@@ -12,7 +12,7 @@ tags:
12
  creator: canberkkkkkk
13
  ---
14
 
15
- > Not: Bu model orijinal olarak **canberkkkkkk** tarafından geliştirilmiş olup, VeriPazarı tarafından Türk yapay zeka topluluğuna katkı sağlamak amacıyla orijinal dokümantasyonu korunarak arşivlenmiştir.
16
  >
17
  > 🔗 Orijinal Kaynak: [canberkkkkkk/ema-lightning](https://huggingface.co/canberkkkkkk/ema-lightning)
18
  > 🔗 Derleyen Platform: [VeriPazarı](https://veripazari.com.tr)
@@ -21,26 +21,26 @@ creator: canberkkkkkk
21
 
22
  # ⚡ EMA Lightning
23
 
24
- **Tiny, fast and accurate Turkish text to speech.** A 5.6M-parameter DiT acoustic model and a 3M-parameter vocoder: 8.6M in total, about 34 MB. Apache 2.0.
25
 
26
- - **Most accurate on Freya-TR-Eval:** 0.92% WER, the lowest of every system measured, including ElevenLabs v4, Gemini 3.8 and the 2.38B-parameter Trendyol-TTS.
27
- - **Fast:** first audio in 3.86 ms and 440× faster than real time on an RTX 4090; 1,316× with batching.
28
- - **Streams:** audio starts while the rest of the text is still being generated.
29
- - **Cheap:** about $0.0085 per million characters on a rented RTX 4090.
30
- - **Runs anywhere:** GPU or CPU, fully offline. No API key, and no text or audio leaves the machine.
31
- - **One model serves many callers:** call it from as many threads as you like; its scheduler, Playhead, runs everyone's work together on the GPU.
32
 
33
- - **Code:** [EMA Lightning on GitHub][github]
34
- - **Package:** [`pip install ema-lightning`](https://pypi.org/project/ema-lightning/)
35
- - **Text frontend:** [normalizer-tr](https://github.com/erdemtuna/normalizer-tr), by Erdem Tuna
36
 
37
- ![EMA Lightning architecture](https://huggingface.co/veripazari/ema-lightning/resolve/main/assets/architecture.png)
38
 
39
- **Figure 1.** Text is encoded per letter, placed on a word–letter timeline by a duration predictor, turned into one condition per frame by a windowed aligner, generated as latents in four steps by a DiT, and decoded to 48 kHz audio. Details under [Architecture](#architecture).
40
 
41
- ## Listen
42
 
43
- Every clip below is made with `say()` at seed 0, straight from the text shown.
44
 
45
  **Model sadece 8.6 milyon parametre ve çok hızlı.**
46
  <audio controls src="https://huggingface.co/veripazari/ema-lightning/resolve/main/assets/sample-1.wav"></audio>
@@ -51,37 +51,37 @@ Every clip below is made with `say()` at seed 0, straight from the text shown.
51
  **Sabahın erken saatlerinde liman henüz uyanmamıştı. Balıkçılar ağlarını sessizce topluyor, martılar ise teknelerin etrafında dönerek şanslarını deniyordu.**
52
  <audio controls src="https://huggingface.co/veripazari/ema-lightning/resolve/main/assets/sample-3.wav"></audio>
53
 
54
- ## Quickstart
55
 
56
  ```bash
57
  pip install ema-lightning
58
  ```
59
 
60
- Make one `EMA` and keep it for the whole program. There are two ways to get speech out of it:
61
 
62
  | | `say()` | `stream()` |
63
  |---|---|---|
64
- | Gives you | the whole audio, once it's ready | the audio piece by piece, as it's made |
65
- | Takes | one text, or a list of texts | one text per call |
66
- | Use it for | files, voiceovers, batch jobs | playing as you go: speakers, phone calls, live apps |
67
 
68
- ### `say()`: a whole text, back when it's ready
69
 
70
  ```python
71
  from ema_lightning import EMA
72
 
73
- tts = EMA() # downloads ema.pt and decoder.pt, uses the GPU if there is one
74
  speech = tts.say("Merhaba, size nasıl yardımcı olabilirim?", path="merhaba.wav")
75
- print(speech.duration, speech.sample_rate) # seconds of audio, 48000
76
  ```
77
 
78
- `say()` returns a `Speech`: the `audio` (a float32 NumPy array, mono, between -1 and 1), its `sample_rate`, its `duration` in seconds, and the `seed` that made it. With `path`, it also writes a WAV file. A list is made in shared batches, one `Speech` per text, in order; with `path`, the clips go into that folder as `0.wav`, `1.wav`, …:
79
 
80
  ```python
81
  speeches = tts.say(["Günaydın.", "Siparişiniz yola çıktı.", "İyi günler dileriz."], path="clips")
82
  ```
83
 
84
- ### `stream()`: hear it while it's being made
85
 
86
  ```python
87
  import sounddevice as sd # pip install sounddevice
@@ -92,9 +92,9 @@ with sd.OutputStream(samplerate=48000, channels=1, dtype="float32") as speaker:
92
  speaker.write(chunk)
93
  ```
94
 
95
- The first chunk is one second of audio and is ready in about 4 ms on a GPU. The rest follows four seconds at a time, far faster than it plays, so playback never waits. Leave the loop early and the rest of that text's work is dropped. Joined together, the chunks are the same audio `say()` gives.
96
 
97
- `stream()` takes one text per call. To stream many texts at once, call it once per text, each from its own thread. All the calls share the model, and Playhead runs them together on the GPU:
98
 
99
  ```python
100
  from concurrent.futures import ThreadPoolExecutor
@@ -105,47 +105,47 @@ texts = ["Merhaba, size nasıl yardımcı olabilirim?", "Siparişiniz yola çık
105
  def stream_one(text):
106
  chunks = []
107
  for chunk in tts.stream(text):
108
- chunks.append(chunk) # in a real app: send it to this caller right away
109
  return chunks
110
 
111
 
112
  with ThreadPoolExecutor(max_workers=len(texts)) as pool:
113
- results = list(pool.map(stream_one, texts)) # one list of chunks per text, in the same order
114
  ```
115
 
116
- ### `.lightning()`: the fast path on NVIDIA GPUs
117
 
118
  ```python
119
  tts = EMA().lightning()
120
  ```
121
 
122
- Call it once at startup. It measures the best batch size for your GPU (once, then cached), compiles the model, records CUDA graphs, checks them against the plain path and prints when it's ready, with its first-audio time. Without it, or on a CPU, everything works the same, just slower.
123
 
124
- | Option | Values | Default |
125
  |---|---|---|
126
- | `speed` | 0.25 to 4 | 1.0 |
127
- | `seed` | non-negative integer; the same seed gives the same audio | random (returned in `speech.seed`) |
128
  | `sample_rate` | 48000, 24000, 16000, 8000 | 48000 |
129
- | `path` | `say()` only: a `.wav` file for one text, a folder for a list | none |
130
 
131
- Any text is accepted, and text never raises. Invalid settings raise `ValueError` before any work starts.
132
 
133
- ## One model, many callers
134
 
135
- ![Playhead: callers, the two queues and the GPU, and one turn of the loop](https://huggingface.co/veripazari/ema-lightning/resolve/main/assets/playhead.svg)
136
 
137
- Every `say()` and `stream()` call goes through Playhead, a scheduler inside `EMA`. A GPU making one sentence at a time is mostly idle, so Playhead collects what every caller needs at that moment and runs it together. It keeps two first-come-first-served queues: sentences waiting for the model, and audio windows waiting for the decoder. Each turn, it takes up to one batch from the front of each, makes them in one pass each on the GPU, and hands every window straight back to the call that asked for it, in order. Nobody's sentences are overtaken, a caller who hangs up leaves the queues, and a batch that fails fails only its own callers.
138
 
139
- On one RTX PRO 6000, 64 streams started at the same instant made 887 seconds of audio in 0.74 seconds, and every one matched its text said alone.
140
 
141
- ## Benchmarks
142
 
143
- Freya-TR-Eval, all 495 sentences, speed 1.0:
144
 
145
- | # | System | Params | Size vs EMA | WER % | CER % | RTF | × real time | x real time (batch 64) | GPU memory |
146
  |---|---|---|---|---|---|---|---|---|---|
147
- | 1 | **EMA Lightning (compiled)** | **5.6M DiT + 3M decoder** | **1×** | **0.92 ± 0.13** | **0.18** | **0.0023** | **440×** | **1,316×** | — |
148
- | 1 | **EMA Lightning (plain PyTorch)** | **5.6M DiT + 3M decoder** | **1×** | **0.92 ± 0.13** | **0.18** | **0.0115** | **87×** | **952×** | **0.28 GB; 1.39 GB at batch 64** |
149
  | 2 | Trendyol-TTS | 2.38B | 277× | 0.98 ± 0.15 | 0.19 ± 0.03 | 0.360 | 2.8× | — | — |
150
  | 3 | Gemini 3.8 Flash-Lite | — | — | 1.31 ± 0.13 | 0.28 ± 0.02 | — | — | — | — |
151
  | 4 | Gemini 3.8 Flash | — | — | 1.35 ± 0.23 | 0.28 ± 0.06 | — | — | — | — |
@@ -159,118 +159,117 @@ Freya-TR-Eval, all 495 sentences, speed 1.0:
159
  | 12 | Antalia 1 ‡ | 305M | 35× | 6.88 ± 0.34 | 2.72 ± 0.21 | 0.328 | 3.0× | — | — |
160
  | 13 | Coqui GlowTTS (tr) † | 28M | 3.3× | 10.75 | 2.92 | 0.016 | 63× | — | — |
161
  | 14 | FreyaTTS † | 183M | 21× | 12.02 | 4.95 | 0.119 | 8.4× | — | — |
162
- | 15 | F5 base (no Turkish) † | 336M | 39× | 77.84 ± 0.13 | 32.58 ± 0.54 | 0.146 | 6.8× | — | — |
163
-
164
 
165
- - **Our runs** (every row without †): all 495 sentences, 3 seeds or takes, raw text in, an 8 kHz band, Whisper large-v3 with beam 5, and Freya's text normalisation. ElevenLabs uses its default voice (George) with default settings. Gemini uses the voice Kore.
166
- - **† marks numbers as reported on the Anka TTS model card.**
167
- - **All RTFs are measured on an RTX 4090**, as total generation time divided by total audio length, three passes after a warm-up, middle pass reported. Cloud APIs have no RTF or parameter count.
168
- - **"±" is the spread across the three seeds.** EMA Lightning's spread comes from its lowest, highest and average result (0.79 to 1.05%); its CER has no spread.
169
- - **‡** "Antalia 1" by Sezgin Saygili, Emre Kaplaner, Oncel Ozgul and Fikri San Koktas (Patientdesk.ai): [huggingface.co/cloud0day3/antalia-1](https://huggingface.co/cloud0day3/antalia-1). Three of its takes failed inside its own code and count as silence.
170
 
171
- ### Speed and cost
172
 
173
- All on an RTX 4090 with `.lightning()`:
174
 
175
  | | |
176
  |---|---|
177
- | One request | 440× real time (RTF 0.0023) |
178
- | First audio, typical | 3.86 ms, from raw text, normalisation included |
179
- | Batch of 64 | 1,316× real time; plain PyTorch 952× |
180
- | A 6 h 7 min audiobook, batched | about 17 seconds |
181
- | Cost at $0.74/hour | about $0.0085 per million characters (24,091 characters a second) |
182
- | CPU | about 6× real time (RTF 0.166, measured on a cloud-container CPU) |
183
 
184
- ## Architecture
185
 
186
- **Figure 1 (top of this card).** **(a)** Overview. Normalized Turkish text is encoded per letter; a duration predictor and a word–letter timeline place every output frame at a word and a position within it; a windowed aligner builds one condition per frame; a latent generator produces 64-dimensional latents at 25 Hz in four steps; a decoder upsamples them ×1920 to 48 kHz audio. **(b)** Windowed Gaussian aligner. Each frame attends only to letters of its own word and the adjacent words, with a Gaussian bias around its position. **(c)** DiT block with shared timestep modulation. One linear layer maps the timestep embedding to all modulation parameters; each of the six blocks adds a learned offset.
187
 
188
- | Part | File | Parameters |
189
  |---|---|---|
190
- | Acoustic model: text encoder, durations, windowed aligner and the DiT latent generator | `ema.pt` | 5.6M |
191
- | Vocoder: the HiFi-GAN-style decoder from latents to 48 kHz audio | `decoder.pt` | 3.0M |
192
- | **Total** | | **8.6M** |
193
-
194
- The acoustic model stays at 5.6M partly through shared modulation (Fig. 1c, below): one projection serves all six DiT blocks, which takes the modulation parameters from 1.81M to 0.31M.
195
-
196
- **Text encoder.** Input text is normalized to spoken-form Turkish with [normalizer-tr](https://github.com/erdemtuna/normalizer-tr) and lowercased. Letters are embedded in *d* = 224 dimensions and encoded by four ConvNeXt blocks followed by two self-attention blocks with RoPE, giving **h** ∈ ℝ<sup>*L*×*d*</sup>.
197
-
198
- **Word–letter timeline.** A convolutional duration predictor estimates the number of frames *d̂*<sub>ℓ</sub> for each letter ℓ. Durations are grouped by word: each word receives the frames of its letters, and each letter receives a position *π*<sub>ℓ</sub> ∈ [0, 1] within its word *w*<sub>ℓ</sub>. Each output frame *f* is likewise assigned a word *w*<sub>*f*</sub> and a position *π*<sub>*f*</sub>. The duration model is trained without external alignments.
199
-
200
- **Windowed Gaussian aligner (Fig. 1b).** With *p* = *w* + *π*, frame *f* attends to letter ℓ through
201
-
202
  $$
203
  \alpha_{f\ell} = \operatorname{softmax}_{\ell}\left( \tau \, \frac{\mathbf{q}_f^{\top} \mathbf{k}_\ell}{\sqrt{d}} - \beta \, \frac{(p_f - p_\ell)^2}{2\sigma^2} \right), \qquad |w_f - w_\ell| \le 1, \tag{1}
204
  $$
205
-
206
  $$
207
  \mathbf{c}_f = \mathbf{W}_o \sum_{\ell} \alpha_{f\ell} \, \mathbf{v}_\ell, \tag{2}
208
  $$
209
-
210
- where **q**<sub>*f*</sub> and **k**<sub>ℓ</sub> are rotated by RoPE at *p*<sub>*f*</sub> and *p*<sub>ℓ</sub>, and *τ*, *β* and *σ* are learned per head. Letters outside the window are masked. The conditions **c** ∈ ℝ<sup>*T*×*d*</sup> are computed once per utterance.
211
-
212
- **Latent generator with shared modulation (Fig. 1c).** Six DiT blocks (8 heads, RoPE over frames, SwiGLU feed-forward) predict a flow-matching velocity on latents **z** ∈ ℝ<sup>*T*×64</sup>. Instead of one adaptive-norm projection per block, a single projection **W** is shared by all blocks:
213
-
214
  $$
215
  [\boldsymbol{\gamma}_1, \boldsymbol{\beta}_1, \boldsymbol{\alpha}_1, \boldsymbol{\gamma}_2, \boldsymbol{\beta}_2, \boldsymbol{\alpha}_2]_k = \mathbf{W} \, \operatorname{SiLU}(\mathbf{e}(t)) + \boldsymbol{\delta}_k, \tag{3}
216
  $$
217
-
218
  $$
219
  \operatorname{Mod}(\mathbf{x}) = \operatorname{LN}(\mathbf{x}) \odot (1 + \boldsymbol{\gamma}) + \boldsymbol{\beta}, \tag{4}
220
  $$
221
-
222
- with a learned offset **δ**<sub>*k*</sub> ∈ ℝ<sup>6×*d*</sup> per block. This reduces the modulation parameters from 1.81M to 0.31M.
223
-
224
- **Sampling: four steps, distilled with DMD2.** The latent generator was first trained as an ordinary flow-matching model. That teacher has the same architecture and the same 5.6M parameters, and samples with 16 midpoint steps: 32 passes of the network per sentence. The shipped generator is a student distilled from it with DMD2 ([Yin et al., 2024](https://arxiv.org/abs/2405.14867)), and it needs four steps, at *t* ∈ {0, ¼, ½, ¾}. Each step predicts the clean latents
225
-
226
  $$
227
  \hat{\mathbf{z}}_1 = \mathbf{z}_t + (1 - t)\, v_\theta(\mathbf{z}_t, t, \mathbf{c}), \tag{5}
228
  $$
229
 
230
- **Decoder.** A HiFi-GAN-style generator with upsampling factors (8, 6, 5, 2, 2, 2) maps the 25 Hz latents to 48 kHz audio. Latents are decoded in 4 s windows with 8 frames of context on each side, so the joined output is identical to decoding the whole utterance at once; a stream's first window is 1 s, so its first audio comes early.
231
-
232
- **Inference.** `.lightning()` enables cuDNN benchmark mode, compiles the model once for any batch size, and records CUDA graphs at batch sizes 1, 2, 4 and every multiple of 8 up to the measured batch size, for length buckets of 32, 64, 128 and 256 letters and 40, 80, 160 and 320 frames, and decoder windows of 48 and 120 frames. Each batch is padded only to the nearest recorded size. The compiled path is verified against the eager path at startup.
233
 
234
- ## Files
235
 
236
- | File | What it is |
 
 
237
  |---|---|
238
- | `ema.pt` | acoustic model: text encoder, durations, aligner, latent generator (5.6M) |
239
- | `decoder.pt` | decoder, latents to 48 kHz audio (3M) |
240
- | `assets/architecture.png` | the architecture figure |
241
- | `assets/playhead.png` | the Playhead figure |
242
- | `samples/` | the example clips under [Listen](#listen), made with `say()` at seed 0 |
 
 
243
 
244
- ## Training data
245
 
246
- An internal corpus of about 1,000 hours of single-speaker Turkish speech, all synthetic, generated with [VoxCPM2](https://huggingface.co/openbmb/VoxCPM2) (OpenBMB, Apache 2.0). The voice is not a real person's: it was designed in VoxCPM2 from a short text description, with no recording of anyone as a reference.
247
 
248
- ## Limitations
 
 
 
249
 
250
- - **One voice.** No voice cloning and no emotion control.
251
- - **Turkish only.** Foreign words are read with Turkish spelling rules.
252
- - **Naturalness is good, not the best.** UTMOS is about 3.30 on Freya-TR-Eval: level with ElevenLabs v4 (3.30), below Gemini 3.8 (3.52 to 3.61) and Trendyol-TTS (3.83).
253
- - **WER is measured by Whisper,** so some of the counted errors are the recogniser's.
254
 
255
- ## Responsible use
256
-
257
- EMA Lightning makes synthetic speech, and people who hear it should know that. Tell listeners they are hearing an AI-generated voice, for example at the start of a call ("Bu görüşmede yapay zekâ ile üretilmiş bir ses kullanılmaktadır."), and label the audio you publish the same way ("Bu ses yapay zekâ ile üretilmiştir."); laws in many places, including the EU AI Act, require this disclosure. Do not present it as a real person's voice, use it in scams or impersonation, or make it say things a real person did not say. Numbers, dates and abbreviations are read through automatic text normalization, which can misread unusual input, so for banking, health, legal or emergency messages, have a person check the text and the audio before it reaches anyone.
258
 
259
- ## Disclaimer
260
-
261
- EMA Lightning is provided "as is", without warranty of any kind, under the Apache License 2.0. The authors are not liable for how it is used or for any damage arising from its use. Whoever deploys it is responsible for using it lawfully, including the disclosure and consent rules that apply where it is used. This section is not legal advice.
262
 
263
- ## License
264
 
265
- Apache 2.0, for the weights and the code. Commercial use included.
266
 
267
- ## Acknowledgements
268
 
269
- Special thanks to **[Erdem Tuna](https://github.com/erdemtuna)**, who built [normalizer-tr](https://github.com/erdemtuna/normalizer-tr), the Turkish text normalizer behind EMA Lightning. Every number, date, amount and symbol you hear read aloud goes through his work.
270
 
271
- Thanks also to **Freya** for the Freya-TR-Eval benchmark, and to **the Anka TTS authors** for the published baselines marked †.
272
 
273
- ## Citation
 
 
274
 
275
  ```bibtex
276
  @misc{aslan2026emalightning,
@@ -284,4 +283,5 @@ Thanks also to **Freya** for the Freya-TR-Eval benchmark, and to **the Anka TTS
284
  [github]: https://github.com/canberk7/ema-lightning
285
 
286
  ---
 
287
  *Bu dosya veripazari.com.tr topluluğu tarafından Hugging Face altyapısında barındırılmaktadır. Orijinal emeğe saygı gereği lisans, metadata ve kaynak referansları korunmuştur.*
 
12
  creator: canberkkkkkk
13
  ---
14
 
15
+ > Not: Bu model orijinal olarak **canberkkkkkk** tarafından geliştirilmiş olup, VeriPazarı tarafından Türk yapay zeka topluluğuna katkı sağlamak amacıyla dokümantasyonu Türkçeye çevrilerek arşivlenmiştir.
16
  >
17
  > 🔗 Orijinal Kaynak: [canberkkkkkk/ema-lightning](https://huggingface.co/canberkkkkkk/ema-lightning)
18
  > 🔗 Derleyen Platform: [VeriPazarı](https://veripazari.com.tr)
 
21
 
22
  # ⚡ EMA Lightning
23
 
24
+ **Küçük, hızlı ve doğru Türkçe metinden sese dönüştürme.** 5,6 milyon parametreli bir DiT akustik modeli ve 3 milyon parametreli bir vokoder: toplamda 8,6 milyon parametre ve yaklaşık 34 MB boyutunda. Apache 2.0 lisanslıdır.
25
 
26
+ - **Freya-TR-Eval üzerinde en yüksek doğruluk:** %0,92 WER (Kelime Hata Oranı) ile ElevenLabs v4, Gemini 3.8 ve 2,38 milyar parametreli Trendyol-TTS dahil olmak üzere ölçülen tüm sistemler arasında en düşük hata oranına sahiptir.
27
+ - **Hızlı:** RTX 4090 üzerinde 3,86 ms'de ilk ses çıktısı ve gerçek zamanlıdan 440 kat daha hızlı; toplu işlem (batching) ile 1.316 kat daha hızlı.
28
+ - **Akış (Streaming):** Metnin geri kalanı henüz oluşturulurken ses çalmaya başlar.
29
+ - **Ekonomik:** Kiralanmış bir RTX 4090 üzerinde milyon karakter başına yaklaşık 0,0085 $.
30
+ - **Her yerde çalışır:** GPU veya CPU üzerinde, tamamen çevrimdışı. API anahtarı gerektirmez; hiçbir metin veya ses verisi makineden dışarı çıkmaz.
31
+ - **Tek model, çoklu kullanıcı:** İstediğiniz kadar iş parçacığından (thread) çağırabilirsiniz; zamanlayıcısı olan Playhead, herkesin işini GPU üzerinde birlikte yürütür.
32
 
33
+ - **Kod:** [GitHub üzerinde EMA Lightning][github]
34
+ - **Paket:** [`pip install ema-lightning`](https://pypi.org/project/ema-lightning/)
35
+ - **Metin önişleme:** [normalizer-tr](https://github.com/erdemtuna/normalizer-tr), Erdem Tuna tarafından.
36
 
37
+ ![EMA Lightning mimarisi](https://huggingface.co/veripazari/ema-lightning/resolve/main/assets/architecture.png)
38
 
39
+ **Şekil 1.** Metin harf bazında kodlanır, bir süre tahmincisi (duration predictor) tarafından kelime-harf zaman çizelgesine yerleştirilir, pencereli bir hizalayıcı tarafından kare başına bir koşula dönüştürülür, bir DiT tarafından dört adımda gizli değişkenler (latents) olarak üretilir ve 48 kHz sese çözümlenir. Detaylar [Mimari](#mimari) bölümündedir.
40
 
41
+ ## Dinle
42
 
43
+ Aşağıdaki her klip, seed 0 kullanılarak ve gösterilen metinden doğrudan `say()` fonksiyonu ile oluşturulmuştur.
44
 
45
  **Model sadece 8.6 milyon parametre ve çok hızlı.**
46
  <audio controls src="https://huggingface.co/veripazari/ema-lightning/resolve/main/assets/sample-1.wav"></audio>
 
51
  **Sabahın erken saatlerinde liman henüz uyanmamıştı. Balıkçılar ağlarını sessizce topluyor, martılar ise teknelerin etrafında dönerek şanslarını deniyordu.**
52
  <audio controls src="https://huggingface.co/veripazari/ema-lightning/resolve/main/assets/sample-3.wav"></audio>
53
 
54
+ ## Hızlı Başlangıç
55
 
56
  ```bash
57
  pip install ema-lightning
58
  ```
59
 
60
+ Bir `EMA` nesnesi oluşturun ve tüm program boyunca bunu kullanın. Sesi elde etmenin iki yolu vardır:
61
 
62
  | | `say()` | `stream()` |
63
  |---|---|---|
64
+ | Çıktı | Hazır olduğunda tüm ses | Üretildikçe parça parça ses |
65
+ | Girdi | Bir metin veya metin listesi | Çağrı başına bir metin |
66
+ | Kullanım alanı | Dosyalar, seslendirmeler, toplu işler | Canlı oynatma: hoparlörler, telefon görüşmeleri, canlı uygulamalar |
67
 
68
+ ### `say()`: hazır olduğunda tüm metni döndürür
69
 
70
  ```python
71
  from ema_lightning import EMA
72
 
73
+ tts = EMA() # ema.pt ve decoder.pt dosyalarını indirir, varsa GPU kullanır
74
  speech = tts.say("Merhaba, size nasıl yardımcı olabilirim?", path="merhaba.wav")
75
+ print(speech.duration, speech.sample_rate) # sesin saniye cinsinden süresi, 48000
76
  ```
77
 
78
+ `say()` bir `Speech` nesnesi döndürür: `audio` (float32 NumPy dizisi, mono, -1 ile 1 arasında), `sample_rate`, saniye cinsinden `duration` ve onu oluşturan `seed`. `path` parametresi ile bir WAV dosyası da yazar. Bir liste verildiğinde, paylaşılan gruplar halinde her metin için bir `Speech` nesnesi sırayla oluşturulur; `path` belirtilirse klipler klasöre `0.wav`, `1.wav`, ... şeklinde kaydedilir:
79
 
80
  ```python
81
  speeches = tts.say(["Günaydın.", "Siparişiniz yola çıktı.", "İyi günler dileriz."], path="clips")
82
  ```
83
 
84
+ ### `stream()`: üretilirken dinleyin
85
 
86
  ```python
87
  import sounddevice as sd # pip install sounddevice
 
92
  speaker.write(chunk)
93
  ```
94
 
95
+ İlk parça bir saniyelik sestir ve GPU üzerinde yaklaşık 4 ms'de hazır olur. Geri kalanı her seferinde dört saniyelik parçalar halinde gelir; oynatma hızından çok daha hızlı olduğu için oynatma asla beklemez. Döngüden erken çıkarsanız, metnin geri kalanının işlenmesi durdurulur. Parçalar birleştirildiğinde `say()` ile verilen sesin aynısı elde edilir.
96
 
97
+ `stream()` çağrı başına bir metin alır. Birçok metni aynı anda yayınlamak için her birini kendi iş parçacığından (thread) bir kez çağırın. Tüm çağrılar modeli paylaşır ve Playhead bunları GPU üzerinde birlikte çalıştırır:
98
 
99
  ```python
100
  from concurrent.futures import ThreadPoolExecutor
 
105
  def stream_one(text):
106
  chunks = []
107
  for chunk in tts.stream(text):
108
+ chunks.append(chunk) # gerçek bir uygulamada: hemen çağırana gönderin
109
  return chunks
110
 
111
 
112
  with ThreadPoolExecutor(max_workers=len(texts)) as pool:
113
+ results = list(pool.map(stream_one, texts)) # her metin için bir parça listesi, aynı sırada
114
  ```
115
 
116
+ ### `.lightning()`: NVIDIA GPU'larda hızlı yol
117
 
118
  ```python
119
  tts = EMA().lightning()
120
  ```
121
 
122
+ Başlangıçta bir kez çağırın. GPU'nuz için en iyi grup boyutunu (batch size) ölçer (bir kez, sonra önbelleğe alınır), modeli derler, CUDA grafiklerini kaydeder, bunları standart yolla karşılaştırır ve ilk ses süresiyle birlikte hazır olduğunda bildirir. Bu olmadan veya CPU üzerinde her şey aynı şekilde çalışır, sadece daha yavaştır.
123
 
124
+ | Seçenek | Değerler | Varsayılan |
125
  |---|---|---|
126
+ | `speed` | 0.25 ile 4 arası | 1.0 |
127
+ | `seed` | negatif olmayan tam sayı; aynı seed aynı sesi üretir | rastgele (speech.seed içinde döner) |
128
  | `sample_rate` | 48000, 24000, 16000, 8000 | 48000 |
129
+ | `path` | sadece `say()` için: tek metin için .wav dosyası, liste için klasör | yok |
130
 
131
+ Her türlü metin kabul edilir ve metin işleme asla hata vermez. Geçersiz ayarlar, herhangi bir işlem başlamadan önce `ValueError` hatası döndürür.
132
 
133
+ ## Tek model, çoklu kullanıcı
134
 
135
+ ![Playhead: çağrılar, iki kuyruk ve GPU, döngünün bir turu](https://huggingface.co/veripazari/ema-lightning/resolve/main/assets/playhead.svg)
136
 
137
+ Her `say()` ve `stream()` çağrısı, `EMA` içindeki bir zamanlayıcı olan Playhead'den geçer. Bir seferde tek bir cümle üreten bir GPU çoğunlukla boştadır; bu nedenle Playhead, her kullanıcının o anda ihtiyaç duyduğu şeyi toplar ve birlikte çalıştırır. İki adet "ilk gelen ilk hizmet alır" (FIFO) kuyruğu tutar: model için bekleyen cümleler ve kod çözücü (decoder) için bekleyen ses pencereleri. Her turda, her birinin önünden bir gruba kadar alır, GPU'da tek geçişte üretir ve her pencereyi sırayla talep eden çağrıya geri verir. Kimsenin cümlesi atlanmaz, bağlantıyı kesen bir kullanıcı kuyruktan çıkar ve başarısız olan bir grup sadece kendi kullanıcılarını etkiler.
138
 
139
+ Bir RTX PRO 6000 üzerinde, aynı anda başlatılan 64 akış, 0,74 saniyede 887 saniyelik ses üretti ve her biri tek başına söylenen metniyle eşleşti.
140
 
141
+ ## Kıyaslamalar (Benchmarks)
142
 
143
+ Freya-TR-Eval, 495 cümlenin tamamı, hız 1.0:
144
 
145
+ | # | Sistem | Parametre | Boyut (EMA'ya göre) | WER % | CER % | RTF | × gerçek zaman | x gerçek zaman (batch 64) | GPU belleği |
146
  |---|---|---|---|---|---|---|---|---|---|
147
+ | 1 | **EMA Lightning (derlenmiş)** | **5.6M DiT + 3M decoder** | **1×** | **0.92 ± 0.13** | **0.18** | **0.0023** | **440×** | **1,316×** | — |
148
+ | 1 | **EMA Lightning (standart PyTorch)** | **5.6M DiT + 3M decoder** | **1×** | **0.92 ± 0.13** | **0.18** | **0.0115** | **87×** | **952×** | **0.28 GB; 1.39 GB (batch 64)** |
149
  | 2 | Trendyol-TTS | 2.38B | 277× | 0.98 ± 0.15 | 0.19 ± 0.03 | 0.360 | 2.8× | — | — |
150
  | 3 | Gemini 3.8 Flash-Lite | — | — | 1.31 ± 0.13 | 0.28 ± 0.02 | — | — | — | — |
151
  | 4 | Gemini 3.8 Flash | — | — | 1.35 ± 0.23 | 0.28 ± 0.06 | — | — | — | — |
 
159
  | 12 | Antalia 1 ‡ | 305M | 35× | 6.88 ± 0.34 | 2.72 ± 0.21 | 0.328 | 3.0× | — | — |
160
  | 13 | Coqui GlowTTS (tr) † | 28M | 3.3× | 10.75 | 2.92 | 0.016 | 63× | — | — |
161
  | 14 | FreyaTTS † | 183M | 21× | 12.02 | 4.95 | 0.119 | 8.4× | — | — |
162
+ | 15 | F5 base (Türkçe değil) † | 336M | 39× | 77.84 ± 0.13 | 32.58 ± 0.54 | 0.146 | 6.8× | — | — |
 
163
 
164
+ - **Bizim testlerimiz** († işareti olmayan her satır): 495 cümlenin tamamı, 3 seed veya deneme, ham metin girişi, 8 kHz bant, beam 5 ile Whisper large-v3 ve Freya'nın metin normalizasyonu. ElevenLabs, varsayılan ayarlarıyla varsayılan sesini (George) kullanır. Gemini, Kore sesini kullanır.
165
+ - **† işareti, Anka TTS model kartında bildirilen sayıları belirtir.**
166
+ - **Tüm RTF değerleri RTX 4090 üzerinde ölçülmüştür.** Toplam üretim süresinin toplam ses uzunluğuna bölünmesiyle hesaplanmıştır; ısınma sonrası üç geçiş yapılmış ve orta değer raporlanmıştır. Bulut API'lerinin RTF veya parametre sayısı yoktur.
167
+ - **"±" üç seed arasındaki dağılımı gösterir.** EMA Lightning'in dağılımı en düşük, en yüksek ve ortalama sonucundan gelir (%0,79 ila %1,05); CER değerinin dağılımı yoktur.
168
+ - **‡** "Antalia 1", Sezgin Saygili, Emre Kaplaner, Oncel Ozgul ve Fikri San Koktas (Patientdesk.ai): [huggingface.co/cloud0day3/antalia-1](https://huggingface.co/cloud0day3/antalia-1). Üç denemesi kendi kodu içinde başarısız olmuş ve sessizlik olarak sayılmıştır.
169
 
170
+ ### Hız ve maliyet
171
 
172
+ Hepsi `.lightning()` ile RTX 4090 üzerinde:
173
 
174
  | | |
175
  |---|---|
176
+ | Tek istek | 440× gerçek zaman (RTF 0.0023) |
177
+ | İlk ses, tipik | 3,86 ms, ham metinden, normalizasyon dahil |
178
+ | 64'lü grup | 1.316× gerçek zaman; standart PyTorch 952× |
179
+ | 6 saat 7 dakikalık sesli kitap, gruplanmış | yaklaşık 17 saniye |
180
+ | 0,74 $/saat maliyetle | milyon karakter başına yaklaşık 0,0085 $ (saniyede 24.091 karakter) |
181
+ | CPU | yaklaşık 6× gerçek zaman (RTF 0.166, bulut konteyner CPU üzerinde ölçülmüştür) |
182
 
183
+ ## Mimari
184
 
185
+ **Şekil 1 (bu kartın üstü).** **(a)** Genel bakış. Normalleştirilmiş Türkçe metin harf bazında kodlanır; bir süre tahmincisi ve kelime-harf zaman çizelgesi her çıktı karesini bir kelimeye ve içindeki bir konuma yerleştirir; pencereli bir hizalayıcı kare başına bir koşul oluşturur; bir gizli değişken üreticisi 25 Hz'de 64 boyutlu değişkenleri dört adımda üretir; bir kod çözücü bunları ×1920 oranında 48 kHz sese yükseltir. **(b)** Pencereli Gauss hizalayıcı. Her kare sadece kendi kelimesinin ve komşu kelimelerin harflerine, konumunun etrafındaki bir Gauss sapmasıyla odaklanır. **(c)** Paylaşımlı zaman adımı modülasyonlu DiT bloğu. Bir doğrusal katman, zaman adımı gömmesini (embedding) tüm modülasyon parametrelerine eşler; altı bloğun her biri öğrenilmiş bir ofset ekler.
186
 
187
+ | Bölüm | Dosya | Parametreler |
188
  |---|---|---|
189
+ | Akustik model: metin kodlayıcı, süreler, pencereli hizalayıcı ve DiT gizli değişken üreticisi | `ema.pt` | 5.6M |
190
+ | Vokoder: gizli değişkenlerden 48 kHz sese HiFi-GAN tarzı kod çözücü | `decoder.pt` | 3.0M |
191
+ | **Toplam** | | **8.6M** |
192
+
193
+ Akustik model, kısmen paylaşımlı modülasyon sayesinde 5,6M parametrede kalır (Şekil 1c, aşağıda): tek bir projeksiyon tüm altı DiT bloğuna hizmet eder, bu da modülasyon parametrelerini 1,81M'den 0,31M'ye düşürür.
194
+
195
+ **Metin kodlayıcı.** Girdi metni [normalizer-tr](https://github.com/erdemtuna/normalizer-tr) ile konuşma formundaki Türkçeye normalleştirilir ve küçük harfe çevrilir. Harfler *d* = 224 boyutunda gömülür ve dört ConvNeXt bloğu ile ardından RoPE içeren iki öz-dikkat (self-attention) bloğu tarafından kodlanarak **h** ∈ ℝ<sup>*L*×*d*</sup> elde edilir.
196
+
197
+ **Kelime-harf zaman çizelgesi.** Evrişimli bir süre tahmincisi, her harf ℓ için kare sayısını *d̂*<sub>ℓ</sub> tahmin eder. Süreler kelimelere göre gruplanır: her kelime harflerinin karelerini alır ve her harf, kelimesi *w*<sub>ℓ</sub> içinde bir konum *π*<sub>ℓ</sub> ∈ [0, 1] alır. Her çıktı karesi *f* de benzer şekilde bir kelimeye *w*<sub>*f*</sub> ve bir konuma *π*<sub>*f*</sub> atanır. Süre modeli, harici hizalamalar olmadan eğitilir.
198
+
199
+ **Pencereli Gauss hizalayıcı (Şekil 1b).** *p* = *w* + *π* ile, kare *f*, harf ℓ'ye şu şekilde odaklanır:
200
+
201
  $$
202
  \alpha_{f\ell} = \operatorname{softmax}_{\ell}\left( \tau \, \frac{\mathbf{q}_f^{\top} \mathbf{k}_\ell}{\sqrt{d}} - \beta \, \frac{(p_f - p_\ell)^2}{2\sigma^2} \right), \qquad |w_f - w_\ell| \le 1, \tag{1}
203
  $$
204
+
205
  $$
206
  \mathbf{c}_f = \mathbf{W}_o \sum_{\ell} \alpha_{f\ell} \, \mathbf{v}_\ell, \tag{2}
207
  $$
208
+
209
+ burada **q**<sub>*f*</sub> ve **k**<sub>ℓ</sub>, *p*<sub>*f*</sub> ve *p*<sub>ℓ</sub> konumlarında RoPE ile döndürülür; *τ*, *β* ve *σ* her başlık (head) için öğrenilir. Pencere dışındaki harfler maskelenir. Koşullar **c** ∈ ℝ<sup>*T*×*d*</sup> her ifade için bir kez hesaplanır.
210
+
211
+ **Paylaşımlı modülasyonlu gizli değişken üreticisi (Şekil 1c).** Altı DiT bloğu (8 başlık, kareler üzerinde RoPE, SwiGLU feed-forward), gizli değişkenler **z** ∈ ℝ<sup>*T*×64</sup> üzerinde bir akış eşleştirme hızı (flow-matching velocity) tahmin eder. Blok başına bir uyarlanabilir norm projeksiyonu yerine, tek bir **W** projeksiyonu tüm bloklar tarafından paylaşılır:
212
+
213
  $$
214
  [\boldsymbol{\gamma}_1, \boldsymbol{\beta}_1, \boldsymbol{\alpha}_1, \boldsymbol{\gamma}_2, \boldsymbol{\beta}_2, \boldsymbol{\alpha}_2]_k = \mathbf{W} \, \operatorname{SiLU}(\mathbf{e}(t)) + \boldsymbol{\delta}_k, \tag{3}
215
  $$
216
+
217
  $$
218
  \operatorname{Mod}(\mathbf{x}) = \operatorname{LN}(\mathbf{x}) \odot (1 + \boldsymbol{\gamma}) + \boldsymbol{\beta}, \tag{4}
219
  $$
220
+
221
+ blok başına öğrenilmiş bir **δ**<sub>*k*</sub> ∈ ℝ<sup>6×*d*</sup> ofseti ile. Bu, modülasyon parametrelerini 1,81M'den 0,31M'ye düşürür.
222
+
223
+ **Örnekleme: dört adım, DMD2 ile damıtılmış.** Gizli değişken üreticisi ilk olarak sıradan bir akış eşleştirme modeli olarak eğitildi. Bu öğretmen model aynı mimariye ve aynı 5,6M parametreye sahiptir ve 16 orta nokta adımıyla örnekleme yapar: cümle başına 32 ağ geçişi. Dağıtılan üretici, DMD2 ([Yin et al., 2024](https://arxiv.org/abs/2405.14867)) ile ondan damıtılmış bir öğrencidir ve *t* ∈ {0, ¼, ½, ¾} değerlerinde dört adıma ihtiyaç duyar. Her adım temiz gizli değişkenleri tahmin eder:
224
+
225
  $$
226
  \hat{\mathbf{z}}_1 = \mathbf{z}_t + (1 - t)\, v_\theta(\mathbf{z}_t, t, \mathbf{c}), \tag{5}
227
  $$
228
 
229
+ **Kod çözücü.** (8, 6, 5, 2, 2, 2) yükseltme faktörlerine sahip HiFi-GAN tarzı bir üretici, 25 Hz gizli değişkenleri 48 kHz sese eşler. Gizli değişkenler, her iki tarafta 8 kare bağlam ile 4 saniyelik pencerelerde çözümlenir, böylece birleştirilmiş çıktı, tüm ifadeyi bir kerede çözümlemekle aynıdır; bir akışın ilk penceresi 1 saniyedir, bu nedenle ilk ses erken gelir.
 
 
230
 
231
+ **Çıkarım.** `.lightning()`, cuDNN benchmark modunu etkinleştirir, modeli herhangi bir grup boyutu için bir kez derler ve 1, 2, 4 grup boyutlarında ve ölçülen grup boyutuna kadar 8'in her katında, 32, 64, 128 ve 256 harf ile 40, 80, 160 ve 320 kare uzunluk grupları ve 48 ve 120 karelik kod çözücü pencereleri için CUDA grafiklerini kaydeder. Her grup sadece en yakın kaydedilmiş boyuta doldurulur. Derlenmiş yol, başlangıçta standart yolla doğrulanır.
232
 
233
+ ## Dosyalar
234
+
235
+ | Dosya | Açıklama |
236
  |---|---|
237
+ | `ema.pt` | akustik model: metin kodlayıcı, süreler, hizalayıcı, gizli değişken üreticisi (5.6M) |
238
+ | `decoder.pt` | kod çözücü, gizli değişkenlerden 48 kHz sese (3M) |
239
+ | `assets/architecture.png` | mimari şeması |
240
+ | `assets/playhead.png` | Playhead şeması |
241
+ | `samples/` | [Dinle](#dinle) bölümündeki örnek klipler, `say()` ile seed 0 kullanılarak yapılmıştır |
242
+
243
+ ## Eğitim verisi
244
 
245
+ Tamamı sentetik, [VoxCPM2](https://huggingface.co/openbmb/VoxCPM2) (OpenBMB, Apache 2.0) ile üretilmiş, yaklaşık 1.000 saatlik tek konuşmacılı Türkçe konuşma içeren dahili bir külliyat. Ses gerçek bir kişiye ait değildir: VoxCPM2'de kısa bir metin açıklamasından tasarlanmıştır, referans olarak herhangi birinin kaydı kullanılmamıştır.
246
 
247
+ ## Sınırlamalar
248
 
249
+ - **Tek ses.** Ses klonlama ve duygu kontrolü yoktur.
250
+ - **Sadece Türkçe.** Yabancı kelimeler Türkçe yazım kurallarına göre okunur.
251
+ - **Doğallık iyi, ancak en iyisi değil.** Freya-TR-Eval üzerinde UTMOS yaklaşık 3,30'dur: ElevenLabs v4 (3,30) ile aynı seviyede, Gemini 3,8 (3,52 - 3,61) ve Trendyol-TTS'nin (3,83) altındadır.
252
+ - **WER, Whisper tarafından ölçülmüştür,** bu nedenle sayılan hataların bazıları tanıma sistemine aittir.
253
 
254
+ ## Sorumlu kullanım
 
 
 
255
 
256
+ EMA Lightning sentetik ses üretir ve bunu duyan kişiler bunun farkında olmalıdır. Dinleyicilere yapay zeka tarafından üretilmiş bir ses duyduklarını bildirin (örneğin bir aramanın başında "Bu görüşmede yapay zekâ ile üretilmiş bir ses kullanılmaktadır.") ve yayınladığınız sesi aynı şekilde etiketleyin ("Bu ses yapay zekâ ile üretilmiştir."); AB Yapay Zeka Yasası dahil olmak üzere birçok yerdeki yasalar bu açıklamayı zorunlu kılar. Gerçek bir kişinin sesi olarak sunmayın, dolandırıcılık veya taklit için kullanmayın veya gerçek bir kişinin söylemediği şeyleri söyletmeyin. Sayılar, tarihler ve kısaltmalar otomatik metin normalizasyonu ile okunur; bu, alışılmadık girdileri yanlış okuyabilir. Bu nedenle bankacılık, sağlık, hukuk veya acil durum mesajları için metni ve sesi bir insanın kontrol etmesini sağlayın.
 
 
257
 
258
+ ## Yasal Uyarı
 
 
259
 
260
+ EMA Lightning, Apache License 2.0 kapsamında, herhangi bir garanti olmaksızın "olduğu gibi" sağlanır. Yazarlar, kullanımından veya kullanımından kaynaklanan herhangi bir zarardan sorumlu değildir. Dağıtan kişi, kullanıldığı yerde geçerli olan açıklama ve onay kuralları dahil olmak üzere, yasalara uygun kullanımdan sorumludur. Bu bölüm yasal tavsiye değildir.
261
 
262
+ ## Lisans
263
 
264
+ Ağırlıklar ve kod için Apache 2.0. Ticari kullanım dahildir.
265
 
266
+ ## Teşekkür
267
 
268
+ EMA Lightning'in arkasındaki Türkçe metin normalleştiricisi [normalizer-tr](https://github.com/erdemtuna/normalizer-tr)'yi inşa eden **[Erdem Tuna](https://github.com/erdemtuna)**'ya özel teşekkürler. Yüksek sesle okunan her sayı, tarih, miktar ve sembol onun çalışmasından geçer.
269
 
270
+ Freya-TR-Eval kıyaslaması için **Freya**'ya ve † ile işaretlenmiş yayınlanmış temel modeller için **Anka TTS yazarlarına** teşekkürler.
271
+
272
+ ## Atıf
273
 
274
  ```bibtex
275
  @misc{aslan2026emalightning,
 
283
  [github]: https://github.com/canberk7/ema-lightning
284
 
285
  ---
286
+
287
  *Bu dosya veripazari.com.tr topluluğu tarafından Hugging Face altyapısında barındırılmaktadır. Orijinal emeğe saygı gereği lisans, metadata ve kaynak referansları korunmuştur.*