Install & Compatibility
Where this runs
tested against v1.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 90.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 4.4s · import 0.000s · 87MB
90MB installed
● package 90MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ArchiveReader
✓ from kaldi_python_io import ArchiveReader
✗ import kaldi_io
ArchiveWriter
✓ from kaldi_python_io import ArchiveWriter
✗ import kaldi_io
ScriptReader
✓ from kaldi_python_io import ScriptReader
✗ import kaldi_io
This quickstart demonstrates how to create a NumPy matrix, write it to a Kaldi archive (`.ark`) file using `kaldi-python-io`, and then read it back. It includes file cleanup.
import kaldi_io
import numpy as np
import os
# Define a path for the temporary Kaldi archive file
temp_ark_path = "temp_matrix.ark"
try:
# 1. Create a NumPy array (e.g., a feature matrix)
# Kaldi typically uses float32 for features
feature_matrix = np.array([[1.1, 2.2, 3.3],
[4.4, 5.5, 6.6]], dtype=np.float32)
print(f"Original matrix:\n{feature_matrix}")
# 2. Write the NumPy array to a Kaldi archive file
# The library supports writing directly to a file path or file-like object
# 'key' is important for Kaldi archives to identify the data
with kaldi_io.open_or_fd(temp_ark_path, 'wb') as f:
kaldi_io.write_mat(f, feature_matrix, key='utt1_features')
print(f"Successfully wrote matrix to '{temp_ark_path}' with key 'utt1_features'.")
# 3. Read the matrix back from the Kaldi archive file
# kaldi_io.read_mat_s is a generator for multiple matrices in an ark file
read_data_generator = kaldi_io.read_mat_s(temp_ark_path)
# Since we wrote only one, we expect one (key, matrix) tuple. Get the first.
key, loaded_matrix = next(read_data_generator)
print(f"\nRead back data:")
print(f"Key: {key}")
print(f"Matrix:\n{loaded_matrix}")
# Verify if the loaded matrix matches the original
assert np.allclose(feature_matrix, loaded_matrix)
print("\nVerification successful: Loaded matrix matches original.")
finally:
# Clean up the temporary file
if os.path.exists(temp_ark_path):
os.remove(temp_ark_path)
print(f"Cleaned up temporary file: {temp_ark_path}")
Upgrade
Version history
1.2.2latest on PyPI · released Mar 18, 2021
Audit
Dependencies
numpyrequiredRequired for numerical array operations, which are central to handling Kaldi's matrix and vector data.