{"record":{"id":"639ef5da9d8d3663","repo":"RVC-Boss/GPT-SoVITS","slug":"the-following-condition-must-be-satisfied-max-sil","errorCode":null,"errorMessage":"The following condition must be satisfied: max_sil_kept >= hop_size","messagePattern":"The following condition must be satisfied: max_sil_kept >= hop_size","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/slicer2.py","lineNumber":51,"sourceCode":"    power = np.mean(np.abs(x) ** 2, axis=-2, keepdims=True)\r\n\r\n    return np.sqrt(power)\r\n\r\n\r\nclass Slicer:\r\n    def __init__(\r\n        self,\r\n        sr: int,\r\n        threshold: float = -40.0,\r\n        min_length: int = 5000,\r\n        min_interval: int = 300,\r\n        hop_size: int = 20,\r\n        max_sil_kept: int = 5000,\r\n    ):\r\n        if not min_length >= min_interval >= hop_size:\r\n            raise ValueError(\"The following condition must be satisfied: min_length >= min_interval >= hop_size\")\r\n        if not max_sil_kept >= hop_size:\r\n            raise ValueError(\"The following condition must be satisfied: max_sil_kept >= hop_size\")\r\n        min_interval = sr * min_interval / 1000\r\n        self.threshold = 10 ** (threshold / 20.0)\r\n        self.hop_size = round(sr * hop_size / 1000)\r\n        self.win_size = min(round(min_interval), 4 * self.hop_size)\r\n        self.min_length = round(sr * min_length / 1000 / self.hop_size)\r\n        self.min_interval = round(min_interval / self.hop_size)\r\n        self.max_sil_kept = round(sr * max_sil_kept / 1000 / self.hop_size)\r\n\r\n    def _apply_slice(self, waveform, begin, end):\r\n        if len(waveform.shape) > 1:\r\n            return waveform[:, begin * self.hop_size : min(waveform.shape[1], end * self.hop_size)]\r\n        else:\r\n            return waveform[begin * self.hop_size : min(waveform.shape[0], end * self.hop_size)]\r\n\r\n    # @timeit\r\n    def slice(self, waveform):\r\n        if len(waveform.shape) > 1:\r\n            samples = waveform.mean(axis=0)\r","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/RVC-Boss/GPT-SoVITS/blob/d523079fc05d9a8028d6085bffe4a2757c32abb6/tools/slicer2.py#L33-L69","documentation":"Companion invariant in Slicer.__init__: max_sil_kept must be >= hop_size. max_sil_kept caps how much silence a slice may retain; the silence detector steps in hop_size units, so if the step were larger than the kept-silence budget the detector could never express its intended retention and rounding would degenerate. The constructor validates it right after the min_length/min_interval/hop_size check.","triggerScenarios":"Constructing Slicer with max_sil_kept < hop_size, e.g. Slicer(32000, hop_size=100, max_sil_kept=50) — a big analysis hop combined with a small silence-retention cap.","commonSituations":"Tuning for minimal retained silence (tiny max_sil_kept) while simultaneously raising hop_size for speed; hand-edited YAML/JSON configs where the two fields are tuned independently.","solutions":["Keep max_sil_kept >= hop_size (defaults: 5000 >= 20 ms).","If you raised hop_size, raise max_sil_kept at least to that value — ideally several multiples.","If you want near-zero retained silence, lower hop_size instead of max_sil_kept below it.","Add a shared parameter-validator/clamp in config-loading code so both slicer invariants are checked together."],"exampleFix":"# before\nslicer = Slicer(32000, hop_size=100, max_sil_kept=50)  # ValueError\n\n# after\nhop = 100\nslicer = Slicer(32000, hop_size=hop, max_sil_kept=max(hop, 50))  # or a sane 5*hop","handlingStrategy":"validation","validationCode":"max_sil_kept = max(max_sil_kept, hop_size)\nslicer = Slicer(sr, hop_size=hop_size, max_sil_kept=max_sil_kept, ...)","typeGuard":"def valid_slicer_silence(max_sil_kept: int, hop_size: int) -> bool:\n    return max_sil_kept >= hop_size","tryCatchPattern":null,"preventionTips":["Never set the silence-retention cap below the analysis hop.","If shrinking retained silence, shrink hop_size too.","Validate both slicer invariants together in one config check."],"tags":["audio-slicing","parameter-validation","config","preprocessing"],"backgroundTag":null,"analyzedSha":"d523079fc05d9a8028d6085bffe4a2757c32abb6","analyzedAt":"2026-08-15T01:06:46.402Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}