No module named 'torchaudio.kaldi_io' (fix)
On torchaudio 2.9, import torchaudio.kaldi_io raises ModuleNotFoundError: No module named 'torchaudio.kaldi_io'. We reproduced it and tested a drop-in replacement with kaldiio.
1. The error
A one-utterance feature archive (written with kaldiio.save_ark), read the old way:
import torchaudio
import torchaudio.kaldi_io
for key, mat in torchaudio.kaldi_io.read_mat_ark("feats.ark"):
print(torchaudio.__version__, key, mat.shape, mat.dtype)
torchaudio 2.9.0:
Traceback (most recent call last):
File "b1.py", line 2, in <module>
import torchaudio.kaldi_io
ModuleNotFoundError: No module named 'torchaudio.kaldi_io'
torchaudio 2.8.0 with the kaldi_io package installed reads it, after a deprecation warning, a KALDI_ROOT banner from kaldi_io itself, and a read-only-array warning (lines shortened):
b1.py:3: UserWarning: torchaudio.kaldi_io.read_mat_ark has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio i...
for key, mat in torchaudio.kaldi_io.read_mat_ark("feats.ark"):
################################################################################
### WARNING, path does not exist: KALDI_ROOT=/mnt/matylda5/iveselyk/Tools/kaldi-trunk
### (please add 'export KALDI_ROOT=<your_path>' in your $HOME/.profile)
### (or run as: KALDI_ROOT=<your_path> python <your_script>.py)
################################################################################
.../site-packages/torchaudio/kaldi_io.py:42: UserWarning: The given NumPy array is not writable, and PyTorch does not support non-writable tensors. This mean...
yield key, torch.from_numpy(np_arr)
2.8.0+cu128 utt1 torch.Size([2, 3]) torch.float32
2. Fix: read the ark with kaldiio
pip install kaldiio
import torch, kaldiio
for key, mat in kaldiio.load_ark("feats.ark"):
t = torch.from_numpy(mat.copy()) # copy: kaldiio returns a read-only array
print(torch.__version__, key, t.shape, t.dtype)
torchaudio 2.9.0 (no torchaudio import needed):
2.9.0+cpu utt1 torch.Size([2, 3]) torch.float32
torch 2.8.0:
2.8.0+cu128 utt1 torch.Size([2, 3]) torch.float32
Same key, shape and dtype as the old read_mat_ark. Without .copy() torch warned "The given NumPy array is not writable" (the old torchaudio wrapper warned the same). For .scp files, kaldiio.load_scp("feats.scp") returns a dict-like reader.
3. Or pin torchaudio 2.8.0
pip install "torch==2.8.0" "torchaudio==2.8.0" kaldi_io
torchaudio.kaldi_io is only a wrapper around the kaldi_io package, so that also has to be installed.
Related: No module named torchaudio.backend · torchaudio sox_effects removed in 2.9 · torchaudio.utils has no attribute download_asset
Frequently asked questions
Which torchaudio version removed kaldi_io?
torchaudio 2.9.0. On 2.8.0 it works with a deprecation warning, as long as the kaldi_io package is installed.
What replaces torchaudio.kaldi_io.read_mat_ark?
kaldiio.load_ark(path) yields (key, numpy array) pairs; wrap with torch.from_numpy(mat.copy()) for a tensor. It gave the same key, shape and dtype in our test.
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), kaldiio and kaldi_io from PyPI. Output pasted unedited except shortened paths and trimmed warning lines. PlainTables is our extension; torchaudio and kaldiio are free.