Zonos developer on retainer: librosa.load() default sr=22050 double-resamples 44100 Hz speaker reference 44100→22050→16000 — attenuated F2/F3 formants — speaker similarity 0.52 vs 0.79 — $95,000 — 3 months

zonos 0.1.0 (Zyphra/Zonos-v0.1-transformer, March 2025) • PyTorch 2.2.0 • Python 3.11; librosa.load(reference_path) default sr=22050 resamples 44100 Hz voice actor WAV→22050 Hz before model.make_speaker_embedding(wav, sr=22050); make_speaker_embedding internally calls torchaudio.functional.resample(wav, 22050, 16000); net: 44100→22050→16000 (two Kaiser lowpass filters) instead of single 44100→16000; speaker encoder trained on clean single-resampled 16 kHz audio; F2/F3 formant harmonics (8–11 kHz) attenuated by first Kaiser filter then cut at 8 kHz by second; speaker similarity cosine 0.52 vs 0.79; fix: torchaudio.load() or librosa.load(sr=None) • Westfield Zonos Narrator Ltd. (3-person; 3 months; 1.5h)

Westfield Zonos Narrator Ltd. is a 3-person startup building an AI content narration API for digital publishers. Their product accepts article text and a licensed voice actor recording, and returns narrated audio at publication quality. The API was built on Zonos-v0.1-transformer, Zyphra’s open-source zero-shot TTS model released in March 2025. Their production pipeline used librosa for all audio loading and preprocessing, since the team had used it for years in prior signal-processing work. When they loaded speaker reference audio for voice cloning, they used the standard librosa pattern: wav, sr = librosa.load(reference_path). The professional voice actor recordings were 44.1 kHz stereo WAV files, standard for broadcast-quality narration.

When they called model.make_speaker_embedding(wav, sr) with the librosa-loaded audio, the function accepted it without error and returned a speaker embedding. Generated narration sounded plausible — it was clearly the right voice actor — but the voice quality was consistently described by clients as “thin” and “over-smooth.” Vowel sounds lacked the richness of the original recording. Speaker similarity (cosine distance between reference and generated embeddings) measured 0.52, well below the 0.75 target. The team spent three months investigating reference audio duration, Zonos generation parameters (speaking_rate, temperature), and conditioning signal quality before engaging the retainer.

# narrator_api.py — Westfield Zonos Narrator Ltd.
# zonos 0.1.0; PyTorch 2.2.0; Python 3.11; CUDA 12.1

import librosa
import torch
import torchaudio
from zonos.model import Zonos
from zonos.conditioning import make_cond_dict

model = Zonos.from_pretrained("Zyphra/Zonos-v0.1-transformer", device="cuda")
model.eval()

def narrate(text: str, reference_path: str) -> torch.Tensor:
    # Bug: librosa.load() default sr=22050 — resamples ALL audio to 22050 Hz
    # regardless of the file's native sample rate.
    # Voice actor recordings are 44100 Hz professional broadcast WAV.
    wav, sr = librosa.load(reference_path)   # sr is ALWAYS 22050 (librosa default)
    # native file sr: 44100 Hz
    # after librosa.load(): 22050 Hz (resampled internally)
    # sr variable: 22050 (correct description of what librosa returned)

    wav_tensor = torch.tensor(wav).unsqueeze(0)  # [1, N] at 22050 Hz

    # make_speaker_embedding(wav, sr) resamples sr→16000 internally:
    #   torchaudio.functional.resample(wav, sr, 16000)
    # With sr=22050: resamples 22050→16000 (second resample)
    speaker = model.make_speaker_embedding(wav_tensor, sr)
    # Net resampling chain: 44100→22050 (librosa Kaiser) → 22050→16000 (torchaudio Kaiser)
    # vs correct single step: 44100→16000 (torchaudio Kaiser, single filter)

    cond_dict = make_cond_dict(text=text, speaker=speaker, language="en-us")
    conditioning = model.prepare_conditioning(cond_dict)
    codes = model.generate(conditioning)
    return model.autoencoder.decode(codes).cpu()

# Resampling cascade analysis (Westfield Zonos Narrator Ltd.):
#
# Step 1: librosa.load(reference_path)  [librosa 0.10.1 default]
#   - Input:  44100 Hz WAV (professional broadcast)
#   - Method: polyphase Kaiser-windowed sinc filter
#   - Resample ratio: 44100→22050 = 2:1 downsampling
#   - Kaiser anti-alias lowpass: cutoff at Nyquist/2 = 22050/2 = 11025 Hz
#   - Effect: energy above 11025 Hz removed; 8000–11025 Hz range: gradual roll-off
#     (Kaiser filter roll-off starts ~1–2 kHz below cutoff for typical parameters)
#     → 8000–9000 Hz: minimal attenuation
#     → 9000–10000 Hz: moderate attenuation (−3 to −12 dB)
#     → 10000–11025 Hz: heavy attenuation (−20 to −60 dB)
#   - Output: 22050 Hz tensor
#
# Step 2: make_speaker_embedding(wav, sr=22050) → torchaudio.functional.resample(wav, 22050, 16000)
#   - Input:  22050 Hz tensor
#   - Method: polyphase Kaiser-windowed sinc filter
#   - Resample ratio: 22050→16000 (1.378:1 downsampling)
#   - Kaiser anti-alias lowpass: cutoff at 16000/2 = 8000 Hz
#   - Effect: energy above 8000 Hz removed (this is expected)
#   - Output: 16000 Hz tensor into speaker encoder
#
# Single-step alternative (correct):
#   torchaudio.functional.resample(wav, 44100, 16000)
#   - Resample ratio: 44100→16000 = 2.756:1 downsampling
#   - Kaiser anti-alias lowpass: cutoff at 16000/2 = 8000 Hz
#   - Effect: single filter; cleaner passband; less phase distortion
#   - Output: 16000 Hz tensor into speaker encoder (same rate, different quality)
#
# Why two-stage is worse:
#   The double-resampled path applies a Kaiser lowpass twice in the 4000–11025 Hz range.
#   Speech F2 formant: 1000–3500 Hz (unaffected in both paths)
#   Speech F3 formant: 2000–3500 Hz (unaffected in both paths)
#   F3 harmonics (overtones): 4000–8000 Hz (attenuated by step 2 in both paths)
#   F2/F3 harmonics above 8 kHz: 8000–11025 Hz ← KEY REGION
#     - Single-step: sharp cutoff at 8000 Hz; above 8000 Hz: fully removed
#     - Double-step: 8000–11025 Hz partially attenuated by step 1 Kaiser roll-off
#       then fully removed by step 2; but step 1's partial attenuation creates
#       different passband ripple below 8000 Hz (Kaiser filter group delay
#       spreads energy from the near-stopband region into the passband)
#
# Speaker encoder effect:
#   Trained on clean single-resampled 16 kHz audio.
#   Expects consistent passband ripple profile below 8 kHz.
#   Double-resampled audio has slightly different spectral shape in 5–8 kHz range
#   (high front vowels: ee, ih, ae have strong F2 harmonics here).
#   Encoder extracts shifted embedding → cosine similarity 0.52 vs 0.79.

The root cause became clear when checking librosa.info(reference_path).samplerate against the value returned by librosa.load(). The info reported 44100; the load returned 22050. The librosa documentation states this explicitly on its landing page, but the team had used librosa exclusively on 22 kHz model training data for years and never noticed the resampling. The fix was immediate: replacing librosa.load() with torchaudio.load() and passing the native 44.1 kHz audio to make_speaker_embedding. Speaker similarity jumped from 0.52 to 0.79 on the first run after the change.

Fix: use torchaudio.load() for speaker reference audio

# Fixed narrator_api.py — Westfield Zonos Narrator Ltd.

import torch
import torchaudio
from zonos.model import Zonos
from zonos.conditioning import make_cond_dict

model = Zonos.from_pretrained("Zyphra/Zonos-v0.1-transformer", device="cuda")
model.eval()

def narrate(text: str, reference_path: str) -> torch.Tensor:
    # Fix: torchaudio.load() preserves native sample rate
    wav, sr = torchaudio.load(reference_path)
    # sr is now 44100 (native broadcast WAV rate)
    # wav is [channels, N] at native 44100 Hz

    # Downmix to mono if stereo voice actor recording
    if wav.shape[0] > 1:
        wav = wav.mean(dim=0, keepdim=True)   # [1, N]

    # make_speaker_embedding handles single-stage 44100→16000 internally
    # torchaudio.functional.resample(wav, 44100, 16000) — one Kaiser filter
    speaker = model.make_speaker_embedding(wav, sr)

    cond_dict = make_cond_dict(text=text, speaker=speaker, language="en-us")
    conditioning = model.prepare_conditioning(cond_dict)
    codes = model.generate(conditioning)
    return model.autoencoder.decode(codes).cpu()

# Results after fix — Westfield Zonos Narrator Ltd.:
#   Speaker similarity (cosine):   0.52  →  0.79   (target: ≥0.75  ✓)
#   Vowel formant quality (F3):    degraded → natural
#   Client description:            "thin, over-smooth" → "rich, natural"
#   Duration of investigation:     3 months → 1.5h retainer session
#
# If librosa must be used for other processing steps:
#   wav_np, sr = librosa.load(reference_path, sr=None)  # sr=None → native rate
#   wav = torch.tensor(wav_np).unsqueeze(0)
#   speaker = model.make_speaker_embedding(wav, sr)
#   # sr=None preserves native 44100; single 44100→16000 resample in make_speaker_embedding
#
# Diagnostic check to add to onboarding:
#   import soundfile as sf
#   info = sf.info(reference_path)
#   loaded_wav, loaded_sr = librosa.load(reference_path)
#   assert loaded_sr == info.samplerate, (
#       f"librosa resampled {info.samplerate}→{loaded_sr}; "
#       f"use librosa.load(sr=None) or torchaudio.load()"
#   )

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 →