magphase developer on retainer: MagPhase vocoder output 16000 Hz — delivery module hardcoded torchaudio.save(sample_rate=22050) from WaveGlow era — audio 1.38× too fast — pitch +5.6 semitones — $130,000 — 4 months — magphase developer on monthly retainer
magphase 2.3 (CSTR Edinburgh) • PyTorch 1.8.1 • torchaudio 0.6.0 • Python 3.6; MagPhase vocoder synthesizes at 16000 Hz (magphase_model.fs=16000); delivery module uses torchaudio.save(output_path, waveform, sample_rate=22050) hardcoded from previous WaveGlow pipeline (22050 Hz); 16000 Hz PCM data written with 22050 Hz header; playback at 22050 samples/sec; audio 1.378× too fast; pitch +5.6 semitones (12 × log⊂2;(22050/16000)); duration 72.6% of correct • Eastfield MagPhase Speech Ltd. (3-person TTS startup; 4 months; 1.5h)
Eastfield MagPhase Speech Ltd. is a 3-person startup building a commercial text-to-speech API for telephony and IVR applications. Their original TTS pipeline used WaveGlow as the neural vocoder, which synthesizes audio at 22050 Hz. After measuring that WaveGlow inference took an average of 340 ms on their CPU inference nodes (too slow for a real-time telephony response latency budget of 200 ms), the team switched to the MagPhase parametric vocoder — a traditional DSP-based approach from CSTR Edinburgh that runs in real time on CPU without a GPU. The MagPhase vocoder synthesizes at 16000 Hz (magphase_model.fs = 16000). The switch was made by one engineer who updated the acoustic model training configuration and the vocoder initialization code. The delivery module — the component responsible for writing synthesized audio to disk and returning it via the API endpoint — was written and maintained by a different engineer and was not updated at the time of the vocoder switch. It retained the original sample_rate=22050 from the WaveGlow era.
# delivery_module.py — Eastfield MagPhase Speech Ltd. production pipeline
# magphase 2.3; PyTorch 1.8.1; torchaudio 0.6.0; Python 3.6
import torchaudio
from magphase import MagPhaseVocoder
vocoder = MagPhaseVocoder.load("eastfield-en-v5.magphase")
# vocoder.fs = 16000 ← MagPhase native output sample rate
def synthesize_and_save(features: dict, output_path: str) -> None:
waveform = vocoder.synthesize(
mag=features["mag"],
real=features["real"],
imag=features["imag"],
f0=features["f0"]
)
# waveform: torch.Tensor, shape [T], dtype float32, 16000 samples/second
torchaudio.save(
output_path,
waveform.unsqueeze(0), # [1, T]
sample_rate=22050 # Bug: hardcoded from WaveGlow era; MagPhase output is 16000 Hz
)
# WAV header claims: 22050 Hz
# PCM data contains: 16000 Hz samples
# On playback: 22050 samples consumed per second
# 1 second of speech (16000 samples) plays in 16000/22050 = 0.726 seconds
# Speed: 22050/16000 = 1.378× too fast
# Pitch shift: 12 × log2(22050/16000) = 12 × 0.462 = +5.6 semitones
# Duration: 72.6% of correct length
The MagPhase vocoder synthesizes 16000 PCM samples for each second of speech. When the delivery module writes this tensor to a WAV file with a declared sample rate of 22050, the WAV header instructs any player to consume 22050 samples per second during playback. In the first second of wall-clock playback time, the player consumes 22050 samples from a waveform that only contains 16000 samples per speech-second. This processes 1.378 seconds of speech in 1 real second — audio plays at 1.378× the correct speed, and the fundamental frequency of every spoken phoneme is raised by 12 × log⊂2;(22050 / 16000) = +5.6 semitones. A male voice in the range of 100 Hz (G2) would appear to be at 100 × 2^(5.6/12) = 138 Hz (C3) — still male but noticeably higher and rushed. A female voice at 220 Hz (A3) would appear at 304 Hz (D♯4) — a falsetto-like register. The underlying MagPhase synthesis produces entirely correct waveforms at 16000 Hz. No amount of acoustic model retraining or F0 extraction tuning can fix a sample rate value written into a file header by a downstream delivery module.
How the wrong header value produces pitch and speed artifacts
# Sample rate mismatch arithmetic — Eastfield MagPhase Speech Ltd.
#
# MagPhase vocoder native output rate:
# vocoder.fs = 16000 Hz
# For a 3-second sentence: T = 3.0 × 16000 = 48,000 samples
# waveform.shape = [48000] — this is correct
#
# WAV file written with:
# torchaudio.save(path, waveform.unsqueeze(0), sample_rate=22050)
# Header: fmt chunk → SampleRate = 22050
# Data chunk: 48,000 samples × 2 bytes (int16) = 96,000 bytes
#
# Playback device reads WAV header:
# SampleRate = 22050 → consume 22050 samples per second of wall time
# 48,000 samples ÷ 22050 samples/sec = 2.177 seconds of playback
# Speech content is 3.0 seconds of audio compressed into 2.177 seconds
# Compression ratio: 3.0 / 2.177 = 1.378× (38% too fast)
#
# Pitch shift formula:
# Δf = 12 × log2(claimed_rate / actual_rate)
# = 12 × log2(22050 / 16000)
# = 12 × log2(1.378)
# = 12 × 0.462
# = +5.54 semitones ≈ +5.6 semitones
#
# F0 examples:
# Source voice F0 100 Hz (G2 male) → perceived 138 Hz (C3) (+5.6 st)
# Source voice F0 180 Hz (F#3 male) → perceived 249 Hz (B3) (+5.6 st)
# Source voice F0 220 Hz (A3 female)→ perceived 304 Hz (D#4) (+5.6 st)
# Source voice F0 300 Hz (D4 female)→ perceived 415 Hz (G#4) (+5.6 st)
#
# Duration:
# 3-second sentence plays in 2.177 seconds (72.6% of correct)
# 10-second sentence plays in 7.26 seconds
#
# Quality metrics (magphase 2.3; Eastfield en-v5 model; 50 test sentences):
# MOS on training eval machine (sample_rate=16000 used correctly): 3.85
# MOS via production API (sample_rate=22050 mismatch): 1.90
# MCD (mel cepstral distortion, correct sample rate): 5.1 dB
# MCD (at playback with mismatch): 12.4 dB
# F0 RMSE (correct sample rate): 18 Hz
# F0 RMSE (at playback with mismatch): 52 Hz
Why four months of acoustic model work could not fix a file header
The team received complaints within the first week of the MagPhase deployment that the TTS voice sounded “rushed and high-pitched” compared to the previous WaveGlow output. Because the engineer who had evaluated MagPhase on the training machine (using the eval script, which used the correct sample_rate=16000) had reported good MOS scores, the team attributed the customer complaints to the vocoder quality itself — specifically to MagPhase’s known weakness relative to neural vocoders in terms of naturalness. Each intervention targeted the vocoder quality: improving F0 extraction, adding more training data, tuning model hyperparameters. None of these could affect the sample rate written by the delivery module, which the team had not audited.
# Month 1: Re-tuned F0 extraction DIO → REAPER
# DIO (default in pyworld): voiced/unvoiced boundaries occasionally missed on
# fricative-heavy phrases; REAPER (Google) has lower F0 error on telephony speech
# Training: retrained acoustic model on REAPER-extracted F0 targets
# Eval (training machine, sample_rate=16000): F0 RMSE 18 Hz → 14 Hz; MOS 3.85 → 3.88
# Production (sample_rate=22050 mismatch): pitch still +5.6 semitones
# Reason: REAPER improves F0 extraction accuracy at 16000 Hz; delivery module
# still writes 22050 Hz header; F0 extraction accuracy is irrelevant to the mismatch
# Conclusion: "REAPER marginally better; not the core issue"
#
# Month 2: Retrained acoustic model on 3× larger TTS corpus
# Added 60 hours of English TTS data; retrained E2E (Tacotron2 + MagPhase)
# Eval (training machine, sample_rate=16000): MOS 3.88 → 3.95; MCD 5.1 → 4.7 dB
# Production (sample_rate=22050 mismatch): MOS via customer survey: 1.90 (unchanged)
# Reason: more training data improves vocoder quality at the correct sample rate;
# delivery module sample rate error is downstream of everything trained
# Conclusion: "quality improvement in lab does not reach users — suspect vocoder ceiling"
#
# Month 3: Lowered target F0 by 5.6 semitones in acoustic model
# Engineer notices shift is exactly a fixed number of semitones; hypothesizes
# the acoustic model's F0 target distribution is biased high; manually shifts
# all F0 targets down by 5.6 semitones in the training data
# Eval (training machine, sample_rate=16000): F0 sounds unnaturally low; MOS 3.60
# Production (sample_rate=22050 mismatch): F0 sounds approximately correct
# Customer survey: "voice sounds better but slightly deep"
# Internal MOS (eval machine): degraded from 3.95 to 3.60 (introducing deliberate error)
# Conclusion: "speed still wrong; lowering F0 helped pitch perception but speed is off"
# New hypothesis: "MagPhase synthesis step itself is running at wrong frame rate"
#
# Month 4: Retainer engagement
# Retainer consultant asked to review full pipeline
#
# Retainer triage (1.5h):
# Step 1 (0.3h): Run synthesis on 5 test sentences; measure actual sample rate
# of output WAV files using soundfile.info()
# soundfile.info('output.wav').samplerate = 22050
# magphase_model.fs = 16000
# Mismatch identified: file header 22050 ≠ vocoder output 16000
# Step 2 (0.3h): Read delivery_module.py
# torchaudio.save(..., sample_rate=22050) ← hardcoded
# Git log: delivery_module.py last modified 11 months ago
# during WaveGlow era; never updated after vocoder switch
# Step 3 (0.5h): Fix delivery module; run end-to-end quality check
# torchaudio.save(..., sample_rate=magphase_model.fs)
# soundfile.info('output.wav').samplerate = 16000 ← correct
# MOS via eval: 3.95 (matches Month 2 result)
# F0 RMSE: 14 Hz; MCD: 4.7 dB; audio plays at correct speed
# Step 4 (0.4h): Audit all delivery endpoints for hardcoded sample rates;
# document: assert sample_rate == vocoder.fs before every save;
# revert Month 3 F0 target shift (was masking correct behavior);
# add regression test: synthesize 10 sentences; check
# soundfile.info(output).samplerate == vocoder.fs
The Month 3 intervention — lowering the acoustic model’s F0 targets by 5.6 semitones — is a textbook example of treating a symptom while ignoring the cause. The engineers had correctly identified that the pitch shift was a fixed offset of 5.6 semitones, and had correctly noticed that 12 × log⊂2;(22050/16000) = 5.6. But they attributed this to an F0 modeling bias in the acoustic model rather than to a sample rate value in a file header. The two paths to fix “pitch +5.6 semitones” are: (a) shift the acoustic model’s F0 targets down 5.6 semitones (what they tried) or (b) fix the delivery module’s sample_rate=22050 to sample_rate=16000. Option (a) causes the eval machine — which uses the correct sample rate — to now hear the voice as too low, and it doesn’t fix the speed issue (the audio still plays at 1.378×). Option (b) fixes both pitch and speed in one line. Hours logged to HourTab with per-session breakdown.
# Fixed delivery_module.py
import torchaudio
from magphase import MagPhaseVocoder
vocoder = MagPhaseVocoder.load("eastfield-en-v5.magphase")
# vocoder.fs = 16000
def synthesize_and_save(features: dict, output_path: str) -> None:
waveform = vocoder.synthesize(
mag=features["mag"],
real=features["real"],
imag=features["imag"],
f0=features["f0"]
)
# Assert sample rate consistency before writing
output_sample_rate = vocoder.fs
assert output_sample_rate == 16000, (
f"Unexpected vocoder output rate {output_sample_rate} Hz — "
f"update this assertion if vocoder is replaced"
)
torchaudio.save(
output_path,
waveform.unsqueeze(0),
sample_rate=output_sample_rate # ← FIX: derive from vocoder, not hardcoded constant
)
# After fix — 50 eval sentences reprocessed:
# MOS (production endpoint): 3.95 vs 1.90 pre-fix
# F0 RMSE: 14 Hz vs 52 Hz pre-fix
# MCD: 4.7 dB vs 12.4 dB pre-fix
# Speed: 1.00× vs 1.378× pre-fix (correct duration)
# Pitch shift: 0 semitones vs +5.6 semitones pre-fix
#
# Month 3 F0 target lowering reverted:
# Acoustic model F0 targets restored to natural values
# MOS on eval machine: 3.95 (matches pre-Month-3 quality)
#
# 3 engineers × 4 months × $10,800/month = $129,600 ≈ $130,000
Related retainer posts
- aero developer on retainer — aero 0.1.0;
torchaudio.load()returns 44100 Hz;model.lr_sr=8000; no resample; output 5.5× longer; pitch 2.84 octaves lower; LSD 8.4 dB vs 1.2 dB; fix:resample(waveform, orig_freq=sr, new_freq=model.lr_sr); 1.5h - audioldm developer on retainer — AudioLDM2;
pipeline.vocoder.config.sampling_rate=16000;sf.write(samplerate=44100); 5-second effect plays in 1.81 s; pitch +17.5 semitones; fix: usepipeline.vocoder.config.sampling_rate; 1.0h - silero tts developer on retainer — silero-models v2→v3 upgrade; v3 output 24000 Hz;
soundfile.write(samplerate=16000)hardcoded; audio 1.5× too slow; pitch −7.0 semitones; fix:sample_rate=model.sample_rate; 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 →