babysor/MockingBird · error · ValueError

Both increase only and decrease only are set

Error message

Both increase only and decrease only are set

What it means

Raised by normalize_volume when both increase_only=True and decrease_only=True are passed. These flags are mutually exclusive: each restricts volume normalization to one direction, so requesting both is contradictory and indicates a caller bug.

Source

Thrown at models/encoder/audio.py:113

    def moving_average(array, width):
        array_padded = np.concatenate((np.zeros((width - 1) // 2), array, np.zeros(width // 2)))
        ret = np.cumsum(array_padded, dtype=float)
        ret[width:] = ret[width:] - ret[:-width]
        return ret[width - 1:] / width
    
    audio_mask = moving_average(voice_flags, vad_moving_average_width)
    audio_mask = np.round(audio_mask).astype(bool)
    
    # Dilate the voiced regions
    audio_mask = binary_dilation(audio_mask, np.ones(vad_max_silence_length + 1))
    audio_mask = np.repeat(audio_mask, samples_per_window)
    
    return wav[audio_mask == True]


def normalize_volume(wav, target_dBFS, increase_only=False, decrease_only=False):
    if increase_only and decrease_only:
        raise ValueError("Both increase only and decrease only are set")
    dBFS_change = target_dBFS - 10 * np.log10(np.mean(wav ** 2))
    if (dBFS_change < 0 and increase_only) or (dBFS_change > 0 and decrease_only):
        return wav
    return wav * (10 ** (dBFS_change / 20))

View on GitHub (pinned to 28dc5e14f1)

Solutions

  1. Remove one of the two flags — decide whether you want the level only raised or only lowered
  2. Pass neither flag to allow normalization in both directions
  3. Add argument validation upstream (e.g. argparse mutually exclusive group)

Example fix

# before
normalize_volume(wav, target_dBFS=-30, increase_only=True, decrease_only=True)
# after
normalize_volume(wav, target_dBFS=-30, increase_only=True)
Defensive patterns

Strategy: type-guard

Validate before calling

if increase_only and decrease_only:
    raise ValueError('increase_only and decrease_only are mutually exclusive')
wav = normalize_volume(wav, target_dBFS, increase_only=increase_only, decrease_only=decrease_only)

Type guard

def valid_volume_flags(increase_only: bool, decrease_only: bool) -> bool:
    return not (increase_only and decrease_only)

Try / catch

try:
    normalize_volume(wav, target, increase_only, decrease_only)
except ValueError as e:
    # caller bug: fix flag wiring, do not retry
    raise

Prevention

When it happens

Trigger: Calling normalize_volume(wav, target_dBFS, increase_only=True, decrease_only=True), directly or via a wrapper that forwards user flags blindly.

Common situations: Copy-pasted argument lists; CLI flags mapping both booleans to True; refactors that default both flags on.

Related errors


AI-assisted analysis of babysor/MockingBird@28dc5e14f1 (2026-08-27). Data as JSON: /api/errors/c21e634b28fa88b0. Report an issue: GitHub.