icefall/egs/librispeech/ASR/prepare_peoples_speech.sh
2023-05-31 13:12:27 +08:00

128 lines
3.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eou pipefail
nj=32
stage=-1
stop_stage=100
# Split data/set to a number of pieces
# This is to avoid OOM during feature extraction.
num_per_split=4000
# We assume dl_dir (download dir) contains the following
# directories and files. If not, they will be downloaded
# by this script automatically.
#
# - $dl_dir/peoples_speech
# This directory contains the following files downloaded from
# https://huggingface.co/datasets/MLCommons/peoples_speech
#
# - test
# - train
# - validation
dl_dir=$PWD/download
. shared/parse_options.sh || exit 1
# vocab size for sentence piece models.
# It will generate data/lang_bpe_xxx,
# data/lang_bpe_yyy if the array contains xxx, yyy
vocab_sizes=(
# 5000
# 2000
# 1000
500
)
# All files generated by this script are saved in "data".
# You can safely remove "data" and rerun this script to regenerate it.
mkdir -p data
log() {
# This function is from espnet
local fname=${BASH_SOURCE[1]##*/}
echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*"
}
log "dl_dir: $dl_dir"
if [ $stage -le 0 ] && [ $stop_stage -ge 0 ]; then
log "Stage 0: Download data"
# If you have pre-downloaded it to /path/to/peoples_speech,
# you can create a symlink
#
# ln -sfv /path/to/peoples_speech $dl_dir/peoples_speech
#
if [ ! -d $dl_dir/peoples_speech/train ]; then
git lfs install
git clone https://huggingface.co/datasets/MLCommons/peoples_speech
fi
fi
if [ $stage -le 1 ] && [ $stop_stage -ge 1 ]; then
log "Stage 1: Prepare People's Speech manifest"
# We assume that you have downloaded the People's Speech corpus
# to $dl_dir/peoples_speech
mkdir -p data/manifests
if [ ! -e data/manifests/.peoples_speech.done ]; then
lhotse prepare peoples-speech -j $nj $dl_dir/peoples_speech data/manifests
touch data/manifests/.peoples_speech.done
fi
fi
if [ $stage -le 2 ] && [ $stop_stage -ge 2 ]; then
log "Stage 2: Preprocess People's Speech manifest"
mkdir -p data/fbank
if [ ! -e data/fbank/.preprocess_complete ]; then
./local/preprocess_peoples_speech.py
touch data/fbank/.preprocess_complete
fi
fi
if [ $stage -le 3 ] && [ $stop_stage -ge 3 ]; then
log "Stage 3: Compute fbank for valid and test subsets of People's Speech"
if [ ! -e data/fbank/.peoples_speech_valid_test.done ]; then
./local/compute_fbank_peoples_speech_valid_test.py
touch data/fbank/.peoples_speech_valid_test.done
fi
fi
if [ $stage -le 4 ] && [ $stop_stage -ge 4 ]; then
log "Stage 4: Split train subset into pieces"
split_dir=data/fbank/peoples_speech_train_split
if [ ! -e $split_dir/.peoples_speech_dirty_split.done ]; then
lhotse split-lazy ./data/fbank/peoples_speech_cuts_dirty_raw.jsonl.gz $split_dir $num_per_split
touch $split_dir/.peoples_speech_dirty_split.done
fi
if [ ! -e $split_dir/.peoples_speech_dirty_sa_split.done ]; then
lhotse split-lazy ./data/fbank/peoples_speech_cuts_dirty_sa_raw.jsonl.gz $split_dir $num_per_split
touch $split_dir/.peoples_speech_dirty_sa_split.done
fi
if [ ! -e $split_dir/.peoples_speech_clean_split.done ]; then
lhotse split-lazy ./data/fbank/peoples_speech_cuts_clean_raw.jsonl.gz $split_dir $num_per_split
touch $split_dir/.peoples_speech_clean_split.done
fi
if [ ! -e $split_dir/.peoples_speech_clean_sa_split.done ]; then
lhotse split-lazy ./data/fbank/peoples_speech_cuts_clean_sa_raw.jsonl.gz $split_dir $num_per_split
touch $split_dir/.peoples_speech_clean_sa_split.done
fi
fi
if [ $stage -le 5 ] && [ $stop_stage -ge 5 ]; then
log "Stage 5: Compute features for train subset of People's Speech"
if [ ! -e data/fbank/.peoples_speech_train.done ]; then
./local/compute_fbank_peoples_speech_splits.py \
--num-workers $nj \
--batch-duration 600 \
--start 0 \
--num-splits 2000
touch data/fbank/.peoples_speech_train.done
fi
fi