Registry / ai-ml / kaldi-python-io

kaldi-python-io

JSON →
library1.2.2pypypi✓ verified 89d ago

kaldi-python-io is a pure Python library providing an I/O interface for accessing data in the Kaldi speech recognition toolkit's native formats. It allows reading and writing various Kaldi data types such as matrices, vectors, and alignments directly in Python. The current version is 1.2.2, with new releases typically occurring every few months based on development activity.

pip install kaldi-python-io
INSTALL
IMPORT
SIG · KALDI-PYTHON-IO
K
kaldi-python-io
ai-mlpythonv1.2.2
Install
4.4s avg
Import
—
Disk
90MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
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
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 90.8MB
glibc
py 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}")
Debug
Known issues
gotchaEnsure you use the correct function for reading Kaldi data based on its format (e.g., `read_mat_s` for iterating through multiple matrices in an ARK file, versus `read_mat` for a single matrix from a stream/file-like object or stdin). Misunderstanding Kaldi's archive/stream conventions can lead to unexpected parsing errors or incomplete data reads.
fix
Consult the `kaldi-python-io` documentation or source for the specific function signature and expected input type (e.g., file path, file-like object, generator) based on your Kaldi data source.
affects: All versions
gotchaKaldi often expects specific data types, particularly `float32` for acoustic features and vectors. When creating data with NumPy to be written by `kaldi-python-io`, ensure your arrays have the correct `dtype` (e.g., `np.float32`) to maintain compatibility with downstream Kaldi tools.
fix
Explicitly set `dtype=np.float32` (or `np.float64` if appropriate for your Kaldi setup) when creating NumPy arrays that will be written to Kaldi formats.
affects: All versions
gotchaWhen writing Kaldi archives (`.ark` files) that contain multiple entries, each entry typically requires a unique string `key`. While `kaldi-python-io` handles the writing, other Kaldi tools rely on these keys for indexing and accessing data. Omitting or duplicating keys when writing multiple entries can lead to issues in Kaldi's data processing pipeline.
fix
Always provide a unique and descriptive string `key` parameter when using `write_mat`, `write_vec_flt`, etc., especially when writing to a stream that will contain multiple entries.
affects: All versions
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.
Agent activity
4 hits · last 30 days
node
4
Resources
kaldi-python-io — pip install kaldi-python-io · libregistry