Skip to content

Commit

Permalink
add user defined kaldi feature type (#1101)
Browse files Browse the repository at this point in the history
* add user defined kaldi feature type

* change type in features.jsonl.gz

* update --feature-type to click

* fix typo

* add option to the corresponding func & contraint the input feature-type

* reformatting the str to pass black test

---------

Co-authored-by: 廖子寒1 <[email protected]>
Co-authored-by: Piotr Żelasko <[email protected]>
  • Loading branch information
3 people authored Jul 21, 2023
1 parent ce6172d commit d5461ff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lhotse/bin/modes/kaldi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def kaldi():
type=int,
help="Number of jobs for computing recording durations.",
)
@click.option(
"-t",
"--feature-type",
default="kaldi-fbank",
show_default=True,
type=click.Choice(["kaldi-fbank", "kaldi-mfcc"]),
help="Feature type when importing precomputed features from feats.scp",
)
@click.option(
"-d",
"--compute-durations",
Expand All @@ -55,6 +63,7 @@ def import_(
frame_shift: float,
map_string_to_underscores: Optional[str],
num_jobs: int,
feature_type: str,
compute_durations: bool,
):
"""
Expand All @@ -70,6 +79,7 @@ def import_(
map_string_to_underscores=map_string_to_underscores,
num_jobs=num_jobs,
use_reco2dur=not compute_durations,
feature_type=feature_type,
)
manifest_dir = Path(manifest_dir)
manifest_dir.mkdir(parents=True, exist_ok=True)
Expand Down
3 changes: 2 additions & 1 deletion lhotse/kaldi.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def load_kaldi_data_dir(
map_string_to_underscores: Optional[str] = None,
use_reco2dur: bool = True,
num_jobs: int = 1,
feature_type: str = "kaldi-fbank",
) -> Tuple[RecordingSet, Optional[SupervisionSet], Optional[FeatureSet]]:
"""
Load a Kaldi data directory and convert it to a Lhotse RecordingSet and
Expand Down Expand Up @@ -239,7 +240,7 @@ def fix_id(t: str) -> str:

features.append(
Features(
type="kaldi_native_io",
type=feature_type,
num_frames=mat_shape.num_rows,
num_features=mat_shape.num_cols,
frame_shift=frame_shift,
Expand Down
Binary file modified test/fixtures/mini_librispeech2/lhotse/features.jsonl.gz
Binary file not shown.

0 comments on commit d5461ff

Please sign in to comment.