Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ready] [Recipes] add aishell2 #465

Merged
merged 14 commits into from
Jul 14, 2022
Empty file.
114 changes: 114 additions & 0 deletions egs/aishell2/ASR/local/compute_fbank_aishell2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env python3
# Copyright 2021 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 file computes fbank features of the aishell dataset.
It looks for manifests in the directory data/manifests.

The generated fbank features are saved in data/fbank.
"""

import argparse
import logging
import os
from pathlib import Path

import torch
from lhotse import CutSet, Fbank, FbankConfig, LilcomChunkyWriter
from lhotse.recipes.utils import read_manifests_if_cached

from icefall.utils import get_executor

# 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)


def compute_fbank_aishell2(num_mel_bins: int = 80):
src_dir = Path("data/manifests")
output_dir = Path("data/fbank")
num_jobs = min(15, os.cpu_count())

dataset_parts = (
"train",
"dev",
"test",
)
prefix = "aishell2"
suffix = "jsonl.gz"
manifests = read_manifests_if_cached(
dataset_parts=dataset_parts,
output_dir=src_dir,
prefix=prefix,
suffix=suffix,
)
assert manifests is not None

extractor = Fbank(FbankConfig(num_mel_bins=num_mel_bins))

with get_executor() as ex: # Initialize the executor only once.
for partition, m in manifests.items():
if (output_dir / f"{prefix}_cuts_{partition}.{suffix}").is_file():
logging.info(f"{partition} already exists - skipping.")
continue
logging.info(f"Processing {partition}")
cut_set = CutSet.from_manifests(
recordings=m["recordings"],
supervisions=m["supervisions"],
)
if "train" in partition:
cut_set = (
cut_set
+ cut_set.perturb_speed(0.9)
+ cut_set.perturb_speed(1.1)
)
cut_set = cut_set.compute_and_store_features(
extractor=extractor,
storage_path=f"{output_dir}/{prefix}_feats_{partition}",
# when an executor is specified, make more partitions
num_jobs=num_jobs if ex is None else 80,
executor=ex,
storage_type=LilcomChunkyWriter,
)
cut_set.to_file(output_dir / f"{prefix}_cuts_{partition}.{suffix}")


def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--num-mel-bins",
type=int,
default=80,
help="""The number of mel bins for Fbank""",
)

return parser.parse_args()


if __name__ == "__main__":
formatter = (
"%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s"
)

logging.basicConfig(format=formatter, level=logging.INFO)

args = get_args()
compute_fbank_aishell2(num_mel_bins=args.num_mel_bins)
1 change: 1 addition & 0 deletions egs/aishell2/ASR/local/compute_fbank_musan.py
193 changes: 193 additions & 0 deletions egs/aishell2/ASR/local/display_manifest_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#!/usr/bin/env python3
# Copyright 2021 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 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 transducer_stateless/train.py
for usage.
"""


from lhotse import load_manifest_lazy


def main():
# path = "./data/fbank/aishell2_cuts_train.jsonl.gz"
# path = "./data/fbank/aishell2_cuts_test.jsonl.gz"
path = "./data/fbank/aishell2_cuts_dev.jsonl.gz"

cuts = load_manifest_lazy(path)
cuts.describe()


if __name__ == "__main__":
main()

"""
## train (after speed perturb)
Cuts count: 360294
Total duration (hours): 455.6
Speech duration (hours): 455.6 (100.0%)
***
Duration statistics (seconds):
mean 4.6
std 1.4
min 1.1
0.1% 1.8
0.5% 2.2
1% 2.3
5% 2.7
10% 3.0
10% 3.0
25% 3.5
50% 4.3
75% 5.4
90% 6.5
95% 7.2
99% 8.8
99.5% 9.4
99.9% 10.9
max 16.1

## test
Cuts count: 7176
Total duration (hours): 10.0
Speech duration (hours): 10.0 (100.0%)
***
Duration statistics (seconds):
mean 5.0
std 1.6
min 1.9
0.1% 2.2
0.5% 2.4
1% 2.6
5% 3.0
10% 3.2
10% 3.2
25% 3.8
50% 4.7
75% 5.9
90% 7.3
95% 8.2
99% 9.9
99.5% 10.7
99.9% 11.9
max 14.7

## dev
Cuts count: 14326
Total duration (hours): 18.1
Speech duration (hours): 18.1 (100.0%)
***
Duration statistics (seconds):
mean 4.5
std 1.3
min 1.6
0.1% 2.1
0.5% 2.3
1% 2.4
5% 2.9
10% 3.1
10% 3.1
25% 3.5
50% 4.3
75% 5.4
90% 6.4
95% 7.0
99% 8.4
99.5% 8.9
99.9% 10.3
max 12.5

## aidatatang_200zh (train)
Cuts count: 164905
Total duration (hours): 139.9
Speech duration (hours): 139.9 (100.0%)
***
Duration statistics (seconds):
mean 3.1
std 1.1
min 1.1
0.1% 1.5
0.5% 1.7
1% 1.8
5% 2.0
10% 2.1
10% 2.1
25% 2.3
50% 2.7
75% 3.4
90% 4.6
95% 5.4
99% 7.1
99.5% 7.8
99.9% 9.1
max 16.3

## aidatatang_200zh (test)
Cuts count: 48144
Total duration (hours): 40.2
Speech duration (hours): 40.2 (100.0%)
***
Duration statistics (seconds):
mean 3.0
std 1.1
min 0.9
0.1% 1.5
0.5% 1.8
1% 1.8
5% 2.0
10% 2.1
10% 2.1
25% 2.3
50% 2.6
75% 3.4
90% 4.4
95% 5.2
99% 6.9
99.5% 7.5
99.9% 9.0
max 21.8

## aidatatang_200zh (dev)
Cuts count: 24216
Total duration (hours): 20.2
Speech duration (hours): 20.2 (100.0%)
***
Duration statistics (seconds):
mean 3.0
std 1.0
min 1.2
0.1% 1.6
0.5% 1.7
1% 1.8
5% 2.0
10% 2.1
10% 2.1
25% 2.3
50% 2.7
75% 3.4
90% 4.4
95% 5.1
99% 6.7
99.5% 7.3
99.9% 8.8
max 11.3
"""
1 change: 1 addition & 0 deletions egs/aishell2/ASR/local/prepare_char.py
1 change: 1 addition & 0 deletions egs/aishell2/ASR/local/text2token.py
Loading