{"record":{"id":"1d5b666cec79fc83","repo":"huggingface/transformers","slug":"length-of-the-window-window-length-may-not-be","errorCode":null,"errorMessage":"Length of the window ({window_length}) may not be larger than frame_length ({frame_length})","messagePattern":"Length of the window \\((.+?)\\) may not be larger than frame_length \\((.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/audio_utils.py","lineNumber":798,"sourceCode":"    if name == \"boxcar\":\n        window = np.ones(length)\n    elif name in [\"hamming\", \"hamming_window\"]:\n        window = np.hamming(length)\n    elif name in [\"hann\", \"hann_window\"]:\n        window = np.hanning(length)\n    elif name == \"povey\":\n        window = np.power(np.hanning(length), 0.85)\n    else:\n        raise ValueError(f\"Unknown window function '{name}'\")\n\n    if periodic:\n        window = window[:-1]\n\n    if frame_length is None:\n        return window\n\n    if window_length > frame_length:\n        raise ValueError(\n            f\"Length of the window ({window_length}) may not be larger than frame_length ({frame_length})\"\n        )\n\n    padded_window = np.zeros(frame_length)\n    offset = (frame_length - window_length) // 2 if center else 0\n    padded_window[offset : offset + window_length] = window\n    return padded_window\n\n\n# Note: This method processes a single waveform. For batch processing, use spectrogram_batch().\ndef spectrogram(\n    waveform: np.ndarray,\n    window: np.ndarray,\n    frame_length: int,\n    hop_length: int,\n    fft_length: int | None = None,\n    power: float | None = 1.0,\n    center: bool = True,","sourceCodeStart":780,"sourceCodeEnd":816,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/audio_utils.py#L780-L816","documentation":"Thrown by `window_function` when `frame_length` is provided and `window_length > frame_length`. The function zero-pads the window into a frame_length-sized buffer; a window longer than the target frame cannot fit, so the combination is rejected. Without frame_length the window is returned unpadded.","triggerScenarios":"Calling `window_function(window_length=512, frame_length=400, ...)` or any call where the two lengths are inverted; typically triggered by feature extractors that request a window shorter than the frame but receive mismatched config values.","commonSituations":"Feature-extractor configs where n_fft/window size and frame length were edited independently; porting setups from other toolkits where window_length includes padding semantics differently; swapping the two positional arguments.","solutions":["Make window_length <= frame_length (usually window_length == frame_length for STFT)","If you need the window centered inside a larger FFT buffer, keep frame_length larger than window_length on purpose","Verify the config values feeding both parameters if the call comes from a processor"],"exampleFix":"// before\nwindow = window_function(window_length=512, frame_length=400)  # ValueError\n\n// after\nwindow = window_function(window_length=400, frame_length=512)  # centered, zero-padded","handlingStrategy":"validation","validationCode":"if frame_length is not None:\n    assert window_length <= frame_length, f\"window_length ({window_length}) must be <= frame_length ({frame_length})\"\nwindow = window_function(window_length, name=\"hann\", frame_length=frame_length)","typeGuard":"def window_fits_frame(window_length: int, frame_length) -> bool:\n    return frame_length is None or window_length <= frame_length","tryCatchPattern":"try:\n    window = window_function(window_length, frame_length=frame_length)\nexcept ValueError as e:\n    if \"may not be larger than frame_length\" in str(e):\n        window_length, frame_length = min(window_length, frame_length), max(window_length, frame_length)\n        window = window_function(window_length, frame_length=frame_length)\n    else:\n        raise","preventionTips":["Default to window_length == frame_length for STFT","Treat frame_length as the outer size: window is padded into it, never the reverse","Validate both lengths come from the same config source"],"tags":["audio","stft","argument-validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}