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)