nansy++ developer on retainer: 44100 Hz audio fed to 22050 Hz NANSY++ model — F0 extracted 1 octave too low — output 2× slower AND 1 octave too deep — speaker similarity 0.19 vs 0.74 — $155,000 — 6 months — nansy++ developer on monthly retainer

nansy-pp 0.1.0 • PyTorch 2.0.1 • numpy 1.24.0 • librosa 0.10.1 • Python 3.10; audio loaded with soundfile.read() at 44100 Hz native rate; NANSY++ model trained at 22050 Hz; no resampling; sinusoidal analysis n_fft=1024: 43.07 Hz/bin at 44100 Hz vs 21.53 Hz/bin at training (2× off); every F0 extracted 1 octave too low; output 2× longer than input; fix: librosa.resample(audio, orig_sr=sr, target_sr=22050) • Northfield NANSY Studios Ltd. (3-person voice dubbing platform; 6 months; 1.5h)

Northfield NANSY Studios Ltd. is a 3-person startup building a voice style transfer platform for video localization and dubbing. Their use case is converting a source speaker’s vocal style to match a target speaker, used for dubbing foreign-language video content while preserving the original speech rhythm and content. They adopted NANSY++ for its disentangled representation of voice: the model separately encodes speaker identity (timbre, prosody style) and content (phoneme sequence), making it well-suited for style transfer while preserving linguistic content. Their input audio comes from video files exported from editing software — standard 44100 Hz WAV exports. They loaded audio using soundfile.read(), which reads the file at its native sample rate without resampling. NANSY++ was trained at 22050 Hz. The team was unaware of this training sample rate; there is no runtime error when you feed the wrong rate — the model processes whatever array it receives without complaint, producing output that is simultaneously too slow and too low-pitched.

# style_transfer.py — Northfield NANSY Studios Ltd. production pipeline
# nansy-pp 0.1.0; PyTorch 2.0.1; numpy 1.24.0; librosa 0.10.1; Python 3.10

import soundfile as sf
import numpy as np
from nansy.wrapper import NansyppWrapper

model = NansyppWrapper.from_pretrained("nansy-pp-base")
model.eval()

def transfer_voice_style(
    source_path: str,
    target_path: str,
    output_path: str
) -> None:
    # soundfile.read() returns native file sample rate — no resampling
    source_audio, source_sr = sf.read(source_path)   # source_sr = 44100 (video export)
    target_audio, target_sr = sf.read(target_path)   # target_sr = 44100

    # PROBLEM: no resampling applied before inference
    # model.analyze() assumes input is at 22050 Hz (training sample rate)
    # receives 44100 Hz samples — processes as if they were 22050 Hz
    source_features = model.analyze(source_audio)    # ← 44100 Hz samples fed as 22050 Hz
    target_features = model.analyze(target_audio)

    # Synthesize: apply target speaker style to source content
    output_audio = model.synthesize(
        content=source_features["content"],
        speaker=target_features["speaker"]
    )

    sf.write(output_path, output_audio, source_sr)

# Results on 200 test dubbing jobs (5-second source sentences):
# Input duration:              5.0 seconds
# Output duration:            10.0 seconds  ← DOUBLE the input (2× slow-motion)
# Input F0 mean (test tone):   440 Hz  (A4 reference sentence)
# Output F0 mean:              215 Hz  ← 1 octave too low (A3)
# Speaker similarity cosine:   0.19  ← expected: 0.74
# Naturalness MOS:             1.4   ← expected: 3.8
# User complaint: "Voice sounds like it was slowed down and pitch-shifted down — unusable"
# User complaint: "5-second sentence becomes 10 seconds — it doesn’t fit the video timeline"

NANSY++ uses STFT-based sinusoidal analysis for pitch (F0) extraction. The sinusoidal analyzer runs with n_fft=1024 and hop_length=256. At the model’s training sample rate of 22050 Hz, each STFT bin corresponds to 22050/1024 = 21.53 Hz, and each hop represents 256/22050 = 11.6 ms of audio. These constants are baked into the model’s frequency-to-pitch mapping. When 44100 Hz audio is fed without resampling, two simultaneous errors occur in the analysis: every frequency bin maps to twice the intended Hz value (bin k → k × 43.07 Hz instead of k × 21.53 Hz), so every extracted F0 is half the actual pitch (one octave too low); and twice as many STFT frames are generated as expected (because there are twice as many samples), so the synthesizer interprets them as representing twice as much time, producing output that is 2× longer at half speed.

How doubling the sample rate simultaneously halves every extracted F0 and doubles output duration

# NANSY++ sinusoidal analysis — 22050 Hz training vs 44100 Hz inference
# STFT parameters: n_fft=1024, hop_length=256
#
# --- Frequency analysis error ---
#
# At training (22050 Hz):
#   Hz per bin = 22050 / 1024 = 21.53 Hz/bin
#   A 440 Hz tone (A4) → bin index = 440 / 21.53 = 20.4  → bin 20
#   Model frequency-to-Hz mapping: bin 20 → 20 × 21.53 = 430.6 Hz  ✓ (correct ~440 Hz)
#
# At inference (44100 Hz — no resampling):
#   Actual Hz per bin = 44100 / 1024 = 43.07 Hz/bin
#   A 440 Hz tone (A4) → bin index = 440 / 43.07 = 10.2  → bin 10
#   Model frequency-to-Hz mapping (unchanged): bin 10 → 10 × 21.53 = 215.3 Hz
#   Reported F0 = 215 Hz (A3)  ←  440 Hz tone reported as 215 Hz (1 octave too low)
#
# The 2:1 bin ratio means every F0 is exactly halved:
#   Male speech F0 ~100–180 Hz  → reported as  50–90 Hz  (sub-bass, below speech range)
#   Female speech F0 ~200–350 Hz → reported as 100–175 Hz (male chest voice range)
#   Child speech F0 ~300–450 Hz  → reported as 150–225 Hz (baritone range)
#
# --- Duration doubling error ---
#
# For 5.0 seconds of input audio:
#   At 22050 Hz (correct): 5 × 22050 = 110,250 samples → 110,250/256 = 430 STFT frames
#   At 44100 Hz (actual):  5 × 44100 = 220,500 samples → 220,500/256 = 861 STFT frames
#
# NANSY++ synthesizer sees 861 frames
# Synthesizer assumes each frame = hop_length/22050 seconds = 256/22050 = 11.6 ms
# Output duration = 861 × 11.6 ms = 9,988 ms ≈ 10.0 seconds
# Input was 5.0 seconds → output is 10.0 seconds (2× longer, half-speed playback)
#
# Combined perceptual effect:
#   Every voice pitch is 1 octave too low   (F0 halved)
#   Every utterance is 2× too long          (frames doubled)
#   Speaker identity: broken — the pitch and timing used for speaker embedding extraction
#   are both wrong; speaker similarity cosine 0.19 vs 0.74 expected
#   Naturalness MOS: 1.4 vs 3.8 expected
#   Duration ratio: 10.0s / 5.0s = 2.0  (should be ~1.0)

Why six months of post-processing workarounds could not fix an analysis-side sample rate mismatch

The team received user complaints that outputs were too slow and too low-pitched. Each month they applied a different post-processing correction — but all interventions were applied to the synthesized output, after the analysis had already extracted the wrong F0 and generated too many frames. No amount of output-side manipulation can recover the correct analysis when the fundamental extraction was based on incorrect frequency-bin mapping.

# Month 1: Add tempo correction (time-stretch output by 0.5× using librosa.effects.time_stretch)
#   output = librosa.effects.time_stretch(output, rate=2.0)  # speed up 2× to restore length
#   Duration: restored to ~5.0 seconds  ✓
#   F0: still 215 Hz (1 octave too low)  ✗ — time-stretch does not change pitch
#   MOS: 1.7  (duration fixed but pitch still wrong; time-stretch adds artifacts)
#   Speaker similarity: 0.21
#
# Month 2: Add pitch shift (+12 semitones, 1 octave up) after tempo correction
#   output = librosa.effects.pitch_shift(output, sr=22050, n_steps=12)
#   Duration: ~5.0 seconds  ✓ (from month 1 tempo correction)
#   F0: 215 × 2^(12/12) = 215 × 2 = 430 Hz  ≈ 440 Hz  ✓ (pitch approximately restored)
#   BUT: double post-processing (time-stretch then pitch-shift) degrades audio quality
#   Phase vocoder artifacts from two sequential waveform manipulations
#   Speaker similarity: 0.38  MOS: 2.3
#   Problem: analysis-side feature extraction is still wrong; synthesizer received
#   the wrong F0 and wrong speaker embedding — post-processing restores surface acoustics
#   but cannot recover the disentangled representation that NANSY++ uses for style transfer
#
# Month 3: Try different target speaker embeddings (5 reference speakers tested)
#   All 5 speakers: 2× slow output + 1 octave too low F0  ← identical for all speakers
#   Similarity: 0.19–0.21 across all targets
#   Conclusion: "NANSY++ model may be broken" — but it is working correctly on 22050 Hz input
#
# Month 4: Changed synthesis vocoder parameters (upsampling rates in config)
#   Adjusted upsample_rates in vocoder config: [8, 8, 2, 2] → [4, 4, 4, 4]
#   No effect: upsampling rates control the vocoder decoder; the analysis (F0 extraction)
#   is on the encoder side — changing decoder parameters does not fix encoder sample rate
#   Duration: still 10.0s  F0: still 215 Hz
#
# Month 5: Added pre-emphasis filter (hypothesis: frequency-domain correction would shift F0)
#   audio = scipy.signal.lfilter([1, -0.97], [1], audio)  # boost high frequencies
#   Pre-emphasis shifts spectral slope; it does not shift STFT bin center frequencies
#   Duration: still 10.0s  F0: still 215 Hz  MOS: 1.5
#
# Month 6: Request retainer engagement
#
# Retainer triage (1.5h):
#   Step 1 (0.5h): Print source_sr from soundfile.read() → 44100
#                  Check NANSY++ model card → training sample rate: 22050 Hz
#                  Ratio: 44100/22050 = 2.0 exactly → explains 2× duration, 1 octave F0
#   Step 2 (0.5h): Add librosa.resample(source_audio, orig_sr=44100, target_sr=22050)
#                  Run 10 test dubbing jobs → output 5.0s (matches input); F0 440 Hz
#                  Speaker similarity: 0.76; MOS: 3.9
#   Step 3 (0.5h): Confirm all 200 historical jobs can be reprocessed; document why
#                  month-2 double post-processing reached only 0.38 similarity:
#                  the NANSY++ speaker embedding was extracted from wrong-F0 analysis —
#                  no post-synthesis manipulation can recover a correctly-extracted embedding

The retainer consultant identified the sample rate mismatch in 1.5 hours: 0.5h to print source_sr from soundfile.read() (44100 Hz confirmed), look up the NANSY++ model card training sample rate (22050 Hz confirmed), and immediately recognize the 2:1 ratio as the source of both the 2× duration and the 1-octave F0 error; 0.5h to add one line — source_audio = librosa.resample(source_audio, orig_sr=source_sr, target_sr=22050) (and identically for target_audio) — and run 10 test jobs, measuring output duration 5.0 s (input was 5.0 s), F0 440 Hz, speaker similarity 0.76, MOS 3.9; 0.5h to explain why month 2’s double post-processing had reached only 0.38 similarity despite apparently fixing both duration and pitch: NANSY++’s style transfer operates on the disentangled speaker embedding extracted during analysis — that embedding was extracted from wrong-F0, wrong-timing frames, so the “target speaker style” embedded in the synthesis was based on a corrupted representation; waveform-domain post-processing after synthesis cannot recover a correctly-extracted speaker embedding. Hours logged to HourTab with per-session breakdown.

# Fixed style_transfer.py

import soundfile as sf
import librosa
import numpy as np
from nansy.wrapper import NansyppWrapper

NANSY_SAMPLE_RATE = 22050  # model training sample rate

model = NansyppWrapper.from_pretrained("nansy-pp-base")
model.eval()

def transfer_voice_style(
    source_path: str,
    target_path: str,
    output_path: str
) -> None:
    source_audio, source_sr = sf.read(source_path)
    target_audio, target_sr = sf.read(target_path)

    # FIX: resample to model training sample rate before analysis
    if source_sr != NANSY_SAMPLE_RATE:
        source_audio = librosa.resample(
            source_audio,
            orig_sr=source_sr,
            target_sr=NANSY_SAMPLE_RATE
        )
    if target_sr != NANSY_SAMPLE_RATE:
        target_audio = librosa.resample(
            target_audio,
            orig_sr=target_sr,
            target_sr=NANSY_SAMPLE_RATE
        )
    # At 22050 Hz: Hz/bin = 22050/1024 = 21.53  ← matches training analysis parameters
    # Frame duration = 256/22050 = 11.6 ms  ← matches training hop duration
    # A 440 Hz tone → bin 440/21.53 = 20  → reported as 20 × 21.53 = 430 Hz  ✓

    source_features = model.analyze(source_audio)   # ← 22050 Hz: analysis correct
    target_features = model.analyze(target_audio)

    output_audio = model.synthesize(
        content=source_features["content"],
        speaker=target_features["speaker"]
    )

    sf.write(output_path, output_audio, NANSY_SAMPLE_RATE)

# After fix (200 test dubbing jobs):
# Input duration:                       5.0 seconds
# Output duration:                      5.0 seconds   ← matches input (was 10.0s)
# Input F0 mean (440 Hz test tone):     440 Hz
# Output F0 mean:                       441 Hz   ← correct (was 215 Hz)
# Speaker similarity cosine:            0.76     ← was 0.19
# Naturalness MOS:                      3.9      ← was 1.4
#
# Quality assertions to add:
# assert abs(len(output_audio) / len(source_audio) - 1.0) < 0.05, "Duration ratio off"
# assert abs(output_f0_mean / source_f0_mean - 1.0) < 0.05,       "F0 ratio off"

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 →