nussl developer on retainer: AudioSignal.audio_data shape is (n_channels, n_samples) — developer expects (n_samples, n_channels) — audio_data[:, 0] extracts shape (2,) not (n_samples,) — voice activity detector receives 2-sample signal — 8 000 podcast recordings per month returned unmixed — 3 weeks — nussl developer on monthly retainer

nussl 1.1.9 • Python 3.9; nussl.AudioSignal.audio_data shape is (num_channels, num_samples) = (2, 882000); developer expects (n_samples, n_channels) from soundfile convention; signal.audio_data[:, 0] extracts shape (2,) • Northfield Nussl Ltd. (podcast source separation pipeline; 8,000 stereo recordings/month from 500 podcast studios; audio_data[:, 0] = shape (2,) — first sample of each channel; VAD receives 2-sample near-zero signal; VAD returns False; Repet separation never triggered; all 8,000 recordings returned unmixed; 3 weeks; fix: signal.audio_data[0, :]; 1.5h retainer engagement)

Northfield Nussl Ltd. built a podcast post-production automation service to separate speech from background music in 8,000 stereo podcast recordings per month submitted by 500 independent podcast studios. The service used nussl 1.1.9’s Repet algorithm to identify repeating background patterns (music beds) and separate them from foreground speech. The pipeline gated source separation on a voice activity detector: recordings with no detected speech (silent gaps, pre-roll, music-only intros) were returned unchanged to avoid unnecessary processing cost. The developer had previously built audio pipelines using soundfile and librosa, both of which return stereo audio as numpy arrays with shape (n_samples, n_channels) — samples on axis 0, channels on axis 1. When switching to nussl for the separation step, the developer used signal.audio_data[:, 0] to extract a mono channel for the VAD, expecting the same (n_samples, n_channels) layout as soundfile.

nussl.AudioSignal.audio_data stores audio with shape (num_channels, num_samples) — channels on axis 0, samples on axis 1. For a 20-second stereo recording at 44100 Hz, signal.audio_data.shape is (2, 882000): axis 0 has length 2 (the two channels), axis 1 has length 882000 (the samples). signal.audio_data[:, 0] selects index 0 along axis 1 (the samples axis), returning a shape (2,) array containing the first sample of channel 0 and the first sample of channel 1 — not the first channel across all 882000 samples. The first sample of a typical podcast recording is very close to 0.0 (most audio files begin at a zero-crossing or with brief pre-roll silence). The resulting 2-element array had values such as [0.0003, -0.0001] — the first sample of each channel at the very start of the file. This 2-element array was passed to the voice activity detector, which computed RMS energy with np.sqrt(np.mean(audio**2)). For values [0.0003, -0.0001], RMS ≈ 0.000224, well below the calibrated speech threshold of 0.001. The VAD returned False for every recording. The separation pipeline’s gate condition evaluated to False and returned the original mixed audio unchanged. All 8,000 recordings per month were delivered with intact background music for 3 weeks. The service returned HTTP 200 responses; output files were valid audio files; response latency was actually lower than expected (no Repet inference). Five podcast studios independently filed support tickets in the same week reporting that the background music removal feature had stopped working, which led to investigation.

The annotated buggy and fixed nussl source separation pipeline, with correct axis extraction and shape validation:

# Northfield Nussl Ltd. — nussl 1.1.9 AudioSignal axis fix
# nussl 1.1.9; Python 3.9
# podcast source separation; 8,000 stereo recordings/month
# Repet algorithm; speech/music separation
# Problem: AudioSignal.audio_data shape (n_channels, n_samples)
#          developer uses [:, 0] expecting (n_samples, n_channels) layout
#          shape (2,) passed to VAD — first sample of each channel
#          VAD RMS near zero → always False → Repet never runs
#          8,000 recordings returned with intact background music
# Fix: audio_data[0, :] extracts first channel shape (n_samples,)

import logging
import numpy as np
import nussl

logger = logging.getLogger(__name__)


# ── BUGGY pipeline ────────────────────────────────────────────────────────────

def extract_mono_buggy(signal: nussl.AudioSignal) -> np.ndarray:
    """
    BUG: nussl AudioSignal.audio_data shape is (n_channels, n_samples).
    [:, 0] selects index 0 along axis 1 (samples axis):
      result = first sample of each channel — shape (n_channels,) = (2,)
    soundfile.read() shape is (n_samples, n_channels):
      [:, 0] there = first channel, all samples — shape (n_samples,)
    The nussl convention is the TRANSPOSE of soundfile's convention.
    """
    # signal.audio_data.shape = (2, 882000) for 20s stereo 44100 Hz
    # BUG: [:, 0] selects column 0 from (2, 882000)
    #      = first sample of each channel = shape (2,)
    mono = signal.audio_data[:, 0]
    # mono.shape = (2,) — WRONG; should be (882000,)
    return mono


def run_separation_buggy(mp3_path: str) -> np.ndarray:
    """
    BUG: VAD receives shape (2,) signal — always returns silence.
    Repet separation never triggered for any recording.
    """
    signal = nussl.AudioSignal(path=mp3_path)
    mono = extract_mono_buggy(signal)

    # VAD: energy-based threshold
    rms = float(np.sqrt(np.mean(mono ** 2)))
    # mono = [sample_0_ch0, sample_0_ch1] ≈ [0.0003, -0.0001]
    # rms ≈ 0.000224 — always below threshold of 0.001
    if rms < 0.001:
        logger.debug(f"VAD: silence detected (RMS={rms:.4f}) — returning original")
        return signal.audio_data   # BUG: always returns here — Repet never runs

    # This block is never reached
    separator = nussl.separation.primitive.Repet(signal)
    separator.run()
    speech, background = separator.make_audio_signals()
    return speech.audio_data


# ── FIXED pipeline ────────────────────────────────────────────────────────────

def extract_mono_fixed(signal: nussl.AudioSignal) -> np.ndarray:
    """
    FIX: use [0, :] to extract first channel from (n_channels, n_samples).
    AudioSignal.audio_data: axis 0 = channels, axis 1 = samples.
    [0, :] selects row 0 = first channel, all samples = shape (n_samples,).
    Alternative: signal.to_mono() averages both channels into one.
    """
    # signal.audio_data.shape = (2, 882000) for 20s stereo 44100 Hz
    # FIX: [0, :] selects row 0 from (2, 882000)
    #      = first channel, all 882000 samples = shape (882000,)
    mono = signal.audio_data[0, :]
    # Shape assertion — catches future axis order changes
    assert mono.ndim == 1, (
        f"Expected 1D mono signal, got shape {mono.shape}. "
        "Check AudioSignal.audio_data axis order: (n_channels, n_samples)."
    )
    assert len(mono) >= 4410, (  # 100ms minimum at 44100 Hz
        f"Mono signal length {len(mono)} too short for VAD. "
        f"Expected at least 4410 samples (100ms at 44100 Hz). "
        "Possible axis confusion — check audio_data[0, :] not audio_data[:, 0]."
    )
    return mono


def run_separation_fixed(mp3_path: str) -> np.ndarray:
    """
    FIX: VAD receives full-length 1D signal — correctly detects speech.
    Repet runs and separates speech from background music.
    """
    signal = nussl.AudioSignal(path=mp3_path)
    mono = extract_mono_fixed(signal)

    # VAD: energy-based threshold on full-length signal
    rms = float(np.sqrt(np.mean(mono ** 2)))
    # mono.shape = (882000,); RMS over 20 seconds of speech+music
    # typical RMS for podcast recording: 0.08-0.25 → VAD True
    if rms < 0.001:
        logger.debug(f"VAD: genuine silence (RMS={rms:.4f}) — returning original")
        return signal.audio_data   # legitimate silence (pre-roll, gap)

    # Repet: separates repeating background (music bed) from foreground (speech)
    separator = nussl.separation.primitive.Repet(signal)
    separator.run()
    speech_signal, background_signal = separator.make_audio_signals()

    # SDR validation: speech SDR should improve vs original mix
    logger.info(
        f"Repet separation complete. "
        f"Speech RMS: {np.sqrt(np.mean(speech_signal.audio_data**2)):.3f}, "
        f"Background RMS: {np.sqrt(np.mean(background_signal.audio_data**2)):.3f}"
    )
    return speech_signal.audio_data

How nussl’s channels-first audio_data convention, the [:, 0] vs [0, :] indexing difference, and a VAD gate combine to silently return 8,000 unmixed podcast recordings per month — and the correct axis extraction pattern for nussl pipelines

The root cause is a clash between two valid but opposite audio array conventions: nussl uses (n_channels, n_samples) (channels first), while soundfile and librosa use (n_samples, n_channels) or (n_samples,) (samples first or 1-D). Both conventions are common in scientific computing — channels-first is used in deep learning frameworks (PyTorch’s torch.Tensor for audio is typically (batch, channels, samples)); samples-first reflects the natural time-series orientation where each row is a point in time. nussl’s choice of channels-first means that the standard soundfile pattern audio[:, 0] (which correctly extracts channel 0 from a (n_samples, n_channels) array) silently extracts the wrong axis when applied to audio_data. The resulting shape (2,) array does not trigger any immediate error: numpy indexing is valid, the array has correct dtype and finite values, and the VAD function accepts it without shape validation. The failure is deferred to the VAD’s energy threshold comparison, which is too low to detect speech because it is computed over 2 near-zero samples rather than the full recording. The silence classification then activates the pipeline’s legitimate early-return branch for silent recordings. The separation algorithm never raises a warning because it never runs. Output files are valid audio. The only observable symptoms are that the output files are identical to the input files and that processing is faster than expected — both of which could easily be explained by other factors (unchanged recordings, infrastructure optimization) in the absence of explicit monitoring. The correct extraction signal.audio_data[0, :] selects row 0 (the first channel) from the (2, 882000) array, returning shape (882000,). The alternative signal.to_mono() averages both channels and returns a new AudioSignal with audio_data.shape = (1, 882000); signal.to_mono().audio_data[0] gives the same 1-D shape. The shape assertion — assert mono.ndim == 1 and len(mono) >= 4410 — catches axis confusion immediately at the extraction point rather than allowing the wrong shape to propagate silently through the VAD gate and appear as a legitimate silence detection. The retainer engagement was 1.5h: 0.5h triage (output files identical to input; check VAD logs: all “silence detected”; print mono shape: (2,); audio_data shape: (2, 882000); identify axis confusion); 0.5h root cause (nussl channels-first convention vs soundfile samples-first; [:, 0] extracts wrong axis; VAD sees near-zero 2-sample input); 0.25h fix ([0, :] extraction; shape assertion; length validation; VAD re-calibration test); 0.25h validation (50-recording test: all VAD True; Repet SDR +8.3 dB average; re-process 3-week backlog: 8,000 recordings; studios confirm background music removed; 1.5h total). Hours logged to HourTab with per-session breakdown.

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 →