huggingface/transformers · error · ValueError

Unknown window function '{name}'

Error message

Unknown window function '{name}'

What it means

Thrown by `window_function` when `name` is not one of the supported window types: "boxcar", "hamming" (or "hamming_window"), "hann" (or "hann_window"), or "povey". The function builds the window with the matching numpy routine; an unknown name has no implementation and the explicit raise prevents falling through to an undefined window.

Source

Thrown at src/transformers/audio_utils.py:789

            than the frame length, so that it will be zero-padded.
        center (`bool`, *optional*, defaults to `True`):
            Whether to center the window inside the FFT buffer. Only used when `frame_length` is provided.

    Returns:
        `np.ndarray` of shape `(window_length,)` or `(frame_length,)` containing the window.
    """
    length = window_length + 1 if periodic else window_length

    if name == "boxcar":
        window = np.ones(length)
    elif name in ["hamming", "hamming_window"]:
        window = np.hamming(length)
    elif name in ["hann", "hann_window"]:
        window = np.hanning(length)
    elif name == "povey":
        window = np.power(np.hanning(length), 0.85)
    else:
        raise ValueError(f"Unknown window function '{name}'")

    if periodic:
        window = window[:-1]

    if frame_length is None:
        return window

    if window_length > frame_length:
        raise ValueError(
            f"Length of the window ({window_length}) may not be larger than frame_length ({frame_length})"
        )

    padded_window = np.zeros(frame_length)
    offset = (frame_length - window_length) // 2 if center else 0
    padded_window[offset : offset + window_length] = window
    return padded_window

View on GitHub (pinned to a597f97485)

Solutions

  1. Use one of: "boxcar", "hamming", "hamming_window", "hann", "hann_window", "povey"
  2. If you need another window (e.g. blackman), compute it directly with numpy (np.blackman) and pass the array as `window` to `spectrogram`
  3. Check the feature extractor config that supplies the window name for typos/casing

Example fix

// before
window = window_function(400, name="blackman")  # ValueError

// after
window = np.blackman(400)  # pass array directly to spectrogram()
# or use a supported name:
window = window_function(400, name="hann")
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED_WINDOWS = {"boxcar", "hamming", "hamming_window", "hann", "hann_window", "povey"}
if name not in SUPPORTED_WINDOWS:
    raise ValueError(f"Unsupported window {name!r}; supported: {sorted(SUPPORTED_WINDOWS)}")
window = window_function(400, name=name)

Type guard

def is_supported_window(name: str) -> bool:
    return isinstance(name, str) and name in {"boxcar", "hamming", "hamming_window", "hann", "hann_window", "povey"}

Try / catch

try:
    window = window_function(length, name=name)
except ValueError as e:
    if "Unknown window function" in str(e):
        import numpy as np
        window = getattr(np, name, None)  # fallback: numpy window directly
        if window is None:
            raise
    else:
        raise

Prevention

When it happens

Trigger: Calling `window_function(length, name=...)` with values like "blackman", "kaldi" (not a window name), "Hann" (capitalized), or a torchaudio/torch window enum. Also hit indirectly when a feature extractor passes a window name from its config, e.g. Whisper-style "hann" works but Kaldi-VAD or custom names fail.

Common situations: Porting Kaldi/torchaudio recipes that use windows transformers does not implement (e.g. "blackman"); config files with capitalized or suffixed names like "hann_window" (the latter is accepted) vs "hann_povey" (not); typos.

Related errors


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/01d135a2ba696a2e. Report an issue: GitHub.