huggingface/transformers · error · ValueError
norm must be one of None or "slaney"
Error message
norm must be one of None or "slaney"
What it means
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.
Source
Thrown at src/transformers/audio_utils.py:692
Lowest frequency of interest in Hz.
max_frequency (`float`):
Highest frequency of interest in Hz. This should not exceed `sampling_rate / 2`.
sampling_rate (`int`):
Sample rate of the audio waveform.
norm (`str`, *optional*):
If `"slaney"`, divide the triangular mel weights by the width of the mel band (area normalization).
mel_scale (`str`, *optional*, defaults to `"htk"`):
The mel frequency scale to use, `"htk"`, `"kaldi"` or `"slaney"`.
triangularize_in_mel_space (`bool`, *optional*, defaults to `False`):
If this option is enabled, the triangular filter is applied in mel space rather than frequency space. This
should be set to `true` in order to get the same results as `torchaudio` when computing mel filters.
Returns:
`np.ndarray` of shape (`num_frequency_bins`, `num_mel_filters`): Triangular filter bank matrix. This is a
projection matrix to go from a spectrogram to a mel spectrogram.
"""
if norm is not None and norm != "slaney":
raise ValueError('norm must be one of None or "slaney"')
if num_frequency_bins < 2:
raise ValueError(f"Require num_frequency_bins: {num_frequency_bins} >= 2")
if min_frequency > max_frequency:
raise ValueError(f"Require min_frequency: {min_frequency} <= max_frequency: {max_frequency}")
# center points of the triangular mel filters
mel_min = hertz_to_mel(min_frequency, mel_scale=mel_scale)
mel_max = hertz_to_mel(max_frequency, mel_scale=mel_scale)
mel_freqs = np.linspace(mel_min, mel_max, num_mel_filters + 2)
filter_freqs = mel_to_hertz(mel_freqs, mel_scale=mel_scale)
if triangularize_in_mel_space:
# frequencies of FFT bins in Hz, but filters triangularized in mel space
fft_bin_width = sampling_rate / ((num_frequency_bins - 1) * 2)
fft_freqs = hertz_to_mel(fft_bin_width * np.arange(num_frequency_bins), mel_scale=mel_scale)
filter_freqs = mel_freqsView on GitHub (pinned to a597f97485)
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
Example fix
// before mel_filters = mel_filter_bank(num_frequency_bins=257, num_mel_filters=80, sampling_rate=16000, norm=1) # ValueError // after mel_filters = mel_filter_bank(num_frequency_bins=257, num_mel_filters=80, sampling_rate=16000, norm="slaney")
Defensive patterns
Strategy: validation
Validate before calling
if norm not in (None, "slaney"):
raise ValueError(f"norm must be None or 'slaney', got {norm!r}")
mel = mel_filter_bank(num_frequency_bins=257, num_mel_filters=80, sampling_rate=16000, norm=norm) Type guard
def is_valid_mel_norm(n) -> bool:
return n is None or n == "slaney" Try / catch
try:
mel = mel_filter_bank(..., norm=norm)
except ValueError as e:
if 'norm must be one of' in str(e):
norm = None # or "slaney" depending on desired behavior
mel = mel_filter_bank(..., norm=norm)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- mel_scale should be one of "htk", "slaney" or "kaldi".
- Require num_frequency_bins: {num_frequency_bins} >= 2
- Require min_frequency: {min_frequency} <= max_frequency: {ma
- You have provided `mel_filters` but `power` is `None`. Mel s
- Cannot use log_mel option '{log_mel}' with power {power}
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/49b584b4e2a76f5e.
Report an issue: GitHub.