torchaudio sox_effects: libsox.so not found (fix)
torchaudio.sox_effects.apply_effects_tensor fails with OSError: libsox.so: cannot open shared object file on torchaudio 2.8 and older when SoX isn't installed, and with ModuleNotFoundError: No module named 'torchaudio.sox_effects' on 2.9, which removed it. We reproduced both and tested the fixes.
1. The two errors
The same augmentation snippet (speed up 10%, keep 16 kHz):
import torch, torchaudio
import torchaudio.sox_effects as sox_effects
sr = 16000
wav = torch.sin(2 * torch.pi * 440 * torch.arange(sr) / sr).unsqueeze(0)
out, out_sr = sox_effects.apply_effects_tensor(wav, sr, [["speed", "1.1"], ["rate", str(sr)]])
print(torchaudio.__version__, out.shape, out_sr)
torchaudio 2.8.0, no libsox on the system (deprecation warning cut):
Traceback (most recent call last):
File "b1.py", line 5, in <module>
out, out_sr = sox_effects.apply_effects_tensor(wav, sr, [["speed", "1.1"], ["rate", str(sr)]])
...
ctypes.CDLL(path)
File ".../ctypes/__init__.py", line 376, in __init__
self._handle = _dlopen(self._name, mode)
^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: libsox.so: cannot open shared object file: No such file or directory
torchaudio 2.9.0:
Traceback (most recent call last):
File "b1.py", line 2, in <module>
import torchaudio.sox_effects as sox_effects
ModuleNotFoundError: No module named 'torchaudio.sox_effects'
Code that uses torchaudio.sox_effects without importing it gets the attribute form on 2.9:
import torchaudio
print(torchaudio.__version__)
torchaudio.sox_effects.apply_effects_file("speech.wav", [["rate", "16000"]])
2.9.0+cpu
Traceback (most recent call last):
File "b3.py", line 3, in <module>
torchaudio.sox_effects.apply_effects_file("speech.wav", [["rate", "16000"]])
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'torchaudio' has no attribute 'sox_effects'
So on 2.8 and older the module exists but needs the system libsox.so at call time (the import itself succeeds); on 2.9 the module is gone. The 2.8 warning says so: "It will be removed from the 2.9 release."
2. Fix (any version): use torchaudio.functional
Most effect chains used for data augmentation have pure-PyTorch equivalents that need no libsox and exist on both 2.8 and 2.9:
import torch, torchaudio
import torchaudio.functional as F
sr = 16000
wav = torch.sin(2 * torch.pi * 440 * torch.arange(sr) / sr).unsqueeze(0)
# sox [["speed", "1.1"], ["rate", "16000"]]: 10% faster (pitch goes up too), still 16 kHz
fast, _ = F.speed(wav, sr, 1.1)
same = F.resample(wav, orig_freq=int(sr * 1.1), new_freq=sr)
print(torchaudio.__version__, fast.shape, torch.allclose(fast, same))
# other common sox effects: ["gain", "-3"], ["lowpass", "3000"]
quiet = F.gain(wav, -3.0)
low = F.lowpass_biquad(wav, sr, 3000.0)
print(quiet.abs().max().item() < wav.abs().max().item(), low.shape)
torchaudio 2.8.0:
2.8.0+cu128 torch.Size([1, 14546]) True
True torch.Size([1, 16000])
torchaudio 2.9.0:
2.9.0+cpu torch.Size([1, 14546]) True
True torch.Size([1, 16000])
F.speed matched resampling exactly here. sox itself returned 14545 samples for the same chain, one fewer than F.speed, so expect tiny length differences, not identical output.
3. Fix (torchaudio 2.8 and older): install libsox
torchaudio loads the unversioned libsox.so. On Debian 13 that symlink is in libsox-dev, not libsox3 (which only has libsox.so.3):
sudo apt install libsox-dev
Without root, conda-forge's sox package ships lib/libsox.so; point the loader at it:
micromamba create -p ./soxenv -c conda-forge sox
LD_LIBRARY_PATH=$PWD/soxenv/lib python b1.py
With either one, torchaudio 2.8.0 (warning lines shortened):
b1.py:5: UserWarning: torchaudio.sox_effects.sox_effects.apply_effects_tensor has been deprecated. This deprecation is part of a large refactoring effort to ...
out, out_sr = sox_effects.apply_effects_tensor(wav, sr, [["speed", "1.1"], ["rate", str(sr)]])
2.8.0+cu128 torch.Size([1, 14545]) 16000
Debian's libsox and conda-forge's gave identical output. This only buys time: upgrading to torchaudio 2.9 removes the module whatever is installed.
Related: No module named torchaudio.backend · No module named torchaudio.io · Could not load libtorchcodec · torchaudio.utils has no attribute download_asset
Frequently asked questions
Which torchaudio version removed sox_effects?
torchaudio 2.9.0. On 2.8.0 it still exists, warns that it will be removed in 2.9, and needs libsox.so at call time.
Which package provides libsox.so on Debian/Ubuntu?
On Debian 13 the unversioned libsox.so symlink is in libsox-dev; libsox3 only ships libsox.so.3, which torchaudio does not look for.
What replaces sox_effects speed and rate?
torchaudio.functional.speed (or functional.resample); gain and lowpass have functional.gain and functional.lowpass_biquad. All ran on 2.8.0 and 2.9.0 without libsox.
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), Debian 13 libsox-dev 14.4.2 and conda-forge sox. Output pasted unedited except shortened site-packages paths, cut tracebacks and trimmed warning lines. PlainTables is our extension; torchaudio and SoX are free.