{"record":{"id":"cac01154cb328c08","repo":"CorentinJ/Real-Time-Voice-Cloning","slug":"both-increase-only-and-decrease-only-are-set","errorCode":null,"errorMessage":"Both increase only and decrease only are set","messagePattern":"Both increase only and decrease only are set","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"encoder/audio.py","lineNumber":113,"sourceCode":"    def moving_average(array, width):\n        array_padded = np.concatenate((np.zeros((width - 1) // 2), array, np.zeros(width // 2)))\n        ret = np.cumsum(array_padded, dtype=float)\n        ret[width:] = ret[width:] - ret[:-width]\n        return ret[width - 1:] / width\n    \n    audio_mask = moving_average(voice_flags, vad_moving_average_width)\n    audio_mask = np.round(audio_mask).astype(bool)\n    \n    # Dilate the voiced regions\n    audio_mask = binary_dilation(audio_mask, np.ones(vad_max_silence_length + 1))\n    audio_mask = np.repeat(audio_mask, samples_per_window)\n    \n    return wav[audio_mask == True]\n\n\ndef normalize_volume(wav, target_dBFS, increase_only=False, decrease_only=False):\n    if increase_only and decrease_only:\n        raise ValueError(\"Both increase only and decrease only are set\")\n    dBFS_change = target_dBFS - 10 * np.log10(np.mean(wav ** 2))\n    if (dBFS_change < 0 and increase_only) or (dBFS_change > 0 and decrease_only):\n        return wav\n    return wav * (10 ** (dBFS_change / 20))\n","sourceCodeStart":95,"sourceCodeEnd":118,"githubUrl":"https://github.com/CorentinJ/Real-Time-Voice-Cloning/blob/890f3a03187195b9829db2079b75c2ba2ab0405c/encoder/audio.py#L95-L118","documentation":"Raised by normalize_volume() in encoder/audio.py when both `increase_only` and `decrease_only` keyword arguments are True. These flags are mutually exclusive: increase_only means 'only amplify quiet audio', decrease_only means 'only attenuate loud audio'. Setting both is a contradictory request (the function would have to both apply and skip any gain change), so it fails fast with a ValueError before touching the waveform.","triggerScenarios":"Calling normalize_volume(wav, target_dBFS, increase_only=True, decrease_only=True). In this codebase the caller is encoder_preprocess.py's preprocess_wav path (volume normalization during trimming); in user code, any direct call passing both flags or a config that maps two independent booleans onto these parameters.","commonSituations":"A wrapper/config that exposes separate 'allow_boost' and 'allow_cut' options and forwards them verbatim; copying example code and flipping flags without reading the semantics; defaulting both parameters to True 'to be safe'.","solutions":["Pass at most one of increase_only / decrease_only (both False is valid and applies the gain unconditionally).","If the two flags come from a config object, validate them together at config load time and fail with a clearer message naming the config keys.","If you want a deadband (neither boost nor cut), that is not what these flags do — clamp dBFS_change yourself before calling with both flags False."],"exampleFix":"// before\nnormalize_volume(wav, -30, increase_only=True, decrease_only=True)\n\n// after\nnormalize_volume(wav, -30, increase_only=True)","handlingStrategy":"validation","validationCode":"def safe_normalize(wav, target_dbfs, increase_only=False, decrease_only=False):\n    if increase_only and decrease_only:\n        raise ValueError(\"increase_only and decrease_only are mutually exclusive\")\n    return normalize_volume(wav, target_dbfs, increase_only, decrease_only)","typeGuard":null,"tryCatchPattern":"try:\n    out = normalize_volume(wav, -30, increase_only=boost, decrease_only=cut)\nexcept ValueError as e:\n    if \"increase only\" in str(e):\n        boost = boost and not cut  # resolve conflict, prefer decrease_only\n        out = normalize_volume(wav, -30, increase_only=boost, decrease_only=cut)\n    else:\n        raise","preventionTips":["Model the two flags as one tri-state enum or Optional[str] so contradictory states are unrepresentable.","Validate flag pairs at config-load time, not deep inside the audio call.","Never default safety flags to True; default both False."],"tags":["audio","validation","arguments","preprocessing"],"backgroundTag":null,"analyzedSha":"890f3a03187195b9829db2079b75c2ba2ab0405c","analyzedAt":"2026-08-15T02:15:13.202Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}