huggingface/transformers · error · TypeError

only a single or a list of entries is supported but got type

Error message

only a single or a list of entries is supported but got type={type(audio_url_or_urls)}

What it means

fetch_audio accepts a single URL string, a list of URLs, or already-valid raw audio (ndarray/list-of-float per is_valid_audio). Anything else — an int, dict, None, bytes — has no defined fetch behavior and raises TypeError with the offending type.

Source

Thrown at src/transformers/feature_extraction_sequence_utils.py:387

        return padding_strategy

    def fetch_audio(self, audio_url_or_urls: str | list[str] | list[list[str]], sampling_rate: int | None = None):
        """
        Convert a single or a list of urls into the corresponding `np.ndarray` objects.

        If a single url is passed, the return value will be a single object. If a list is passed a list of objects is
        returned.
        """
        # Accepted input types for `raw_audio`: "np.ndarray | list[float] | list[np.ndarray] | list[list[float]]"
        sampling_rate = sampling_rate if sampling_rate else self.sampling_rate
        if isinstance(audio_url_or_urls, list) and not isinstance(audio_url_or_urls[0], float):
            return [self.fetch_audio(x, sampling_rate=sampling_rate) for x in audio_url_or_urls]
        elif isinstance(audio_url_or_urls, str):
            return load_audio(audio_url_or_urls, sampling_rate=sampling_rate)
        elif is_valid_audio(audio_url_or_urls):
            return audio_url_or_urls
        else:
            raise TypeError(f"only a single or a list of entries is supported but got type={type(audio_url_or_urls)}")

View on GitHub (pinned to a597f97485)

Solutions

  1. Convert Path to str: fetch_audio(str(path_or_url))
  2. Pass raw audio as np.ndarray (float) or list of floats instead of odd containers
  3. Filter None/invalid entries before calling fetch_audio

Example fix

# before
fe.fetch_audio(Path("/tmp/a.wav"))

# after
fe.fetch_audio(str(Path("/tmp/a.wav").resolve()))
Defensive patterns

Strategy: type-guard

Validate before calling

from pathlib import Path

def normalize_audio_arg(x):
    return str(x) if isinstance(x, Path) else x

Type guard

def is_fetchable_audio(x) -> bool:
    import numpy as np
    return isinstance(x, str) or (isinstance(x, list) and all(isinstance(i, str) for i in x)) or \
           isinstance(x, np.ndarray)

Try / catch

try:
    fe.fetch_audio(src)
except TypeError as e:
    if "only a single or a list" in str(e):
        raise TypeError(f"unsupported audio source {type(src)}; pass str URL or np.ndarray") from e
    raise

Prevention

When it happens

Trigger: Calling fetch_audio with e.g. an int index, a Path object, bytes, or a nested list of lists of floats in an unexpected shape; also lists whose first element is float are treated as raw audio and then fail validity for outer types.

Common situations: Passing Path objects instead of str URLs; data pipelines that sometimes hand over None; assuming local file paths or file-likes are supported when only URL strings and raw arrays are.

Related errors


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