{"record":{"id":"49b584b4e2a76f5e","repo":"huggingface/transformers","slug":"norm-must-be-one-of-none-or-slaney","errorCode":null,"errorMessage":"norm must be one of None or \"slaney\"","messagePattern":"norm must be one of None or \"slaney\"","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/audio_utils.py","lineNumber":692,"sourceCode":"            Lowest frequency of interest in Hz.\n        max_frequency (`float`):\n            Highest frequency of interest in Hz. This should not exceed `sampling_rate / 2`.\n        sampling_rate (`int`):\n            Sample rate of the audio waveform.\n        norm (`str`, *optional*):\n            If `\"slaney\"`, divide the triangular mel weights by the width of the mel band (area normalization).\n        mel_scale (`str`, *optional*, defaults to `\"htk\"`):\n            The mel frequency scale to use, `\"htk\"`, `\"kaldi\"` or `\"slaney\"`.\n        triangularize_in_mel_space (`bool`, *optional*, defaults to `False`):\n            If this option is enabled, the triangular filter is applied in mel space rather than frequency space. This\n            should be set to `true` in order to get the same results as `torchaudio` when computing mel filters.\n\n    Returns:\n        `np.ndarray` of shape (`num_frequency_bins`, `num_mel_filters`): Triangular filter bank matrix. This is a\n        projection matrix to go from a spectrogram to a mel spectrogram.\n    \"\"\"\n    if norm is not None and norm != \"slaney\":\n        raise ValueError('norm must be one of None or \"slaney\"')\n\n    if num_frequency_bins < 2:\n        raise ValueError(f\"Require num_frequency_bins: {num_frequency_bins} >= 2\")\n\n    if min_frequency > max_frequency:\n        raise ValueError(f\"Require min_frequency: {min_frequency} <= max_frequency: {max_frequency}\")\n\n    # center points of the triangular mel filters\n    mel_min = hertz_to_mel(min_frequency, mel_scale=mel_scale)\n    mel_max = hertz_to_mel(max_frequency, mel_scale=mel_scale)\n    mel_freqs = np.linspace(mel_min, mel_max, num_mel_filters + 2)\n    filter_freqs = mel_to_hertz(mel_freqs, mel_scale=mel_scale)\n\n    if triangularize_in_mel_space:\n        # frequencies of FFT bins in Hz, but filters triangularized in mel space\n        fft_bin_width = sampling_rate / ((num_frequency_bins - 1) * 2)\n        fft_freqs = hertz_to_mel(fft_bin_width * np.arange(num_frequency_bins), mel_scale=mel_scale)\n        filter_freqs = mel_freqs","sourceCodeStart":674,"sourceCodeEnd":710,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/audio_utils.py#L674-L710","documentation":"Thrown by `mel_filter_bank` when the `norm` argument is neither None nor the string \"slaney\". Normalization controls whether triangular mel weights are divided by the mel-band width (Slaney-style area normalization); no other normalization scheme is implemented, so anything else is rejected before the filter bank matrix is built.","triggerScenarios":"Calling `mel_filter_bank(..., norm=...)` with values like \"none\", \"l2\", 1, True, or \"Slaney\" (wrong casing). Often reached indirectly through a feature extractor that computes mel filters with a norm setting read from a config.","commonSituations":"Porting code from librosa (which uses norm=1 or norm=\"slaney\") without translating the value; passing a boolean where None was intended; typos or casing in preprocessor configs.","solutions":["Set norm=None for no normalization or norm=\"slaney\" for area normalization","If translating librosa code, map librosa's norm=1 to \"slaney\" and norm=None to None","Check preprocessor_config.json / kwargs overrides for invalid norm values"],"exampleFix":"// before\nmel_filters = mel_filter_bank(num_frequency_bins=257, num_mel_filters=80, sampling_rate=16000, norm=1)  # ValueError\n\n// after\nmel_filters = mel_filter_bank(num_frequency_bins=257, num_mel_filters=80, sampling_rate=16000, norm=\"slaney\")","handlingStrategy":"validation","validationCode":"if norm not in (None, \"slaney\"):\n    raise ValueError(f\"norm must be None or 'slaney', got {norm!r}\")\nmel = mel_filter_bank(num_frequency_bins=257, num_mel_filters=80, sampling_rate=16000, norm=norm)","typeGuard":"def is_valid_mel_norm(n) -> bool:\n    return n is None or n == \"slaney\"","tryCatchPattern":"try:\n    mel = mel_filter_bank(..., norm=norm)\nexcept ValueError as e:\n    if 'norm must be one of' in str(e):\n        norm = None  # or \"slaney\" depending on desired behavior\n        mel = mel_filter_bank(..., norm=norm)\n    else:\n        raise","preventionTips":["When porting librosa code, map norm=1 to \"slaney\" and norm=None to None","Do not pass booleans or integers for norm","Keep normalization choice consistent with the pretrained model's config"],"tags":["audio","mel-spectrogram","argument-validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}