# Having trouble importing speechbrain.inference

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhaving-trouble-importing-speechbrain-inference%2F172402%3E%5C
**Category:** Beginners\
**Created:** [January 12, 2026, 6:18pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhaving-trouble-importing-speechbrain-inference%2F172402 "2026-01-12T18:18:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [January 12, 2026, 8:38pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhaving-trouble-importing-speechbrain-inference%2F172402%2F2 "2026-01-12T20:38:21Z")

</div>

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](https://speechbrain.readthedocs.io/en/v1.0.3/_modules/speechbrain/utils/torch_audio_backend.html "Source code for speechbrain.utils.torch\_audio\_backend"))
- TorchAudio **deprecated** `list_audio_backends()` in 2.8 and says it **will be removed in 2.9**. ([PyTorch Docs](https://docs.pytorch.org/audio/2.8/generated/torchaudio.list_audio_backends.html "torchaudio.list\_audio\_backends"))
- 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](https://speechbrain.readthedocs.io/en/latest/_modules/speechbrain/utils/torch_audio_backend.html "Source code for speechbrain.utils.torch\_audio\_backend"))

### 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](https://github.com/fishaudio/fish-speech/issues/1118 "Crash on startup: AttributeError: torchaudio. ..."))  
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](https://pypi.org/project/speechbrain/ "speechbrain"))

* * *

## First: confirm your installed versions (30 seconds)

Run this in the Space terminal or logs:

```bash
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](https://docs.pytorch.org/audio/2.8/generated/torchaudio.list_audio_backends.html "torchaudio.list\_audio\_backends"))

* * *

## 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](https://docs.pytorch.org/audio/stable/installation.html "Installing pre-built binaries — Torchaudio 2.9.0 ..."))

**requirements.txt (example)**

```txt
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](https://docs.pytorch.org/audio/2.8/generated/torchaudio.list_audio_backends.html "torchaudio.list\_audio\_backends"))

* * *

## Fix 2 (future-facing): keep TorchAudio 2.9+ and use newer SpeechBrain code

SpeechBrain “latest” has a defensive check:

- if `torchaudio.list_audio_backends` exists, call it
- else (TorchAudio 2.9+), skip backend check and proceed ([SpeechBrain](https://speechbrain.readthedocs.io/en/latest/_modules/speechbrain/utils/torch_audio_backend.html "Source code for speechbrain.utils.torch\_audio\_backend"))

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**

```txt
git+https://github.com/speechbrain/speechbrain.git

```

If you do this, still keep Torch and TorchAudio matched (same major.minor). ([PyTorch Docs](https://docs.pytorch.org/audio/stable/installation.html "Installing pre-built binaries — Torchaudio 2.9.0 ..."))

* * *

## Minor note: import path

The canonical class lives at `speechbrain.inference.speaker.SpeakerRecognition`. ([SpeechBrain](https://speechbrain.readthedocs.io/en/latest/API/speechbrain.inference.speaker.html "speechbrain.inference.speaker module - Read the Docs"))  
So after your dependency issue is fixed, prefer:

```python
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](https://speechbrain.readthedocs.io/en/latest/API/speechbrain.inference.speaker.html "speechbrain.inference.speaker module - Read the Docs"))

* * *

## 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](https://huggingface.co/docs/hub/en/spaces-dependencies "Handling Spaces Dependencies in Gradio Spaces"))  
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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-force-rebuild-a-huggingface-space%2F18419 "Can I force rebuild a huggingface space?"))

### 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](https://speechbrain.readthedocs.io/en/stable/audioloading.html "Audio loading troubleshooting - SpeechBrain - Read the Docs"))  
If you need system FFmpeg in a Space, you can add it with `packages.txt` (documented by HF). ([Hugging Face](https://huggingface.co/docs/hub/en/spaces-dependencies "Handling Spaces Dependencies in Gradio Spaces"))

* * *

## What I would do for “first app, get it working”

1. Pin stable versions (Fix 1) because it is simplest and reproducible.
2. Confirm `torch` and `torchaudio` are the same release line. ([PyTorch Docs](https://docs.pytorch.org/audio/stable/installation.html "Installing pre-built binaries — Torchaudio 2.9.0 ..."))
3. Factory reboot the Space after editing `requirements.txt`. ([Hugging Face Forums](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-force-rebuild-a-huggingface-space%2F18419 "Can I force rebuild a huggingface space?"))

If you specifically want the newest TorchAudio stack, do Fix 2 and install SpeechBrain from GitHub so you get the 2.9+ guard. ([SpeechBrain](https://speechbrain.readthedocs.io/en/latest/_modules/speechbrain/utils/torch_audio_backend.html "Source code for speechbrain.utils.torch\_audio\_backend"))

* * *

### Summary

- Root cause: TorchAudio 2.9 removed `list_audio_backends()`. SpeechBrain 1.0.3 still calls it at import. ([PyTorch Docs](https://docs.pytorch.org/audio/2.8/generated/torchaudio.list_audio_backends.html "torchaudio.list\_audio\_backends"))
- Fix A: pin `torch==2.8.0` + `torchaudio==2.8.0` + `speechbrain==1.0.3`. Keep torch and torchaudio matched. ([PyTorch Docs](https://docs.pytorch.org/audio/stable/installation.html "Installing pre-built binaries — Torchaudio 2.9.0 ..."))
- Fix B: keep TorchAudio 2.9+ and install newer SpeechBrain code that guards the call. ([SpeechBrain](https://speechbrain.readthedocs.io/en/latest/_modules/speechbrain/utils/torch_audio_backend.html "Source code for speechbrain.utils.torch\_audio\_backend"))
- On Spaces: use Factory reboot if pins do not apply due to caching. ([Hugging Face Forums](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcan-i-force-rebuild-a-huggingface-space%2F18419 "Can I force rebuild a huggingface space?"))

---

_[View the full topic](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhaving-trouble-importing-speechbrain-inference%2F172402)._
