nemo tts developer on retainer: custom narrator fine-tuned at speaker=128 — inference calls generate_spectrogram(tokens) without speaker kwarg — default speaker=0 (VCTK British male) — similarity 0.29 vs 0.84 — $185,000 — 6 months — nemo tts developer on monthly retainer

nemo_toolkit[tts] 1.17.0 (NVIDIA NeMo) • PyTorch 2.0.1 • Python 3.9; FastPitch + HiFi-GAN; custom narrator Evelyn Cole fine-tuned at speaker=128 in speaker embedding table (cfg.model.speaker=128); inference script calls model.generate_spectrogram(tokens=tokens) without speaker kwarg; NeMo default speaker=None falls back to speaker=0 (VCTK p225, British male); 3,000 audiobook chapters generated in wrong voice; speaker similarity cosine 0.29 vs 0.84; MOS 2.1 vs 4.1; fix: model.generate_spectrogram(tokens=tokens, speaker=128) • Westfield NeMo TTS Ltd. (5-person audiobook production platform; 6 months; 1.5h)

Westfield NeMo TTS Ltd. is a 5-person startup building an automated audiobook production platform. Their product converts text manuscripts into audiobooks using a custom licensed narrator voice (Evelyn Cole, an American female voice talent contracted exclusively for the platform). The team started from NVIDIA’s multi-speaker FastPitch pretrained checkpoint, which includes speaker embeddings for 109 VCTK speakers at indices 0–108. They fine-tuned on 10 hours of Evelyn Cole’s studio recordings by adding a new speaker embedding at index 128 and training it while freezing all other model weights. The fine-tuning configuration correctly set cfg.model.speaker=128. After 30 epochs of fine-tuning, the validation MOS on held-out Evelyn Cole test sentences reached 4.1 — confirming that the model had learned her voice characteristics. The fine-tuning engineer ran a quick listening test on the training machine, heard Evelyn’s voice, and marked the model as production-ready. The inference server was built separately by a different engineer, using the NeMo TTS inference API without referencing the fine-tuning configuration.

# inference_server.py — Westfield NeMo TTS Ltd. production pipeline
# nemo_toolkit[tts] 1.17.0; PyTorch 2.0.1; Python 3.9

import torch
import numpy as np
from nemo.collections.tts.models import FastPitchModel, HifiGanModel

fastpitch = FastPitchModel.restore_from("westfield-evelyn-cole-v3.nemo")
hifigan   = HifiGanModel.restore_from("hifigan-22050hz.nemo")
fastpitch.eval()
hifigan.eval()

# Fine-tuning config had: cfg.model.speaker = 128
# model.speaker_emb.weight[128] = Evelyn Cole's trained voice embedding
# model.speaker_emb.weight[0]   = VCTK p225 (British male, 23y, baseline speaker)

def synthesize_chapter(text: str) -> np.ndarray:
    tokens = fastpitch.parse(text)
    tokens = tokens.to(fastpitch.device)

    with torch.no_grad():
        spec, spec_len, _, _ = fastpitch.generate_spectrogram(
            tokens=tokens
            # Bug: speaker kwarg omitted
            # NeMo default: speaker=None → self.speaker_emb(LongTensor([0]))
            # Uses speaker 0 embedding (VCTK p225) instead of Evelyn Cole (index 128)
        )
        audio = hifigan.convert_spectrogram_to_audio(spec=spec)

    return audio.squeeze().cpu().numpy()

# Results on 3,000 audiobook chapters (15 titles × 200 chapters each):
# Expected: Evelyn Cole's voice (American female, warm, mid-register)
# Actual:   VCTK p225 (British male, formal, high-register)
# Speaker similarity cosine: 0.29  ← expected: 0.84
# MOS (voice identity match): 2.1  ← expected: 4.1
# MOS (naturalness only):     4.0  ← TTS itself works; just wrong voice
# User complaint #1 (after first audiobook delivery): "This is a man's voice"
# User complaint #2: "We contracted Evelyn Cole's voice — this sounds British"
# User complaint #3: "The speech quality is good but it's completely the wrong narrator"

The NeMo FastPitch speaker conditioning system works correctly — the bug is not in the model but in which speaker embedding it accesses at inference. Inside generate_spectrogram(), the speaker argument is passed to self.speaker_emb(torch.LongTensor([speaker])), which performs a lookup in the embedding table and returns a vector that is added to the encoder output at every Transformer layer. When speaker=None is passed (the default when the kwarg is omitted), NeMo falls back to speaker=0. Speaker 0’s embedding was present in the original pretrained checkpoint and was never modified during fine-tuning (only the new row at index 128 was trained). Speaker 0 corresponds to VCTK speaker p225 — a British male speaker whose voice characteristics are encoded in model.speaker_emb.weight[0]. The model generates high-quality, natural-sounding speech in English, with correct prosody and no artifacts. It simply generates it in p225’s British male voice, not in Evelyn Cole’s American female voice. The fine-tuning engineer’s quick listening test on the training machine had confirmed the correct voice because the training evaluation script explicitly passed speaker=128 — a detail not carried over to the production inference server.

How the speaker embedding mismatch produces correct speech in the wrong voice

# NeMo FastPitch speaker embedding architecture
# model: FastPitch multi-speaker; speaker_emb_dim=128
# model.speaker_emb: nn.Embedding(num_speakers=129, embedding_dim=128)
#   indices 0-108: original VCTK speakers from pretrained checkpoint
#   indices 109-127: unused (zero-initialized at fine-tuning setup)
#   index 128: Evelyn Cole — trained for 30 epochs on 10 hours of recordings
#
# speaker_emb.weight[0]   (p225): cosine(weight[0], weight[128]) = 0.12  ← very different
# speaker_emb.weight[128] (Evelyn): trained voice — American female characteristics
#
# Inference call analysis:
#   generate_spectrogram(tokens=tokens)  — no speaker kwarg
#   Inside FastPitchModel.generate_spectrogram():
#     speaker = 0  (default fallback when speaker=None)
#     spk_emb = self.speaker_emb(torch.LongTensor([0]).to(device))
#     spk_emb = spk_emb.unsqueeze(1)  # [1, 1, 128]
#     # spk_emb is VCTK p225's embedding vector
#     # Added to encoder output at every Transformer layer:
#     #   enc_out = enc_out + spk_emb  (broadcasts to [1, T, 128])
#     # FastPitch generates pitch (F0), duration, and energy conditioned on p225
#     # F0 range: p225 male fundamental ≈ 90–180 Hz (tenor range)
#     # Evelyn Cole female fundamental ≈ 190–310 Hz (mezzo-soprano range)
#     # Pitch trajectory, formant positions, and prosody rhythm: p225 characteristics
#
# Fine-tuning evaluation script (correctly used speaker=128):
#   generate_spectrogram(tokens=tokens, speaker=128)
#   spk_emb = self.speaker_emb(torch.LongTensor([128]).to(device))
#   # Evelyn Cole's embedding → correct F0 range, formants, prosody → MOS 4.1
#
# Production inference server (incorrectly omitted speaker kwarg):
#   generate_spectrogram(tokens=tokens)  → speaker=0 (p225)
#   Speaker similarity cosine (Evelyn vs output): 0.29
#   MOS voice identity: 2.1 (listeners correctly identified wrong gender+accent)
#   MOS naturalness: 4.0 (speech quality is high — just p225's voice, not Evelyn's)
#
# The model is not broken; it correctly generates speech for speaker 0 (p225)
# The fine-tuning is not broken; speaker 128 (Evelyn Cole) is correctly trained
# The only failure: inference code never passes speaker=128

Why six months of retraining could not fix a missing keyword argument

The team received complaints from their first audiobook client that the output voice was British and male rather than American and female. They attributed the problem to insufficient fine-tuning data or incorrect training parameters. Each intervention re-ran fine-tuning or changed model architecture while leaving the inference server’s missing speaker argument unchanged. No amount of fine-tuning can change what voice the inference server requests when it always requests speaker=0.

# Month 1: Retrain from scratch with more Evelyn Cole data (15 hours total, was 10)
#   Fine-tuning: cfg.model.speaker=128; trained correctly on more data
#   Validation on training machine: MOS 4.2 (slight improvement from more data)
#   Inference: generate_spectrogram(tokens=tokens)  — speaker=0 still used
#   Similarity: 0.28  MOS: 2.1
#   Reason: more fine-tuning data improved speaker 128 embedding quality marginally;
#   inference still uses speaker 0 (p225); improvement not visible at inference
#   Conclusion: "need even more data — target 20 hours for next iteration"
#
# Month 2: Increase fine-tuning epochs from 30 to 100
#   speaker_emb.weight[128] converges further; validation MOS 4.1 (same)
#   Inference: speaker=0 unchanged
#   Similarity: 0.30  MOS: 2.1
#   Reason: longer training improves embedding at index 128; inference uses index 0
#   Slight similarity improvement (0.29→0.30) is noise, not signal
#   Conclusion: "overfitting concern at 100 epochs; revert to 30"
#
# Month 3: Change learning rate schedule (cosine annealing → linear warmup)
#   Fine-tuning: different LR schedule; same speaker=128 config
#   Inference: speaker=0 unchanged
#   Similarity: 0.29  MOS: 2.1
#   Reason: LR schedule affects how speaker 128 is trained; inference uses speaker 0
#   Conclusion: "LR schedule doesn't matter — deeper problem"
#
# Month 4: Try different speaker embedding initialization
#   Initialize speaker 128 from speaker 64 (a female VCTK speaker) instead of random
#   Fine-tuning: starts from female speaker embedding, trains toward Evelyn Cole
#   Validation MOS 4.2 (slightly better initialization helps convergence)
#   Inference: speaker=0 unchanged (p225, same as always)
#   Similarity: 0.31  MOS: 2.1
#   Reason: better initialization improves speaker 128 embedding; inference uses 0
#   Conclusion: "initialization matters slightly — female seed helps"
#
# Month 5: Reduce speaker embedding dimension from 128 to 64
#   Model architecture change; full retrain required
#   Fine-tuning: speaker=128 in smaller 64-dim embedding space
#   Inference: speaker=0 unchanged
#   Similarity: 0.29  MOS: 2.0
#   Reason: reduced dimension doesn't help; inference still uses speaker 0
#   Conclusion: "embedding dim not the issue — maybe the HiFi-GAN?"
#
# Month 6: Client escalation
#   Audiobook platform client escalates: "15 titles delivered, all in wrong voice"
#   Junior intern assigned to listen to both inference output and fine-tuning evaluation
#   output side by side → "these sound like different people; the eval one sounds right"
#   Inference server code audit requested → retainer engagement
#
# Retainer triage (1.5h):
#   Step 1 (0.5h): Compare fine-tuning eval script with inference server
#                  eval_script.py:    generate_spectrogram(tokens=tokens, speaker=128) ← correct
#                  inference_server:  generate_spectrogram(tokens=tokens)              ← bug
#                  speaker kwarg absent; default falls back to speaker=0
#   Step 2 (0.5h): Confirm speaker 128 embedding is correct
#                  model.speaker_emb.weight[128]: L2 norm 1.14; non-zero; well-trained
#                  model.speaker_emb.weight[0]:   cosine similarity to [128] = 0.12 (very different)
#                  Run inference with speaker=128 on 10 test sentences: similarity 0.84; MOS 4.1
#   Step 3 (0.5h): Fix inference server; audit all other inference endpoints for same issue;
#                  document: assert speaker_id == cfg.model.speaker before every generation call;
#                  3,000 chapters reprocessed with speaker=128; similarity 0.84; MOS 4.1

The fine-tuning evaluation script had always been correct — it explicitly passed speaker=128 and produced Evelyn Cole’s voice at MOS 4.1. The validation metrics that the team reviewed each month were all computed on the training machine using the eval script. The inference server, written independently, used the same generate_spectrogram call pattern from the NeMo TTS documentation examples, which demonstrate single-speaker use and do not specify the speaker argument. The documentation’s omission of the speaker kwarg in examples is unremarkable for single-speaker deployments but fatal for multi-speaker fine-tuned deployments. The retainer consultant identified the discrepancy between the two scripts in 30 minutes. The fix was a single keyword argument. Hours logged to HourTab with per-session breakdown.

# Fixed inference_server.py

import torch
import numpy as np
from nemo.collections.tts.models import FastPitchModel, HifiGanModel

fastpitch = FastPitchModel.restore_from("westfield-evelyn-cole-v3.nemo")
hifigan   = HifiGanModel.restore_from("hifigan-22050hz.nemo")
fastpitch.eval()
hifigan.eval()

EVELYN_COLE_SPEAKER_ID = 128  # index used in cfg.model.speaker during fine-tuning

def synthesize_chapter(text: str) -> np.ndarray:
    tokens = fastpitch.parse(text)
    tokens = tokens.to(fastpitch.device)

    # Assert speaker identity is correct before generating
    assert EVELYN_COLE_SPEAKER_ID < fastpitch.speaker_emb.weight.shape[0], (
        f"Speaker {EVELYN_COLE_SPEAKER_ID} not in embedding table "
        f"(size {fastpitch.speaker_emb.weight.shape[0]})"
    )

    with torch.no_grad():
        spec, spec_len, _, _ = fastpitch.generate_spectrogram(
            tokens=tokens,
            speaker=EVELYN_COLE_SPEAKER_ID   # ← FIX: explicitly specify fine-tuned speaker
        )
        audio = hifigan.convert_spectrogram_to_audio(spec=spec)

    return audio.squeeze().cpu().numpy()

# After fix — 3,000 chapters reprocessed:
# Speaker similarity cosine: 0.84  vs 0.29 pre-fix
# MOS (voice identity):      4.1   vs 2.1 pre-fix
# MOS (naturalness):         4.0   unchanged (speech quality was always correct)
# All 15 audiobook titles regenerated; client accepted all chapters

Related retainer posts


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 →