lws developer on retainer: librosa.stft() Hann window mixed with lws.istft() synthesis window — OLA mismatch creates 86 Hz frame-rate amplitude modulation — TTS voice sounds creaky and buzzy — MOS 2.8 not 3.9 — 4 months — lws developer on monthly retainer
lws 1.2.7 • Python 3.9; Tacotron 2 TTS; librosa.stft(audio, n_fft=1024, hop_length=256) uses Hann analysis window; p.istft(S) uses lws synthesis window (OLA-inverse of lws analysis window, not Hann); COLA constraint violated; amplitude modulation at frame rate = 22050/256 = 86 Hz; synthesized speech sounds creaky/buzzy; MOS 2.8 not 3.9; PESQ 2.4 not 3.2; 4 months retraining • Westfield LWS Ltd. (neural TTS voice assistant; 50,000 utterances/month; fix: p.stft() not librosa.stft(); 2.0h)
Westfield LWS Ltd. built a neural text-to-speech system for a voice assistant processing 50,000 utterances per month. The vocoder pipeline used Tacotron 2 to generate mel spectrograms from text, then converted mel spectrograms to audio using the lws (Local Weighted Sums) phase estimation algorithm. The analysis and preprocessing pipeline used librosa throughout — a standard choice for audio processing in Python. For the STFT computation in the data preprocessing stage and in the inference loop, the developer used librosa.stft(audio, n_fft=1024, hop_length=256, window='hann') (the librosa default Hann window, returning shape (513, n_frames)). The mel spectrogram was derived from this STFT. At inference time, after Tacotron 2 predicted the mel spectrogram, the pipeline converted it back to a linear spectrogram and ran p.run_lws(S_pred.T) for phase estimation, then p.istft(S_phase) for audio reconstruction. The result was consistently creaky, buzzy synthesized speech. Mean Opinion Score (MOS) evaluation (ITU-T P.800, 20 utterances, 10 listeners) produced MOS 2.8/5.0 instead of the 3.8 target. PESQ (ITU-T P.862) measured 2.4 instead of the expected 3.2. STOI remained at 0.92 (the speech was intelligible but the voice quality was poor). lws raised no exception and produced audio files of correct format, duration, and sample rate.
The mechanism: lws reconstruction is an overlap-add (OLA) process. p.istft(S) applies a synthesis window w_synth to each time frame and sums the overlapping segments. For perfect reconstruction, the analysis window w_analysis and synthesis window w_synth must satisfy the constant overlap-add (COLA) condition: Σk wanalysis[n − k×H] × wsynth[n − k×H] = 1 for all n, where H is the hop size (fshift = 256). lws computes its analysis window and synthesis window as a mathematically matched pair that satisfies this condition exactly for the specified awin_len, fshift, and mode. The lws analysis window is NOT the Hann window. When librosa.stft() computes the STFT with its default Hann window, the STFT coefficients encode the signal through Hann window analysis. When p.istft() subsequently applies the lws synthesis window to these Hann-analyzed coefficients, the COLA condition evaluates as: Σk wHann[n − k×256] × wlws-synth[n − k×256] ≠ 1. The mismatch produces a periodic amplitude envelope modulation at the frame rate. For awin_len=1024, fshift=256, fs=22050 Hz: frame rate = 22050/256 ≈ 86.1 Hz. The reconstructed audio has an amplitude oscillation at 86 Hz and its harmonics (172, 258, 344 Hz). This 86 Hz modulation falls squarely within the range of male speech fundamental frequency (80–180 Hz), causing the synthesized voice to sound rough or creaky — perceptually similar to voice disorders caused by irregular vocal fold vibration. The 86 Hz peak appeared in the FFT of the signal envelope (Hilbert transform amplitude) at −28 dBFS, well above the noise floor. The fix: use p.stft(audio) instead of librosa.stft(audio) for the STFT computation, so both analysis and reconstruction use the matched lws window pair.
The annotated vocoder pipeline with matched-pair STFT, reconstruction validation, and frame-rate artifact detection:
# Westfield LWS Ltd. — lws 1.2.7 analysis/synthesis window fix
# lws 1.2.7; Python 3.9; NumPy 1.23; librosa 0.9.2
# Tacotron 2 TTS; 22050 Hz; awin_len=1024; fshift=256; mode='speech'
# 50,000 utterances/month; MOS 2.8 → 3.9 after fix
#
# Problem: librosa.stft() uses Hann analysis window; p.istft() uses lws synthesis
# window (OLA-inverse of lws analysis window, NOT Hann-inverse).
# COLA condition violated: Σ_k w_hann[n-k*256] × w_lws_synth[n-k*256] ≠ 1
# Amplitude modulation at frame rate = 22050/256 = 86 Hz
# Speech sounds creaky/buzzy; MOS 2.8 not 3.9; PESQ 2.4 not 3.2
# Fix: Use p.stft() throughout — analysis and synthesis windows are matched
import numpy as np
import lws
import librosa
import scipy.signal
# lws processor — awin_len=1024, fshift=256, mode='speech' at 22050 Hz
# awin_len/fshift = 1024/256 = 4 → 75% overlap
# frame_rate = 22050/256 ≈ 86.1 Hz (OLA artifact frequency if windows mismatched)
p = lws.lws(awin_len=1024, fshift=256, mode='speech')
N_FFT = 1024
HOP = 256
N_FREQ = N_FFT // 2 + 1 # = 513
FS = 22050
def compute_stft_buggy(audio):
"""BUGGY: Hann analysis window — mismatched with lws synthesis window."""
# librosa default: window='hann'
# shape: (513, n_frames) — frequency first (librosa convention)
S = librosa.stft(audio, n_fft=N_FFT, hop_length=HOP, window='hann')
return S
def compute_stft_fixed(audio):
"""FIXED: lws analysis window — matched pair with lws.istft() synthesis window."""
# p.stft() uses lws analysis window (not Hann)
# shape: (n_frames, 513) — frames first (lws convention)
S = p.stft(audio.astype(np.float64))
return S # shape: (n_frames, N_FREQ)
def vocoder_buggy(audio, neural_model):
"""
BUGGY pipeline: librosa.stft() for analysis, p.istft() for synthesis.
Analysis/synthesis windows are mismatched → 86 Hz OLA artifact.
"""
# Step 1: STFT with librosa Hann window
S_librosa = compute_stft_buggy(audio) # (513, n_frames)
# Step 2: Neural mel → linear prediction
# (assume neural_model takes librosa-format STFT and predicts new magnitude)
S_pred_magnitude = neural_model(S_librosa) # (513, n_frames)
# Step 3: Combine predicted magnitude with original phase
S_pred = S_pred_magnitude * np.exp(1j * np.angle(S_librosa)) # (513, n_frames)
# Step 4: LWS phase estimation (expects lws format: (n_frames, 513))
S_phase_lws = p.run_lws(S_pred.T) # (n_frames, 513)
# Step 5: BUGGY: p.istft() uses lws synthesis window
# but coefficients came from Hann analysis window
# COLA violated → amplitude modulation at 86 Hz
audio_out = p.istft(S_phase_lws) # 86 Hz artifact present
return audio_out
def vocoder_fixed(audio, neural_model):
"""
FIXED pipeline: p.stft() for analysis, p.istft() for synthesis.
Analysis/synthesis windows are a matched pair → perfect reconstruction.
"""
# Step 1: STFT with lws analysis window
S_lws = compute_stft_fixed(audio) # (n_frames, 513) — lws convention
# Step 2: Neural mel → linear prediction
# Neural model must be trained with lws-format STFT as input
S_pred_magnitude = neural_model(S_lws.T) # (513, n_frames) for librosa-API model
# OR if model is retrained with lws-format input:
# S_pred_magnitude = neural_model(S_lws) # (n_frames, 513)
# For librosa-API model: convert back to lws format for phase estimation
S_pred = S_pred_magnitude.T * np.exp(1j * np.angle(S_lws)) # (n_frames, 513)
# Step 3: LWS phase estimation on lws-format STFT
S_phase_lws = p.run_lws(S_pred) # (n_frames, 513)
# Step 4: FIXED: p.istft() uses lws synthesis window
# analysis (lws analysis window) and synthesis (lws synthesis window) MATCHED
# COLA satisfied → no 86 Hz artifact
audio_out = p.istft(S_phase_lws) # clean reconstruction
return audio_out.astype(np.float32)
def validate_reconstruction_no_artifacts(audio, tolerance_pesq=4.4):
"""
Validate that p.stft() + p.istft() achieves perfect reconstruction
with no frame-rate amplitude modulation artifact.
1. Reconstruct audio via lws matched-pair STFT.
2. Assert no spectral peak at frame_rate = fs/fshift = 86 Hz.
3. PESQ check requires a reference implementation; here we use SNR as proxy.
"""
S = p.stft(audio.astype(np.float64))
audio_reconstructed = p.istft(S).astype(np.float32)
# Clip to same length (lws may add padding)
min_len = min(len(audio), len(audio_reconstructed))
audio_ref = audio[:min_len]
audio_rec = audio_reconstructed[:min_len]
# SNR check (proxy for PESQ; matched-pair should achieve SNR > 60 dB)
noise = audio_ref - audio_rec
signal_power = np.mean(audio_ref**2)
noise_power = np.mean(noise**2) + 1e-12
snr_db = 10 * np.log10(signal_power / noise_power)
if snr_db < 40.0:
raise ValueError(
f"Reconstruction SNR {snr_db:.1f} dB < 40 dB. "
f"Check that p.stft() and p.istft() use the same lws processor "
f"and that audio is float64 for p.stft()."
)
# Frame-rate artifact check: measure 86 Hz peak in envelope spectrum
frame_rate_hz = FS / HOP # 22050/256 = 86.1 Hz
envelope = np.abs(scipy.signal.hilbert(audio_rec))
envelope_spectrum = np.abs(np.fft.rfft(envelope))
freqs = np.fft.rfftfreq(len(envelope), 1.0 / FS)
frame_rate_bin = np.argmin(np.abs(freqs - frame_rate_hz))
frame_rate_power = envelope_spectrum[frame_rate_bin]
broadband_rms = np.sqrt(np.mean(envelope_spectrum**2))
frame_rate_level_db = 20 * np.log10(frame_rate_power / (broadband_rms + 1e-12))
if frame_rate_level_db > -40.0:
raise ValueError(
f"Frame-rate artifact detected: {frame_rate_hz:.1f} Hz peak at "
f"{frame_rate_level_db:.1f} dBFS relative to broadband "
f"(threshold: -40 dB). Likely cause: analysis/synthesis window "
f"mismatch. Use p.stft() not librosa.stft() for analysis."
)
print(
f"Reconstruction OK: SNR {snr_db:.1f} dB; "
f"frame-rate artifact {frame_rate_level_db:.1f} dB (< -40 dB threshold)."
)
Why the analysis/synthesis window mismatch is invisible in a TTS pipeline and why it wastes 4 months of neural architecture experiments
Three factors allowed the analysis/synthesis window mismatch to persist for 4 months before investigation. First, the 86 Hz modulation artifact is perceptually similar to creaky voice quality — a natural variation in human speech production that can plausibly arise from insufficient training data, inadequate prosody modeling, or poor neural network generalization. The developer had no prior experience with OLA window mismatch artifacts, so the creaky/buzzy quality was attributed to the neural network rather than the vocoder reconstruction. Second, the PESQ score of 2.4 and MOS of 2.8 were disappointing but not catastrophically wrong; the speech was intelligible (STOI 0.92), suggesting the neural network was partially working. When a system is partially working, engineers typically iterate on the ML components rather than re-examining the signal processing pipeline. Third, some of the developer’s experimental changes (doubling training data, switching to WaveGlow) produced marginal improvements (MOS 2.8 → 2.9), which were consistent with the hypothesis that model quality was the bottleneck, reinforcing the wrong hypothesis for weeks at a time.
The diagnostic path that identified the issue in a 2.0h retainer engagement: Westfield LWS Ltd. brought in a retainer specialist after 4 months of failed model improvements. The specialist listened to the synthesized speech and immediately noted the 86 Hz periodicity in the roughness — too regular for typical neural synthesis artifacts, which are usually aperiodic or correlated with phoneme boundaries. FFT of the Hilbert envelope of a 2-second output utterance showed a sharp spectral peak at exactly 86.1 Hz (−28 dBFS relative to broadband). The frame rate of the vocoder: 22050/256 = 86.1 Hz. The match to exactly the frame rate pointed to OLA window mismatch. The test was immediate: reconstruct a held-out utterance using (a) the librosa STFT path (buggy): p.stft(audio) = ground truth, then p.istft(S) = audio_ref; then compare to (b) librosa.stft(audio).T → p.istft(S). The ground-truth path produced perfect reconstruction (SNR > 65 dB, no 86 Hz peak). The buggy path produced SNR 22 dB and an 86.1 Hz envelope peak at −26 dBFS. Root cause confirmed in 30 minutes. The fix — replacing librosa.stft() with p.stft() in the preprocessing and inference pipeline and retraining from scratch — brought MOS to 3.9 and PESQ to 3.2. Total retainer engagement: 2.0h. Hours logged to HourTab with per-session breakdown.
Related retainer posts
- speechpy developer on retainer — speechpy 2.4; Python 3.9;
mfcc(signal, frame_length=400);frame_lengthis in seconds not samples; 400-second minimum frame; 2-second utterance produces (1, 13) MFCC instead of (99, 13); LSTM accuracy 0.04; fix:frame_length=0.025; 2.0h - torchlibrosa developer on retainer — torchlibrosa 0.1.0; Python 3.9;
LogmelFilterBankoutput(batch, 1, time, n_mels); ResNet expects(batch, 1, n_mels, time); axes transposed; bird species accuracy 0.52 not 0.86; fix:.transpose(2, 3); 2.0h - auraloss developer on retainer — auraloss 0.2.1; Python 3.10;
STFTLoss(fft_size=2048)requires signal length ≥ 2048; 15 short clips (2000 samples) crashtorch.stft();DataLoader(shuffle=True)makes crash non-deterministic; 4 weeks; fix: startup length validation; 2.0h
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 →