parallel wavegan developer on retainer: mel spectrogram not normalized with stats.h5 before vocoder — LJSpeech mean/scale not applied to custom TTS output — GAN generates broadband buzzing on all voiced speech — MOS 1.3 not 4.1 — $200,000 — 6 months — parallel wavegan developer on monthly retainer
parallel_wavegan 0.5.4 • torch 1.13.1 • Python 3.9; LJSpeech pretrained checkpoint; stats.h5 mean = −4.65, scale = 2.84; inference script missing (mel − mean) / scale; unnormalized log-mel values (−72 to −0.4) fed to vocoder trained on normalized inputs; GAN broadband buzz MOS 1.3 vs 4.1; fix: mel_norm = (mel − mean) / scale before model.inference() • Southfield ParallelWave TTS Ltd. (4-person audiobook platform; 6 months; 1.5h)
Southfield ParallelWave TTS Ltd. is a 4-person startup building an AI audiobook narration platform. Authors upload manuscript text and choose a licensed voice actor timbre; the platform generates narration WAV files at MOS ≥ 4.0 quality. The developer used a FastSpeech2 acoustic model (trained on a 20-hour audiobook corpus) paired with a Parallel WaveGAN vocoder using the LJSpeech pretrained checkpoint from kan-bayashi’s parallel_wavegan library. The developer built a custom inference script based on the library’s README quick-start example. The README shows the basic model loading and inference call but omits the normalization step — a step that is in the official inference.py but invisible in abbreviated examples:
# synthesize.py — TTS vocoder inference (parallel_wavegan 0.5.4, torch 1.13.1)
import torch, numpy as np, soundfile as sf
from parallel_wavegan.utils import load_model
# Load pretrained Parallel WaveGAN generator
checkpoint = torch.load(
"checkpoints/ljspeech_parallel_wavegan.v1/checkpoint-400000steps.pkl",
map_location="cpu"
)
model = load_model(checkpoint)
model.remove_weight_norm()
model.eval().to("cuda")
# stats.h5 is in the checkpoint directory
# stats.h5 contains: /mean (shape: 80,) /scale (shape: 80,)
# NOT LOADED — normalization step omitted from README quick-start example
def vocoder_infer(mel: np.ndarray, out_path: str) -> None:
# mel: log mel spectrogram from FastSpeech2, shape (T, 80)
# unnormalized log-mel values range: -72.3 to -0.4, mean -13.6
mel_tensor = torch.FloatTensor(mel).unsqueeze(0).transpose(1, 2)
# shape: (1, 80, T) — vocoder expects normalized inputs; receives unnormalized
with torch.no_grad():
wav = model.inference(mel_tensor.to("cuda")) # ← GAN receives out-of-distribution input
sf.write(out_path, wav.view(-1).cpu().numpy(), samplerate=22050)
# MOS on 20-sentence test set (5 voice actors, 100 sentences each):
# Voice 1 (male narrator): MOS 1.2 — continuous buzzing on all vowels
# Voice 2 (female narrator): MOS 1.4 — metallic ringing on /s/ /sh/ sounds
# Voice 3 (child voice): MOS 1.3 — broadband noise masks all phonemes
# Average MOS: 1.3
# Official TTS inference.py on same mel input: MOS 4.1 ← gap identified in retainer
Parallel WaveGAN is a GAN-based neural vocoder trained to map mel spectrogram frames to waveform samples. The generator and discriminator are both trained on a fixed distribution of mel spectrogram values computed from the training dataset. The normalization step — (mel − mean) / scale using per-bin statistics from stats.h5 — maps the training data to approximately zero mean and unit variance before the GAN processes it. This ensures the GAN’s internal activations stay in the range the network was designed for during training.
When inference code skips normalization, the generator receives log-mel values in their raw scale (−72 to −0.4 for the custom audiobook data, mean −13.6). The LJSpeech training distribution, normalized to mean 0 and std 1, corresponds to a raw scale of approximately −11 to −1.5 centered at −4.65. The unnormalized custom data mean (−13.6) is 3.2 standard deviations below the training distribution mean. Every single mel frame the vocoder receives is outside the range it was trained on.
What out-of-distribution mel values do to a GAN vocoder
# Mel spectrogram statistics comparison:
#
# LJSpeech training data (unnormalized log-mel, 80 bins):
# Mean (across all frames, all bins): -4.65
# Scale (std across all frames): 2.84
# Range (p1 to p99): -11.3 to -0.8
#
# After normalization with LJSpeech stats:
# LJSpeech training data: mean 0.0, std 1.0, range -2.3 to 1.6
# LJSpeech test data: mean -0.1, std 1.0, range -2.4 to 1.7 ← in distribution
# Custom audiobook data: mean -3.2, std 2.1, range -6.3 to 1.5 ← shifted but closer
#
# Without normalization (what the custom inference script does):
# LJSpeech test data fed raw: mean -4.65 — still problematic but resembles training range
# Custom audiobook data raw: mean -13.6 — 3.2 sigma below training mean
#
# GAN generator internal behavior with unnormalized input:
# First conv layer activation: saturates at negative extremes
# Upsampling blocks: interpret large negative values as "silence"
# Discriminator training: never saw inputs at this range
# Generator output: attempts to produce "silence-like" waveform → aliasing artifacts
# Aliasing manifests as: broadband buzz at 6–8 kHz (most prominent on sustained vowels)
# Additional artifact: metallic harmonic ringing at 1–3 kHz on fricatives
#
# MOS breakdown by artifact type:
# Sustained vowels (a, e, i, o, u): MOS 1.1 — continuous 7 kHz buzz audible
# Fricatives (s, sh, f, v): MOS 1.4 — metallic ringing added to real fricative
# Plosives (p, b, t, d, k, g): MOS 1.6 — artifact briefer, less severe
# Silence between words: MOS 2.1 — no phoneme content, less artifact
# Overall: MOS 1.3
#
# Same inference code with normalization applied:
# Sustained vowels: MOS 4.3
# Fricatives: MOS 4.0
# Plosives: MOS 4.2
# Overall: MOS 4.1
Why six months of retraining could not fix the normalization gap
The team received user complaints about “robotic buzzing” and “completely unusable voice quality” and attributed the problem to the LJSpeech pretrained checkpoint not matching their audiobook voice timbre. They reasoned that training a custom Parallel WaveGAN on their own data would fix the quality. Over six months they ran:
# Month 1: Retrain Parallel WaveGAN from scratch on 20h custom audiobook corpus
# Training data loader: copies kan-bayashi's training code, includes normalization ✓
# Training: runs for 400k steps on custom data, computes new stats.h5 from custom data
# New stats.h5: mean=-5.21 (custom audiobook recording level), scale=3.07
# Inference script: unchanged — still missing (mel - mean) / scale
# Result: MOS 1.4 (custom-trained model still receives unnormalized mels in inference)
# Conclusion: "custom training helped a little, need more data"
#
# Month 2: Data augmentation — add +60h of narration recordings
# 80h total training corpus; retrain PWG 400k steps
# Inference script: still missing normalization
# Result: MOS 1.4 (unchanged — normalization gap persists regardless of data size)
#
# Month 3: Switch to HiFi-GAN V2 pretrained checkpoint
# HiFi-GAN also uses stats.h5 normalization (generator expects mean=0, std=1)
# Developer's HiFi-GAN inference script: also missing normalization (same omission)
# Result: MOS 1.5 (slightly different artifact profile; buzz replaced by metallic ring)
# Conclusion: "HiFi-GAN marginally better but still unacceptable"
#
# Month 4: Try WaveGlow (NVIDIA, normalizing flow vocoder)
# WaveGlow uses mel normalization differently (sigma parameter in flow)
# Without normalization: flow layer inversion fails; output is clipped white noise
# Result: MOS 1.3 (worst so far)
# Conclusion: "WaveGlow incompatible with our acoustic model output"
#
# Month 5: Retrain both FastSpeech2 and Parallel WaveGAN jointly on 80h corpus
# Full 2-week training pipeline; retrained acoustic model outputs similar mel range
# Inference script: still missing normalization for both models
# Result: MOS 1.4 (ceiling: normalization gap cannot be closed by retraining)
# Monthly audiobook generation revenue: near zero (all orders refunded)
#
# Month 6: Request retainer engagement
# MOS still 1.3–1.4 on all tested configurations
#
# Retainer triage (1.5h):
# Step 1 (0.5h): Run official inference.py on same FastSpeech2 mel output → MOS 4.1
# Run developer's synthesize.py on same FastSpeech2 mel output → MOS 1.3
# Diff the two scripts → missing 3 lines found
# Step 2 (0.5h): Add stats.h5 load and normalization to synthesize.py
# Run fixed script on 20 test sentences → MOS 1.3 → 4.0
# Step 3 (0.5h): Verify that the custom-retrained checkpoint's stats.h5 also works
# Custom stats.h5 (mean=-5.21, scale=3.07) gives MOS 4.0
# LJSpeech stats.h5 (mean=-4.65, scale=2.84) gives MOS 4.1
# Root cause: 2 missing lines in inference script
The retainer consultant found the missing normalization in 1.5 hours: 0.5h to run the official inference.py and the developer’s synthesize.py on identical FastSpeech2 mel spectrogram output and compare the MOS scores (4.1 vs 1.3), then diff the two scripts to find the three missing lines (mean = read_hdf5(stats_file, "/mean"), scale = read_hdf5(stats_file, "/scale"), mel_norm = (mel - mean) / scale); 0.5h to add the normalization to synthesize.py, run on 20 test sentences, and confirm MOS improved from 1.3 to 4.0; 0.5h to verify the fix works with both the LJSpeech pretrained checkpoint and the custom-retrained checkpoint, confirm that the custom stats.h5 from the month-1 retraining was also valid (and that retraining was wasted effort while the inference script was broken), and add an assertion to catch future normalization regressions. Hours logged to HourTab with per-session breakdown.
# Fixed synthesize.py
import torch, numpy as np, soundfile as sf
from parallel_wavegan.utils import load_model, read_hdf5
checkpoint = torch.load(
"checkpoints/ljspeech_parallel_wavegan.v1/checkpoint-400000steps.pkl",
map_location="cpu"
)
model = load_model(checkpoint)
model.remove_weight_norm()
model.eval().to("cuda")
# Load normalization statistics from checkpoint directory — REQUIRED for clean output
stats_file = "checkpoints/ljspeech_parallel_wavegan.v1/stats.h5"
mean = read_hdf5(stats_file, "/mean") # shape: (num_mels,), e.g. (80,) for 80-bin mel
scale = read_hdf5(stats_file, "/scale") # shape: (num_mels,)
# Defensive check: normalization should bring mel to approximately mean=0, std=1
def vocoder_infer(mel: np.ndarray, out_path: str) -> None:
mel_norm = (mel - mean) / scale # ← normalize BEFORE passing to generator
# Verify normalization is working
assert abs(mel_norm.mean()) < 0.5, (
f"mel_norm.mean()={mel_norm.mean():.2f}; check stats.h5 path and that "
"stats.h5 matches the checkpoint training run"
)
assert 0.5 < mel_norm.std() < 2.0, (
f"mel_norm.std()={mel_norm.std():.2f}; normalization may be incorrect"
)
mel_tensor = torch.FloatTensor(mel_norm).unsqueeze(0).transpose(1, 2).to("cuda")
with torch.no_grad():
wav = model.inference(mel_tensor)
sf.write(out_path, wav.view(-1).cpu().numpy(), samplerate=22050)
# After fix (100 test sentences, 5 voice actors):
# Voice 1 (male narrator): MOS 4.2 (was 1.2)
# Voice 2 (female narrator): MOS 4.0 (was 1.4)
# Voice 3 (child voice): MOS 4.1 (was 1.3)
# Overall MOS: 4.1 (was 1.3)
# Retraining cost: unnecessary — LJSpeech pretrained + correct normalization = MOS 4.1
# Custom retrained checkpoint: also works with its own stats.h5
Related retainer posts
- hifi-gan developer on retainer — HiFi-GAN V2 vocoder;
stats.h5normalization applied with wrong checkpoint stats; mel-bin mean shift 0.8σ; MOS 2.6 not 4.3; fix: load stats.h5 matching training run; 2.0h - fastspeech2 developer on retainer — ESPnet2 FastSpeech2; mel spectrogram output range mismatch between training and inference normalizer; duration predictor off by 2×; fix: consistent mel stats across acoustic model and vocoder; 2.0h
- waveglow developer on retainer — NVIDIA WaveGlow;
sigmaparameter set to default 0.666 for training but 0.9 for inference; generated audio 36% noisier than training; fix:sigma=0.666at inference matching training; 1.5h
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →