File size: 10,773 Bytes
d4101a0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | # Lua Nova V1
A compact, high-naturalness **24 kHz Brazilian Portuguese (PT-BR)** neural Text-to-Speech system combining an **85-symbol eSpeak-NG phonetic front end**, **ProsodyFlow** (generative DurationFlow & ProsodyFlow), an **Optimal-Transport Conditional Flow Matching (OT-CFM)** acoustic decoder operating in universal **Slaney 100-band log-mel space**, **Sway Sampling**, and a gently adapted **MIT BigVGAN-base** vocoder.
This release packages the **`CFM v5 (Option A + Weight Soup) + BigVGAN-base FT (Option B)`** architecture (`~35.8M` total inference parameters, `~137 MB` FP32 / `~68 MB` FP16) cleanly for public reproduction, fine-tuning, **2-step Euler distillation (`v1.1.0`)**, **split ONNX Runtime CPU inference**, and **overlap-crossfaded chunked streaming** — with **zero binary checkpoints committed to Git** (weights belong on Hugging Face).
---
## Highlights & Benchmarks (`tts-eval` v1.0.0)
Evaluated on a frozen multi-metric suite across `heldout_ref` (30 paired studio utterances) and `stress_ptbr` (36 challenging PT-BR sentences covering questions, exclamations, long clauses, numbers, homographs, and foreign/tech terms):
| System | Held-out (30) Pass | Held-out Comp ↑ | Nat ↑ | Anti-Rob ↑ | SCOREQ ↑ | UTMOS22 ↑ | Stress (36) Comp ↑ | Stress Anti-Rob ↑ | Stress WER ↓ | Stress CER Phon ↓ |
|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
| Real Studio Recording (`24 kHz`) | 30/30 | 88.1 | 95.1 | 77.8 | 3.77 | 3.61 | — | — | — | — |
| `BigVGAN v1 Large` Copy-GT *(stock oracle)* | 30/30 | 82.7 | 88.4 | 63.8 | 3.59 | 3.42 | — | — | — | — |
| `BigVGAN-base` Copy-GT *(stock oracle)* | 30/30 | 78.8 | 84.1 | 53.9 | 3.51 | 3.28 | — | — | — | — |
| `CFM v5 + BigVGAN-base` *(stock)* | 30/30 | 81.9 | 88.1 | 54.4 | 3.60 | 3.43 | 79.9 | 50.9 | 1.84% | 0.31% |
| `CFM v5 Option A (Soup50+Sway)` + `BigVGAN-base` | 30/30 | 81.3 | 86.7 | 52.9 | 3.60 | 3.44 | 80.7 | 54.3 | 1.85% | 0.33% |
| `CFM v5 Option A+B + BigVGAN-base FT` (`8p` Sway Midpoint) | **30/30** | **83.9** | **91.6** | 59.1 | **3.74** | 3.49 | **85.0** | **65.4** | 1.85% | 0.28% |
| **`CFM v5 Fast (2p Euler) + BigVGAN-base FT` (`v1.1.0`)** | **30/30** | **85.2** | 91.0 | **64.4** | **3.74** | **3.51** | **84.8** | 64.3 | **1.67%** | **0.23%** |
| `CFM v5 Option A+B + BigVGAN v1 Large FT` (`8p` Sway Midpoint) | **30/30** | **83.5** | 90.9 | 58.5 | 3.72 | 3.48 | 84.1 | 61.9 | 1.68% | 0.33% |
### CPU, GPU & Streaming Latency (`v1.0.0` vs. `v1.1.0`)
Measured across 5 representative PT-BR sentences (`24.5 s` audio total, warmup excluded; 6 physical / 12 logical CPU cores + RTX 4070 GPU):
| Mode | Avg Latency / Sentence | Speed (RT ↑) | Streaming TTFA (avg) | Model Size |
|---|---:|---:|---:|---:|
| PyTorch CPU — `v1.0.0` Baseline (`8p` Sway Midpoint) | 3,213 ms | `1.53×` | 3,213 ms | 188.8 MB (`135.1 + 53.7`) |
| **PyTorch CPU — `v1.1.0` Distilled (`2p` Euler)** | **2,337 ms** | **`2.10×`** | 2,337 ms | **136.9 MB** (`83.2 + 53.7`) |
| **PyTorch CPU — `v1.1.0` Streaming (`2p` Euler, `chunk=24`)** | 2,610 ms | `1.88×` | **`465.3 ms`** | **136.9 MB** (`83.2 + 53.7`) |
| ONNX CPU (`6` threads) — `8p` Sway Midpoint | 4,223 ms | `1.16×` | 4,223 ms | 145.0 MB (`90.3 + 54.7`) |
| ONNX CPU (`6` threads) — `v1.1.0` Distilled (`2p` Euler) | 3,469 ms | `1.41×` | 3,469 ms | **141.0 MB** (`86.3 + 54.7`) |
| **ONNX CPU (`6` threads) — Streaming (`2p` Euler, `chunk=24`)** | 5,166 ms | `0.95×` | **`554.9 ms`** | **141.0 MB** (`86.3 + 54.7`) |
| PyTorch GPU — `8p` -> **`2p` Euler** | 535 ms -> **437 ms** | `9.10×` -> **`11.13×`** | — | `192 MB` loaded / `319 MB` peak VRAM |
See [CPU & Latency Optimization Guide](./docs/OPTIMIZATION.md) for distillation training, split ONNX export, and chunked streaming details.
---
## Audio Comparison Samples
Reference 24 kHz studio recordings compared side-by-side against unconstrained `CFM v5 Option A+B + BigVGAN-base FT` synthesis from raw text:
| Sample | Text | Reference (`24 kHz`) | Synthesized (`Lua Nova V1`) |
|---|---|---|---|
| `01` | *"Se crivarmos a proposta da permissionária, eu premo por essa decisão."* | [sample_01_ref.wav](./assets/samples/sample_01_ref.wav) | [sample_01_gen.wav](./assets/samples/sample_01_gen.wav) |
| `02` | *"Precisamos frisarmos que eles pensassem em visitar a praia de Arribá."* | [sample_02_ref.wav](./assets/samples/sample_02_ref.wav) | [sample_02_gen.wav](./assets/samples/sample_02_gen.wav) |
| `03` | *"Você sustentas a ideia de que o sínodo aguentou a pressão?"* | [sample_03_ref.wav](./assets/samples/sample_03_ref.wav) | [sample_03_gen.wav](./assets/samples/sample_03_gen.wav) |
---
## Installation
### Prerequisites
1. **Python 3.11 or 3.12** and [`uv`](https://docs.astral.sh/uv/).
2. **`espeak-ng`** available on `PATH` (used at runtime and alignment for PT-BR G2P, invoked only as an external subprocess):
- **Linux (Debian/Ubuntu):** `sudo apt-get install espeak-ng`
- **macOS:** `brew install espeak-ng`
- **Windows:** install [eSpeak NG](https://github.com/espeak-ng/espeak-ng/releases) and ensure `espeak-ng.exe` is in `PATH`.
### Install with `uv`
```bash
# Inference only
uv sync
# Inference + full training & forced alignment stack
uv sync --extra train
# Optional: ONNX tools
uv sync --extra onnx
```
> **Note on NVIDIA CUDA PyTorch wheels:** If you are training on GPU and `uv sync` resolves CPU-only wheels on your platform, install matching `torch`/`torchaudio` CUDA wheels via `--extra-index-url https://download.pytorch.org/whl/cu126` (or your CUDA version) after syncing dependencies.
---
## Model Weights (Hugging Face)
Binary model weights (`*.pt`, `*.onnx`, `*.safetensors`) are **excluded from this Git repository** and distributed via Hugging Face. Place downloaded weights in a local `checkpoints/` folder (git-ignored):
- **CFM checkpoints:**
- `cfm_v5_fast2.pt` *(recommended, `v1.1.0`)* — 2-step Euler distilled from `cfm_v5_soup50.pt` (`2.10× RT` CPU / `465 ms` TTFA)
- `cfm_v5_soup50.pt` *(baseline, `v1.0.0`)* — 8-step Sway Midpoint teacher (50/50 weight soup of `CFM v5` + `Option A` E2E)
- **Vocoder checkpoint:** `bigvgan_base_optB_2k.pt` (fine-tuned MIT `nvidia/bigvgan_base_24khz_100band`) or pass any compatible HF ID directly (`nvidia/bigvgan_base_24khz_100band` or `nvidia/bigvgan_24khz_100band`)
You can also strip legacy `Vocos` buffers from a training checkpoint before uploading to Hugging Face:
```python
from lua_nova_v1.utils import strip_legacy_vocoder
strip_legacy_vocoder("runs/cfm_v5_e2e/inference_v5_soup50.pt", "release_weights/cfm_v5_soup50_fp16.pt", fp16=True)
```
---
## Quickstart
### CLI Inference
```bash
uv run lua-nova-speak \
--text "Olá! Dia 22/03 às 14h30 custou R$ 45,90; você prefere testar o modelo agora?" \
--out output.wav \
--cfm checkpoints/cfm_v5_soup50.pt \
--vocoder checkpoints/bigvgan_base_optB_2k.pt \
--device cpu
```
### Python API (PyTorch Streaming & 2-Step Fast Mode)
```python
import numpy as np
from lua_nova_v1 import Synthesizer
synth = Synthesizer.from_checkpoints(
cfm_path="checkpoints/cfm_v5_fast2.pt",
vocoder_path_or_id="checkpoints/bigvgan_base_optB_2k.pt",
device="cpu",
)
# Full utterance (2 Euler steps)
wav = synth.speak(
"Você tem certeza de que o modelo já fala perguntas com naturalidade?",
n_steps=2,
solver="euler",
sway_coef=0.0,
temperature=0.35,
)
synth.save_wav("output.wav", wav)
# Low-latency chunked streaming (TTFA ~465 ms on CPU)
chunks = list(
synth.speak_stream(
"Olá! Este áudio está sendo gerado em partes com transição suave.",
n_steps=2,
solver="euler",
sway_coef=0.0,
chunk_frames=24,
)
)
synth.save_wav("output_stream.wav", np.concatenate(chunks))
```
### ONNX Runtime CPU (PyTorch-free Deployment)
```bash
# Export split opset-17 ONNX graphs
uv run lua-nova-export-onnx \
--cfm checkpoints/cfm_v5_fast2.pt \
--vocoder checkpoints/bigvgan_base_optB_2k.pt \
--out-dir checkpoints/onnx \
--steps 2 --solver euler --sway-coef 0.0 --verify
# Synthesize directly with ONNX Runtime CPU + streaming
uv run lua-nova-speak \
--onnx-cfm checkpoints/onnx/cfm_v5.onnx \
--onnx-vocoder checkpoints/onnx/bigvgan_base_ft.onnx \
--text "Síntese em CPU via ONNX Runtime com streaming por chunks." \
--out output_onnx.wav --stream --chunk-frames 24
```
```python
from lua_nova_v1 import OnnxSynthesizer
ox = OnnxSynthesizer("checkpoints/onnx/cfm_v5.onnx", "checkpoints/onnx/bigvgan_base_ft.onnx")
wav = ox.speak("Oi! Tudo bem com você?")
ox.save_wav("onnx.wav", wav)
```
---
## Documentation & Guides
- [Architecture & Key Design Choices](./docs/ARCHITECTURE.md)
- [CPU & Latency Optimization Guide (Distillation, ONNX & Streaming)](./docs/OPTIMIZATION.md)
- [Fine-Tuning on a New Voice](./docs/FINE_TUNING.md)
- [Training From Scratch Guide](./docs/TRAINING_FROM_SCRATCH.md)
- [Third-Party Notices & Licenses](./THIRD_PARTY_NOTICES.md)
---
## Repository Layout
```text
lua-nova-v1/
├── assets/samples/ # Paired 24 kHz studio reference & generated audio examples
├── docs/ # Architecture, optimization, training, and fine-tuning guides
├── src/lua_nova_v1/
│ ├── config.py # ModelConfig & CFMConfig dataclasses
│ ├── text/ # PT-BR normalizer (numbers, currency, dates) & eSpeak G2P
│ ├── models/ # Front end, ProsodyFlow, OT-CFM v5 + Sway Sampling, BigVGAN wrapper
│ ├── data/ # Acoustic prep, wav2vec2 CTC forced aligner, Dataset & BucketSampler
│ ├── training/ # Stage 1, ProsodyFlow, CFM v5, Option A (E2E), Option B (Vocoder FT), Distill
│ ├── export/ # Split opset-17 ONNX exporters for CFM v5 and BigVGAN
│ ├── inference/ # PyTorch Synthesizer, OnnxSynthesizer, overlap-crossfade streaming, CLI
│ └── utils/ # RMS/fade/PCM16 post-processing, weight souping, checkpoint stripping
├── tests/ # Unit & end-to-end synthetic verification tests
└── third_party/bigvgan/ # MIT-licensed NVIDIA BigVGAN generator, losses & discriminators
```
---
## License
Code authored in this repository is released under the **Apache License 2.0** ([LICENSE](./LICENSE)). Components under `third_party/bigvgan/` are MIT-licensed by NVIDIA ([third_party/bigvgan/LICENSE](./third_party/bigvgan/LICENSE)). See [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md).
|