diff --git a/egs/multi_ja_en/ASR/local/compute_fbank_reazonspeech.py b/egs/multi_ja_en/ASR/local/compute_fbank_reazonspeech.py deleted file mode 100644 index af7841406..000000000 --- a/egs/multi_ja_en/ASR/local/compute_fbank_reazonspeech.py +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2023 The University of Electro-Communications (Author: Teo Wen Shen) # noqa -# -# See ../../../../LICENSE for clarification regarding multiple authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import argparse -import logging -import os -from pathlib import Path -from typing import List, Tuple - -import torch - -# fmt: off -from lhotse import ( # See the following for why LilcomChunkyWriter is preferred; https://github.com/k2-fsa/icefall/pull/404; https://github.com/lhotse-speech/lhotse/pull/527 - CutSet, - Fbank, - FbankConfig, - LilcomChunkyWriter, - RecordingSet, - SupervisionSet, -) - -# fmt: on - -# Torch's multithreaded behavior needs to be disabled or -# it wastes a lot of CPU and slow things down. -# Do this outside of main() in case it needs to take effect -# even when we are not invoking the main (e.g. when spawning subprocesses). -torch.set_num_threads(1) -torch.set_num_interop_threads(1) - -RNG_SEED = 42 -concat_params = {"gap": 1.0, "maxlen": 10.0} - - -def make_cutset_blueprints( - manifest_dir: Path, -) -> List[Tuple[str, CutSet]]: - cut_sets = [] - - # Create test dataset - logging.info("Creating test cuts.") - cut_sets.append( - ( - "test", - CutSet.from_manifests( - recordings=RecordingSet.from_file( - manifest_dir / "reazonspeech_recordings_test.jsonl.gz" - ), - supervisions=SupervisionSet.from_file( - manifest_dir / "reazonspeech_supervisions_test.jsonl.gz" - ), - ), - ) - ) - - # Create dev dataset - logging.info("Creating dev cuts.") - cut_sets.append( - ( - "dev", - CutSet.from_manifests( - recordings=RecordingSet.from_file( - manifest_dir / "reazonspeech_recordings_dev.jsonl.gz" - ), - supervisions=SupervisionSet.from_file( - manifest_dir / "reazonspeech_supervisions_dev.jsonl.gz" - ), - ), - ) - ) - - # Create train dataset - logging.info("Creating train cuts.") - cut_sets.append( - ( - "train", - CutSet.from_manifests( - recordings=RecordingSet.from_file( - manifest_dir / "reazonspeech_recordings_train.jsonl.gz" - ), - supervisions=SupervisionSet.from_file( - manifest_dir / "reazonspeech_supervisions_train.jsonl.gz" - ), - ), - ) - ) - return cut_sets - - -def get_args(): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter, - ) - parser.add_argument("-m", "--manifest-dir", type=Path) - return parser.parse_args() - - -def main(): - args = get_args() - - extractor = Fbank(FbankConfig(num_mel_bins=80)) - num_jobs = min(16, os.cpu_count()) - - formatter = "%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s" - - logging.basicConfig(format=formatter, level=logging.INFO) - - if (args.manifest_dir / ".reazonspeech-fbank.done").exists(): - logging.info( - "Previous fbank computed for ReazonSpeech found. " - f"Delete {args.manifest_dir / '.reazonspeech-fbank.done'} to allow recomputing fbank." - ) - return - else: - cut_sets = make_cutset_blueprints(args.manifest_dir) - for part, cut_set in cut_sets: - logging.info(f"Processing {part}") - cut_set = cut_set.compute_and_store_features( - extractor=extractor, - num_jobs=num_jobs, - storage_path=(args.manifest_dir / f"feats_{part}").as_posix(), - storage_type=LilcomChunkyWriter, - ) - cut_set.to_file(args.manifest_dir / f"reazonspeech_cuts_{part}.jsonl.gz") - - logging.info("All fbank computed for ReazonSpeech.") - (args.manifest_dir / ".reazonspeech-fbank.done").touch() - - -if __name__ == "__main__": - main() diff --git a/egs/multi_ja_en/ASR/local/display_manifest_statistics.py b/egs/multi_ja_en/ASR/local/display_manifest_statistics.py deleted file mode 100644 index ace1dd73f..000000000 --- a/egs/multi_ja_en/ASR/local/display_manifest_statistics.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2021 Xiaomi Corp. (authors: Fangjun Kuang) -# 2022 The University of Electro-Communications (author: Teo Wen Shen) # noqa -# -# See ../../../../LICENSE for clarification regarding multiple authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -from pathlib import Path - -from lhotse import CutSet, load_manifest - -ARGPARSE_DESCRIPTION = """ -This file displays duration statistics of utterances in a manifest. -You can use the displayed value to choose minimum/maximum duration -to remove short and long utterances during the training. - -See the function `remove_short_and_long_utt()` in -pruned_transducer_stateless5/train.py for usage. -""" - - -def get_parser(): - parser = argparse.ArgumentParser( - description=ARGPARSE_DESCRIPTION, - formatter_class=argparse.ArgumentDefaultsHelpFormatter, - ) - - parser.add_argument("--manifest-dir", type=Path, help="Path to cutset manifests") - - return parser.parse_args() - - -def main(): - args = get_parser() - - for part in ["train", "dev"]: - path = args.manifest_dir / f"reazonspeech_cuts_{part}.jsonl.gz" - cuts: CutSet = load_manifest(path) - - print("\n---------------------------------\n") - print(path.name + ":") - cuts.describe() - - -if __name__ == "__main__": - main() diff --git a/egs/multi_ja_en/ASR/local/prepare_lang_char.py b/egs/multi_ja_en/ASR/local/prepare_lang_char.py deleted file mode 100644 index 19c5f4a31..000000000 --- a/egs/multi_ja_en/ASR/local/prepare_lang_char.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2022 The University of Electro-Communications (Author: Teo Wen Shen) # noqa -# -# See ../../../../LICENSE for clarification regarding multiple authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import argparse -import logging -from pathlib import Path - -from lhotse import CutSet - - -def get_args(): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter, - ) - - parser.add_argument( - "train_cut", metavar="train-cut", type=Path, help="Path to the train cut" - ) - - parser.add_argument( - "--lang-dir", - type=Path, - default=Path("data/lang_char"), - help=( - "Name of lang dir. " - "If not set, this will default to lang_char_{trans-mode}" - ), - ) - - return parser.parse_args() - - -def main(): - args = get_args() - logging.basicConfig( - format=("%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s"), - level=logging.INFO, - ) - - sysdef_string = set(["", "", "", " "]) - - token_set = set() - logging.info(f"Creating vocabulary from {args.train_cut}.") - train_cut: CutSet = CutSet.from_file(args.train_cut) - for cut in train_cut: - for sup in cut.supervisions: - token_set.update(sup.text) - - token_set = [""] + sorted(token_set - sysdef_string) + ["", ""] - args.lang_dir.mkdir(parents=True, exist_ok=True) - (args.lang_dir / "tokens.txt").write_text( - "\n".join(f"{t}\t{i}" for i, t in enumerate(token_set)) - ) - - (args.lang_dir / "lang_type").write_text("char") - logging.info("Done.") - - -if __name__ == "__main__": - main() diff --git a/egs/multi_ja_en/ASR/local/validate_manifest.py b/egs/multi_ja_en/ASR/local/validate_manifest.py deleted file mode 100644 index 7f67c64b6..000000000 --- a/egs/multi_ja_en/ASR/local/validate_manifest.py +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2022 Xiaomi Corp. (authors: Fangjun Kuang) -# -# See ../../../../LICENSE for clarification regarding multiple authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -""" -This script checks the following assumptions of the generated manifest: - -- Single supervision per cut -- Supervision time bounds are within cut time bounds - -We will add more checks later if needed. - -Usage example: - - python3 ./local/validate_manifest.py \ - ./data/fbank/librispeech_cuts_train-clean-100.jsonl.gz - -""" - -import argparse -import logging -from pathlib import Path - -from lhotse import CutSet, load_manifest -from lhotse.cut import Cut - - -def get_args(): - parser = argparse.ArgumentParser() - - parser.add_argument( - "--manifest", - type=Path, - help="Path to the manifest file", - ) - - return parser.parse_args() - - -def validate_one_supervision_per_cut(c: Cut): - if len(c.supervisions) != 1: - raise ValueError(f"{c.id} has {len(c.supervisions)} supervisions") - - -def validate_supervision_and_cut_time_bounds(c: Cut): - s = c.supervisions[0] - - # Removed because when the cuts were trimmed from supervisions, - # the start time of the supervision can be lesser than cut start time. - # https://github.com/lhotse-speech/lhotse/issues/813 - # if s.start < c.start: - # raise ValueError( - # f"{c.id}: Supervision start time {s.start} is less " - # f"than cut start time {c.start}" - # ) - - if s.end > c.end: - raise ValueError( - f"{c.id}: Supervision end time {s.end} is larger " - f"than cut end time {c.end}" - ) - - -def main(): - args = get_args() - - manifest = Path(args.manifest) - logging.info(f"Validating {manifest}") - - assert manifest.is_file(), f"{manifest} does not exist" - cut_set = load_manifest(manifest) - assert isinstance(cut_set, CutSet) - - for c in cut_set: - validate_one_supervision_per_cut(c) - validate_supervision_and_cut_time_bounds(c) - - -if __name__ == "__main__": - formatter = "%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s" - - logging.basicConfig(format=formatter, level=logging.INFO) - - main()