No module named 'torchaudio.backend' (fix)

On torchaudio 2.9 and newer, from torchaudio.backend.common import AudioMetaData raises ModuleNotFoundError: No module named 'torchaudio.backend', and torchaudio.set_audio_backend / list_audio_backends raise AttributeError: module 'torchaudio' has no attribute .... We reproduced all three and tested two fixes.

1. The three errors on torchaudio 2.9

torch and torchaudio 2.9.0. The old import path:

from torchaudio.backend.common import AudioMetaData
Traceback (most recent call last):
  File "b2.py", line 1, in <module>
    from torchaudio.backend.common import AudioMetaData
ModuleNotFoundError: No module named 'torchaudio.backend'

The old backend switch:

import torchaudio
print("torchaudio", torchaudio.__version__)
torchaudio.set_audio_backend("soundfile")
Traceback (most recent call last):
  File "b1.py", line 3, in <module>
    torchaudio.set_audio_backend("soundfile")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'torchaudio' has no attribute 'set_audio_backend'

And listing backends:

import torchaudio
print(torchaudio.list_audio_backends())
Traceback (most recent call last):
  File "b3.py", line 2, in <module>
    print(torchaudio.list_audio_backends())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'torchaudio' has no attribute 'list_audio_backends'

On torchaudio 2.8.0 all three still run, with deprecation warnings (the AudioMetaData one says it moved to torchaudio.AudioMetaData, which 2.9 also removed). list_audio_backends() printed ['soundfile'] there.

2. Why: torchaudio 2.9 has no backends any more

torchaudio.load still accepts backend=, but in 2.9 it always decodes through TorchCodec. Without FFmpeg, asking for soundfile does not help:

import torchaudio
waveform, sr = torchaudio.load("tone.wav", backend="soundfile")
print(waveform.shape, sr)
Traceback (most recent call last):
  ...
RuntimeError: Could not load libtorchcodec. Likely causes:
          1. FFmpeg is not properly installed in your environment. We support
  ...

With FFmpeg libraries available, the same call works and warns that the argument is unused:

.../site-packages/torchaudio/__init__.py:86: UserWarning: The 'backend' parameter is not used by TorchCodec AudioDecoder.
  return load_with_torchcodec(
torch.Size([1, 16000]) 16000

3. Fix: drop the backend calls (guarded)

If your code only called set_audio_backend to pick a decoder, guard it so the same file runs on old and new torchaudio:

import torchaudio
print("torchaudio", torchaudio.__version__)
if hasattr(torchaudio, "set_audio_backend"):     # gone in 2.9; load ignores backends there
    torchaudio.set_audio_backend("soundfile")
waveform, sr = torchaudio.load("tone.wav")
print(waveform.shape, sr)

torchaudio 2.8.0 (long warning lines shortened):

torchaudio 2.8.0+cu128
b6.py:4: UserWarning: torchaudio._backend.set_audio_backend has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAu...
  torchaudio.set_audio_backend("soundfile")
.../site-packages/torchaudio/_internal/module_utils.py:71: UserWarning: torchaudio._backend.set_audio_backend has been deprecated. With dispatcher enabled, t...
  return func(*args, **kwargs)
.../site-packages/torchaudio/_backend/utils.py:213: UserWarning: In 2.9, this function's implementation will be changed to use torchaudio.load_with_torchcode...
  warnings.warn(
torch.Size([1, 16000]) 16000

torchaudio 2.9.0 with FFmpeg 7 shared libraries on the loader path:

torchaudio 2.9.0+cpu
torch.Size([1, 16000]) 16000

On 2.9 load needs TorchCodec plus FFmpeg 4–8; see Could not load libtorchcodec if that fails. For torchaudio.backend.common.AudioMetaData / torchaudio.info, use soundfile.info (tested here).

4. Fix: pin torch and torchaudio 2.8.0

When the import is inside a library you can't edit (older speech/diarization packages):

pip install "torch==2.8.0" "torchaudio==2.8.0"

Install them together; torch and torchaudio versions must match. All three snippets above ran on that pair.

Related: torchaudio has no attribute AudioMetaData · torchaudio has no attribute info · torchaudio sox_effects: libsox.so not found · No module named torchaudio.kaldi_io

Frequently asked questions

Which torchaudio version removed torchaudio.backend?

In our test torchaudio.backend, set_audio_backend and list_audio_backends exist on 2.8.0 (with deprecation warnings) and are gone on 2.9.0.

Does torchaudio.load(backend="soundfile") still use soundfile?

No. On 2.9.0 it decoded through TorchCodec and warned that the backend parameter is not used; without FFmpeg it failed with Could not load libtorchcodec.

Written with AI assistance. Measured on 2026-10-24 on Linux with CPython 3.11.17, torch/torchaudio 2.8.0 (PyPI wheels) and 2.9.0 (CPU wheels), torchcodec 0.9.1, conda-forge FFmpeg 7. Output pasted unedited except shortened site-packages paths, cut tracebacks and trimmed warning lines. PlainTables is our extension; torchaudio is free.