Hi,
I'm trying my first app on Hugging Face. I'm having an issue importing speechbrain.inference. It seems there's a compatibility problem with torchaudio - see traceback below.
Has anyone else seen this, and do you know of a fix?
Thanks,
Rob.
Traceback (most recent call last):
File "/app/app.py", line 2, in <module>
from speechbrain.inference import SpeakerRecognition
File "/usr/local/lib/python3.10/site-packages/speechbrain/__init__.py", line 6, in <module>
from .core import Brain, Stage, create_experiment_directory, parse_arguments
File "/usr/local/lib/python3.10/site-packages/speechbrain/core.py", line 39, in <module>
from speechbrain.dataio.dataloader import LoopedLoader, SaveableDataLoader
File "/usr/local/lib/python3.10/site-packages/speechbrain/dataio/dataloader.py", line 46, in <module>
from speechbrain.dataio.dataset import DynamicItemDataset
File "/usr/local/lib/python3.10/site-packages/speechbrain/dataio/dataset.py", line 15, in <module>
from speechbrain.dataio.dataio import load_data_csv, load_data_json
File "/usr/local/lib/python3.10/site-packages/speechbrain/dataio/dataio.py", line 36, in <module>
check_torchaudio_backend()
File "/usr/local/lib/python3.10/site-packages/speechbrain/utils/torch_audio_backend.py", line 57, in check_torchaudio_backend
available_backends = torchaudio.list_audio_backends()
AttributeError: module 'torchaudio' has no attribute 'list_audio_backends'
oh…
You are hitting a clean breaking-change boundary: SpeechBrain is calling a TorchAudio function that no longer exists in newer TorchAudio.
What is happening
- SpeechBrain runs
check_torchaudio_backend()during import. - Older SpeechBrain code calls
torchaudio.list_audio_backends()unconditionally. That matches your traceback. (SpeechBrain) - TorchAudio deprecated
list_audio_backends()in 2.8 and says it will be removed in 2.9. (PyTorch Docs) - So if your Space installed torchaudio 2.9+, importing SpeechBrain can crash exactly as you see.
This is not hypothetical. SpeechBrain’s latest docs show they updated the check to guard the call because “list_audio_backends() was removed in torchaudio 2.9+” and they skip backend checking when it is missing. (SpeechBrain)
Why it’s common on Hugging Face Spaces
Spaces rebuild environments often. If you do not pin versions, pip can pull a newer TorchAudio later and break older SpeechBrain. This class of “torchaudio 2.9 removed API” break is showing up in multiple repos. (GitHub)
Also, PyPI’s latest SpeechBrain release is 1.0.3 (Apr 7, 2025), so pip install speechbrain can still give you code that expects older TorchAudio behavior. (PyPI)
First: confirm your installed versions (30 seconds)
Run this in the Space terminal or logs:
python -c "import torch, torchaudio, speechbrain; print('torch', torch.__version__); print('torchaudio', torchaudio.__version__); print('speechbrain', speechbrain.__version__); print('has list_audio_backends', hasattr(torchaudio,'list_audio_backends'))"
If has list_audio_backends is False, you are on the “TorchAudio removed it” side of the line. (PyTorch Docs)
Fix 1 (most stable): pin TorchAudio to <2.9 and match Torch exactly
If you want to keep using SpeechBrain 1.0.3 from PyPI, pin TorchAudio to a version where the function still exists (2.8.x), and pin Torch to the matching release.
Why match: TorchAudio binaries are compiled against a specific PyTorch release. TorchAudio’s install docs say TorchAudio and PyTorch from different releases cannot be used together. (PyTorch Docs)
requirements.txt (example)
torch==2.8.0
torchaudio==2.8.0
speechbrain==1.0.3
This works because list_audio_backends() still exists in TorchAudio 2.8 (deprecated but present). (PyTorch Docs)
Fix 2 (future-facing): keep TorchAudio 2.9+ and use newer SpeechBrain code
SpeechBrain “latest” has a defensive check:
- if
torchaudio.list_audio_backendsexists, call it - else (TorchAudio 2.9+), skip backend check and proceed (SpeechBrain)
So the fix is to install a SpeechBrain revision that includes that guarded logic.
On Spaces this often means installing from the GitHub repo instead of PyPI:
requirements.txt
git+https://github.com/speechbrain/speechbrain.git
If you do this, still keep Torch and TorchAudio matched (same major.minor). (PyTorch Docs)
Minor note: import path
The canonical class lives at speechbrain.inference.speaker.SpeakerRecognition. (SpeechBrain)
So after your dependency issue is fixed, prefer:
from speechbrain.inference.speaker import SpeakerRecognition
This does not fix your error by itself, because your crash happens earlier during SpeechBrain import, but it is the documented path. (SpeechBrain)
Hugging Face Spaces gotchas that matter
1) Make sure Spaces actually rebuilds with your new pins
HF’s docs explain requirements.txt and system deps via packages.txt. (Hugging Face)
If you change pins and it still behaves the same, do a Factory reboot. HF staff note this rebuilds “without using cached requirements.” (Hugging Face Forums)
2) Next likely pitfall: audio decoding dependencies
Once import works, audio I/O can still fail due to missing codecs/backends. SpeechBrain keeps a troubleshooting page for this. (SpeechBrain)
If you need system FFmpeg in a Space, you can add it with packages.txt (documented by HF). (Hugging Face)
What I would do for “first app, get it working”
- Pin stable versions (Fix 1) because it is simplest and reproducible.
- Confirm
torchandtorchaudioare the same release line. (PyTorch Docs) - Factory reboot the Space after editing
requirements.txt. (Hugging Face Forums)
If you specifically want the newest TorchAudio stack, do Fix 2 and install SpeechBrain from GitHub so you get the 2.9+ guard. (SpeechBrain)
Summary
- Root cause: TorchAudio 2.9 removed
list_audio_backends(). SpeechBrain 1.0.3 still calls it at import. (PyTorch Docs) - Fix A: pin
torch==2.8.0+torchaudio==2.8.0+speechbrain==1.0.3. Keep torch and torchaudio matched. (PyTorch Docs) - Fix B: keep TorchAudio 2.9+ and install newer SpeechBrain code that guards the call. (SpeechBrain)
- On Spaces: use Factory reboot if pins do not apply due to caching. (Hugging Face Forums)
Thanks for your reply.
I have made the changes to requirements.txt to specify the versions for torch, torchaudio and speechbrain.
I am now getting a different error, it seems there is an incompatibility with hf_hub_download:
Exit code: 1. Reason: /usr/local/lib/python3.13/site-packages/speechbrain/utils/torch_audio_backend.py:57: UserWarning: torchaudio._backend.list_audio_backends has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see Update on TorchAudio’s future · Issue #3902 · pytorch/audio · GitHub for more information. It will be removed from the 2.9 release. available_backends = torchaudio.list_audio_backends() Traceback (most recent call last): File “/app/app.py”, line 5, in verification = SpeakerRecognition.from_hparams( source=“speechbrain/spkrec-ecapa-voxceleb”, run_opts={“device”: “cpu”} # Change to “cuda” if GPU is available ) File “/usr/local/lib/python3.13/site-packages/speechbrain/inference/interfaces.py”, line 477, in from_hparams hparams_local_path = fetch( filename=hparams_file, …<7 lines>… local_strategy=local_strategy, ) File “/usr/local/lib/python3.13/site-packages/speechbrain/utils/fetching.py”, line 387, in fetch fetched_file = huggingface_hub.hf_hub_download( **kwargs, cache_dir=huggingface_cache_dir, ) File “/usr/local/lib/python3.13/site-packages/huggingface_hub/utils/_validators.py”, line 89, in _inner_fn return fn(*args, **kwargs) TypeError: hf_hub_download() got an unexpected keyword argument ‘use_auth_token’
Regards,
Rob.
Library version mismatches often remain unresolved, so in such cases, pin the version of any library that doesn’t need to be the latest for your specific use to an older, stable one…
You are seeing two separate “API moved/removed” breakages caused by upstream version drift:
- TorchAudio refactor (2.8 → 2.9) affects
torchaudio.list_audio_backends(). - huggingface_hub v1.0 removed the
use_auth_tokenkeyword (and a few other keywords) that SpeechBrain still passes intohf_hub_download().
Both are common in Hugging Face Spaces because a rebuild can silently pick up newer dependency versions unless you pin them.
1) Why your new error happens: hf_hub_download(..., use_auth_token=...) crashes
What the traceback means
SpeechBrain calls:
SpeakerRecognition.from_hparams(...)- which calls
speechbrain.utils.fetching.fetch(...) - which calls
huggingface_hub.hf_hub_download(...)
SpeechBrain currently builds kwargs including "use_auth_token": use_auth_token and passes them to hf_hub_download. (speechbrain.readthedocs.io)
But in huggingface_hub v1.0, Hugging Face explicitly removed:
use_auth_token(replaced bytoken)- and also removed
resume_download,force_filename,local_dir_use_symlinksfromhf_hub_download(Hugging Face)
So if your Space has huggingface_hub>=1.0, SpeechBrain’s call pattern can fail immediately with:
TypeError: hf_hub_download() got an unexpected keyword argument 'use_auth_token'
That is exactly your error.
Why you got it “even though you are not using a private model”
Even when the model is public, SpeechBrain still passes the keyword argument (use_auth_token=False). The function signature mismatch is enough to crash.
2) The most reliable fix: pin huggingface_hub to v0.x
If you want SpeechBrain “as-is” with minimal patching, add a hub pin:
huggingface_hub<1.0
Reason: use_auth_token is removed in hub v1.0, so staying on v0.x preserves compatibility. (Hugging Face)
Practical requirements.txt pattern (example)
Keep your existing pins for torch/torchaudio/speechbrain, then add:
huggingface_hub<1.0
After rebuild, confirm versions at runtime:
import huggingface_hub, speechbrain
print("huggingface_hub", huggingface_hub.__version__)
print("speechbrain", speechbrain.__version__)
One more important detail
SpeechBrain also sometimes passes force_filename and local_dir_use_symlinks to hf_hub_download in one code path. Those are also removed in hub v1.0. (Hugging Face)
That is another reason pinning hub <1.0 is the cleanest fix.
3) Alternative fixes if you cannot downgrade huggingface_hub
Sometimes other dependencies force hub v1.x. If that is your situation, you have three workarounds.
A) Patch SpeechBrain locally (rename the argument)
In SpeechBrain’s fetching.py, the intent is “use my HF token if needed.” In hub v1.0 that parameter is now named token. (Hugging Face)
Minimal conceptual change:
use_auth_token→token
Caveat:
- If you hit the code path that uses
force_filename/local_dir_use_symlinks, you must adjust those too because hub v1.0 removed them. (Hugging Face)
B) Install a SpeechBrain revision that already supports hub v1.x
If/when SpeechBrain releases a version updated for hub v1.0, upgrading SpeechBrain instead of downgrading hub is ideal.
Right now, the SpeechBrain docs/source still show use_auth_token being passed to hf_hub_download. (speechbrain.readthedocs.io)
So you need to verify in the specific SpeechBrain version you install.
C) Monkeypatch hf_hub_download at startup (quick and dirty)
You can wrap the function to translate use_auth_token → token and drop removed kwargs.
This is brittle, but it can unblock a demo quickly.
4) Your earlier TorchAudio problem: why it happened and why it is now “only a warning”
What happened originally
You initially got:
AttributeError: module 'torchaudio' has no attribute 'list_audio_backends'
TorchAudio deprecated torchaudio.list_audio_backends() in 2.8 and removed deprecated APIs in 2.9. (PyTorch Documentation)
So if your environment had TorchAudio 2.9+, code calling list_audio_backends() can break (projects are actively hitting this). (GitHub)
Why you now see a deprecation warning instead
Your new warning says the function exists but is deprecated and will be removed (that is the 2.8 behavior). (PyTorch Documentation)
So your torch/torchaudio pin likely moved you back to 2.8.x, which is consistent with “works but warns.”
5) Hugging Face Spaces specifics that matter in your case
Python version in Spaces can change dependency behavior
Spaces let you set python_version: in the README YAML and it defaults to 3.10. (Hugging Face)
Your traceback shows Python 3.13 paths. That is valid, but it increases the chance you end up on the newest major releases of everything.
If you want fewer surprises:
- set
python_version: "3.10"(or 3.11) in README YAML (Hugging Face) - and pin the ML stack tightly
Dependency pinning is normal on Spaces
Spaces install from requirements.txt, so pins are the standard way to keep rebuilds stable. (Hugging Face)
6) Similar cases people hit (so you know this is not “just you”)
- Other projects hit the same
use_auth_tokenkeyword crash when hub removes it (example issue in Hugging Face ecosystem). (GitHub) - People explicitly fix it by downgrading
huggingface_hub<1.0because v1.0 is where the breaking change lands. (Zenn) - Multiple repos hit TorchAudio breakage when deprecated APIs disappear in 2.9. (GitHub)
7) Recommended path for your exact situation
Given your tracebacks, the shortest stable route is:
-
Keep Torch/TorchAudio pinned to a compatible pair (your current state looks like TorchAudio 2.8.x, which avoids the hard error). (PyTorch Documentation)
-
Add one more pin to stop SpeechBrain vs Hub fighting:
huggingface_hub<1.0(Hugging Face)
-
Rebuild the Space.
-
Print versions on startup to confirm the environment is what you think it is.
If you later want to move to hub v1.x, do it deliberately by upgrading SpeechBrain to a version that has removed use_auth_token internally (verify in release notes or source), because hub v1.0 breaking changes are explicit and non-trivial. (Hugging Face)
High-quality references to keep handy
- Hugging Face Hub v1.0 migration guide (lists removal of
use_auth_tokenand removedhf_hub_downloadparameters). (Hugging Face) - SpeechBrain
fetch()implementation showing it passesuse_auth_tokenintohf_hub_download. (speechbrain.readthedocs.io) - TorchAudio docs for
list_audio_backends()deprecation and removal timeline. (PyTorch Documentation) - Spaces config reference for
python_versiondefault and how to set it. (Hugging Face)
Summary
- Your current crash is SpeechBrain passing
use_auth_tokentohf_hub_download, but huggingface_hub v1.0 removed that parameter. (Hugging Face) - Fastest fix: pin
huggingface_hub<1.0. (Hugging Face) - Your earlier TorchAudio issue is the same category: 2.9 removed APIs deprecated in 2.8. (PyTorch Documentation)
- On Spaces, also consider setting
python_version: "3.10"to reduce churn. (Hugging Face)