Skip to content

Commit

Permalink
Merge pull request #58 from vesis84/alicegaz_patch_1
Browse files Browse the repository at this point in the history
Alicegaz patch 1
  • Loading branch information
KarelVesely84 authored Jun 16, 2023
2 parents e662eda + 3d86399 commit 44595b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ Note: it is recommended to set `$KALDI_ROOT` in your `$HOME/.bashrc` as
`export KALDI_ROOT=<some_kaldi_dir>`, so you can read/write using
pipes which contain kaldi binaries.

#### Unit tests

Unit tests are started this way:

`./run_tests.sh`

or by:

`python3 -m unittest discover -s tests -t .`
`python2 -m unittest discover -s tests -t .`


#### License
Apache License, Version 2.0 ('LICENSE-2.0.txt')
Expand Down
14 changes: 8 additions & 6 deletions kaldi_io/kaldi_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def write_vec_flt(file_or_fd, v, key=''):
# Float matrices (features, transformations, ...),

# Reading,

def read_mat_scp(file_or_fd):
""" generator(key,mat) = read_mat_scp(file_or_fd)
Returns generator of (key,matrix) tuples, read according to kaldi scp.
Expand All @@ -357,20 +358,21 @@ def read_mat_scp(file_or_fd):
d = { key:mat for key,mat in kaldi_io.read_mat_scp(file) }
"""
fd = open_or_fd(file_or_fd)
try:
for line in fd:

for line in fd:
try:
(key, rxfile) = line.decode().split(' ')
(rxfile, range_slice) = _strip_mat_range(rxfile)

# TODO, this reads whole file, and then selects the range.
# A faster solution would be to change API of read_mat() and load just the frames we need...
mat = read_mat(rxfile)
if range_slice is not None: mat = (mat[range_slice]).copy() # apply the range_slice,
#

yield key, mat
finally:
if fd is not file_or_fd : fd.close()
except:
print("WARNING: error reading matrix, key: %s, (it is skipped)" % key)

if fd is not file_or_fd: fd.close()

def read_mat_ark(file_or_fd):
""" generator(key,mat) = read_mat_ark(file_or_fd)
Expand Down

0 comments on commit 44595b1

Please sign in to comment.