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 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- text-to-speech
|
| 5 |
+
- speech-synthesis
|
| 6 |
+
- autoencoder
|
| 7 |
+
- flow-matching
|
| 8 |
+
- audio
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# BlueCodec β Speech Autoencoder
|
| 12 |
+
|
| 13 |
+
This repository contains the pretrained **Speech Autoencoder (AE)** from the Light-BlueTTS system β Stage 1 of a three-stage TTS pipeline.
|
| 14 |
+
|
| 15 |
+
The AE encodes 44.1 kHz audio into a 24-dim continuous latent space at ~86 Hz, and decodes back to waveform via a causal dilated decoder.
|
| 16 |
+
|
| 17 |
+
**Total inference model size:** ~71M parameters (AE decoder ~25M, TTL ~45M, DP ~0.5M)
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## Checkpoint
|
| 22 |
+
|
| 23 |
+
| File | Contents |
|
| 24 |
+
|---|---|
|
| 25 |
+
| `ae_latest.safetensors` | Encoder + Decoder weights (202 tensors, ~204 MB) |
|
| 26 |
+
|
| 27 |
+
Keys are prefixed with `encoder.*` and `decoder.*`.
|
| 28 |
+
|
| 29 |
+
---
|
| 30 |
+
|
| 31 |
+
## Architecture
|
| 32 |
+
|
| 33 |
+
Encodes via a concatenated log-linear (1025-ch) + log-mel (228-ch) spectrogram (FFT 2048, hop 512) into a 24-dim latent at ~86 Hz.
|
| 34 |
+
|
| 35 |
+
| Component | Details |
|
| 36 |
+
|---|---|
|
| 37 |
+
| Input | 1253-channel spectrogram (1025 log-linear + 228 log-mel) |
|
| 38 |
+
| Encoder (~25.6M) | Conv1d stem (1253β512) + 10 ConvNeXt blocks (intermediate 2048) + proj (512β24) |
|
| 39 |
+
| Decoder (~25.3M) | CausalConv1d stem (24β512) + 10 causal dilated ConvNeXt blocks + VocoderHead |
|
| 40 |
+
| Decoder dilations | `[1, 2, 4, 1, 2, 4, 1, 1, 1, 1]` |
|
| 41 |
+
| Discriminators (train only) | MPD (periods 2,3,5,7,11) + MRD (FFTs 512/1024/2048) |
|
| 42 |
+
|
| 43 |
+
**Generator loss (training):**
|
| 44 |
+
```
|
| 45 |
+
L_G = 45 * L_recon + 1 * L_adv + 0.1 * L_fm
|
| 46 |
+
```
|
| 47 |
+
Reconstruction uses multi-resolution mel L1 on 3 scales: (FFT 1024, 64 mels), (FFT 2048, 128 mels), (FFT 4096, 128 mels).
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
## Full Pipeline β Light-BlueTTS
|
| 52 |
+
|
| 53 |
+
Training is split into three independent stages run in order:
|
| 54 |
+
|
| 55 |
+
1. **Speech Autoencoder** β *this repo* β encodes audio into a 24-dim continuous latent space
|
| 56 |
+
2. **Text-to-Latent (TTL)** β flow-matching model that maps text + reference speech to latents
|
| 57 |
+
3. **Duration Predictor (DP)** β utterance-level duration estimator
|
| 58 |
+
|
| 59 |
+
### Text-to-Latent Module
|
| 60 |
+
|
| 61 |
+
Operates on *compressed* latents: the 24-dim latent is reshaped to 144-dim at ~14 Hz (compression factor K_c = 6).
|
| 62 |
+
|
| 63 |
+
| Component | Details |
|
| 64 |
+
|---|---|
|
| 65 |
+
| Reference Encoder (~4.8M) | Conv1d (144β256) + 6 ConvNeXt blocks (k=5) + 2 cross-attn layers β 50 style tokens |
|
| 66 |
+
| Text Encoder (~6.9M) | Char embedding (256-dim) + 6 ConvNeXt blocks + 4 self-attn blocks (RoPE) + 2 style cross-attn layers |
|
| 67 |
+
| Vector Field Estimator (~33M) | proj_in (144β512) + 4Γ superblock + 4 final ConvNeXt blocks + proj_out (512β144) |
|
| 68 |
+
| VF superblock | 4Γ dilated ConvNeXt (d=1,2,4,8) + time injection + 2Γ ConvNeXt + text cross-attn + style cross-attn |
|
| 69 |
+
|
| 70 |
+
**Flow-matching objective (L1, masked):**
|
| 71 |
+
```
|
| 72 |
+
L_TTL = E [ || m Β· (v(z_t, z_ref, c, t) - (zβ - (1 - Ο_min)Β·zβ)) ||β ]
|
| 73 |
+
```
|
| 74 |
+
Ο_min = 1e-8, p_uncond = 0.05. Inference: Euler method, NFE=32, CFG=3.
|
| 75 |
+
|
| 76 |
+
### Duration Predictor (~0.5M)
|
| 77 |
+
|
| 78 |
+
Utterance-level (not phoneme-level).
|
| 79 |
+
|
| 80 |
+
| Component | Details |
|
| 81 |
+
|---|---|
|
| 82 |
+
| DP Reference Encoder | Linear (144β64) + 4 ConvNeXt blocks + 2 cross-attn β 64-dim embedding |
|
| 83 |
+
| DP Text Encoder | Char embedding (64-dim) + 6 ConvNeXt blocks + 2 self-attn + utterance token β 64-dim |
|
| 84 |
+
| Estimator | Linear(192β128) + PReLU + Linear(128β1) β scalar log-duration |
|
| 85 |
+
|
| 86 |
+
---
|
| 87 |
+
|
| 88 |
+
## Training the Autoencoder
|
| 89 |
+
|
| 90 |
+
Multi-GPU training via PyTorch DDP on 4Γ GPUs.
|
| 91 |
+
|
| 92 |
+
```bash
|
| 93 |
+
torchrun --nproc_per_node=4 src/train_autoencoder.py \
|
| 94 |
+
--arch_config configs/tts.json
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
**Key hyperparameters:**
|
| 98 |
+
|
| 99 |
+
| Parameter | Value |
|
| 100 |
+
|---|---|
|
| 101 |
+
| Optimizer | AdamW (Ξ²β=0.8, Ξ²β=0.99, wd=0.01) |
|
| 102 |
+
| Learning rate | 2e-4 with cosine annealing to 1e-6 |
|
| 103 |
+
| Batch size | 128 |
|
| 104 |
+
| Crop length | 0.19 s (~8,379 samples at 44.1 kHz) |
|
| 105 |
+
| Total iterations | 1,500,000 |
|
| 106 |
+
| Hardware (paper) | 2Γ RTX 3090 |
|
| 107 |
+
|
| 108 |
+
Resume from checkpoint:
|
| 109 |
+
```bash
|
| 110 |
+
torchrun --nproc_per_node=4 src/train_autoencoder.py \
|
| 111 |
+
--resume checkpoints/ae/ae_latest.pt
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
Training dataset: ~5.9M files / ~10,000 hours of audio.
|
| 115 |
+
|
| 116 |
+
---
|
| 117 |
+
|
| 118 |
+
## Reducing Model Size
|
| 119 |
+
|
| 120 |
+
All dimensions are controlled by `configs/tts.json`. Key levers for the AE:
|
| 121 |
+
|
| 122 |
+
| Change | Param reduction |
|
| 123 |
+
|---|---|
|
| 124 |
+
| `encoder.idim`: 1253 β 228 (mel-only input) | β3.7M |
|
| 125 |
+
| `encoder.hdim`: 512 β 256 | β10M |
|
| 126 |
+
| `encoder.intermediate_dim`: 2048 β 1024 | β10.5M |
|
| 127 |
+
| Reduce `encoder.num_layers` / `decoder.num_layers` 10 β 6 | β8.4M each |
|
| 128 |
+
|
| 129 |
+
> Reducing `idim` to 228 also requires updating `LinearMelSpectrogram` to output mel-only (set `n_mels=228` and remove log-linear concatenation in `models/utils.py`).
|
| 130 |
+
|
| 131 |
+
---
|
| 132 |
+
|
| 133 |
+
## Repository Structure
|
| 134 |
+
|
| 135 |
+
```
|
| 136 |
+
training/
|
| 137 |
+
βββ src/
|
| 138 |
+
β βββ train_autoencoder.py # Stage 1: AE training (multi-GPU DDP)
|
| 139 |
+
β βββ train_text_to_latent.py # Stage 2: TTL flow-matching training
|
| 140 |
+
β βββ train_duration_predictor.py # Stage 3: Duration predictor training
|
| 141 |
+
βββ models/
|
| 142 |
+
β βββ autoencoder/
|
| 143 |
+
β β βββ latent_encoder.py # LatentEncoder (mel β 24-dim latent)
|
| 144 |
+
β β βββ latent_decoder.py # LatentDecoder1D (latent β waveform)
|
| 145 |
+
οΏ½οΏ½οΏ½ β βββ discriminators.py # MPD + MRD for GAN training
|
| 146 |
+
β β βββ modules.py # Shared: ConvNeXtBlock, CausalConvNeXtBlock, etc.
|
| 147 |
+
β βββ text2latent/
|
| 148 |
+
β βββ text_encoder.py # TextEncoder with ConvNeXt + self-attn + style cross-attn
|
| 149 |
+
β βββ reference_encoder.py # ReferenceEncoder (audio β style tokens)
|
| 150 |
+
β βββ vf_estimator.py # VectorFieldEstimator (flow-matching backbone)
|
| 151 |
+
β βββ duration_predictor.py # TTSDurationModel (full DP model)
|
| 152 |
+
β βββ dp_network.py # DPNetwork (backward-compatible wrapper)
|
| 153 |
+
βββ compute_latent_stats.py # Compute latent mean/std (run before Stage 2/3)
|
| 154 |
+
βββ configs/
|
| 155 |
+
βββ tts.json # Single config file for all stages
|
| 156 |
+
```
|