speechbrain.utils.fetching module

Downloads or otherwise fetches pretrained models

  • Aku Rouhe 2021

  • Samuele Cornell 2021

  • Andreas Nautsch 2022, 2023




Designator where to fetch models/audios from.


NamedTuple describing a source path and how to fetch it



Ensures you have a local copy of the file, returns its path


class speechbrain.utils.fetching.FetchFrom(value)[source]

Bases: Enum

Designator where to fetch models/audios from.

Note: HuggingFace repository sources and local folder sources may be confused if their source type is undefined.

URI = 3
class speechbrain.utils.fetching.FetchSource(FetchFrom, path)

Bases: tuple

NamedTuple describing a source path and how to fetch it


Alias for field number 0

encode(*args, **kwargs)

Alias for field number 1

speechbrain.utils.fetching.fetch(filename, source, savedir='./pretrained_model_checkpoints', overwrite=False, save_filename=None, use_auth_token=False, revision=None, huggingface_cache_dir=None)[source]

Ensures you have a local copy of the file, returns its path

In case the source is an external location, downloads the file. In case the source is already accessible on the filesystem, creates a symlink in the savedir. Thus, the side effects of this function always look similar: savedir/save_filename can be used to access the file. And save_filename defaults to the filename arg.

  • filename (str) – Name of the file including extensions.

  • source (str or FetchSource) – Where to look for the file. This is interpreted in special ways: First, if the source begins with “http://” or “https://”, it is interpreted as a web address and the file is downloaded. Second, if the source is a valid directory path, a symlink is created to the file. Otherwise, the source is interpreted as a Huggingface model hub ID, and the file is downloaded from there.

  • savedir (str) – Path where to save downloads/symlinks.

  • overwrite (bool) – If True, always overwrite existing savedir/filename file and download or recreate the link. If False (as by default), if savedir/filename exists, assume it is correct and don’t download/relink. Note that Huggingface local cache is always used - with overwrite=True we just relink from the local cache.

  • save_filename (str) – The filename to use for saving this file. Defaults to filename if not given.

  • use_auth_token (bool (default: False)) – If true Hugginface’s auth_token will be used to load private models from the HuggingFace Hub, default is False because majority of models are public.

  • revision (str) – The model revision corresponding to the HuggingFace Hub model revision. This is particularly useful if you wish to pin your code to a particular version of a model hosted at HuggingFace.

  • huggingface_cache_dir (str) – Path to HuggingFace cache; if None -> “~/.cache/huggingface” (default: None)


Path to file on local file system.

Return type:



ValueError – If file is not found