mirror of
https://github.com/k2-fsa/icefall.git
synced 2025-08-08 17:42:21 +00:00
116 lines
3.1 KiB
Bash
116 lines
3.1 KiB
Bash
#!/usr/bin/env bash
|
|
# Copyright 2024 Johns Hopkins University (Amir Hussein)
|
|
# Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
set -eou pipefail
|
|
|
|
nj=20
|
|
stage=-1
|
|
stop_stage=6
|
|
|
|
# We assume dl_dir (download dir) contains the following
|
|
# directories and files.
|
|
#
|
|
# - $dl_dir/mgb2
|
|
#
|
|
# You can download the data from
|
|
#
|
|
#
|
|
# - $dl_dir/musan
|
|
# This directory contains the following directories downloaded from
|
|
# http://www.openslr.org/17/
|
|
#
|
|
# - music
|
|
# - noise
|
|
# - speech
|
|
#
|
|
|
|
dl_dir=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=(
|
|
4000
|
|
)
|
|
|
|
# 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 -1 ] && [ $stop_stage -ge -1 ]; then
|
|
log "Stage 0: Download data"
|
|
|
|
# Note: Download SEAME from https://catalog.ldc.upenn.edu/LDC2015S04
|
|
#
|
|
# downlaod the splits https://github.com/zengzp0912/SEAME-dev-set.git to $dl_dir
|
|
#
|
|
# If you have pre-downloaded it to /path/to/seame,
|
|
# you can create a symlink
|
|
#
|
|
# ln -sfv /path/to/seame $dl_dir/seame
|
|
|
|
# If you have pre-downloaded it to /path/to/musan,
|
|
# you can create a symlink
|
|
#
|
|
# ln -sfv /path/to/musan $dl_dir/
|
|
#
|
|
if [ ! -d $dl_dir/musan ]; then
|
|
lhotse download musan $dl_dir
|
|
fi
|
|
fi
|
|
|
|
fbank=data_seame/fbank
|
|
manifests=data_seame/manifests
|
|
mkdir -p $manifests
|
|
|
|
if [ $stage -le 0] && [ $stop_stage -ge 0 ]; then
|
|
log "Stage 0: Prepare seame manifest"
|
|
# We assume that you have downloaded the corpus
|
|
# to $dl_dir/seame
|
|
lhotse prepare seame $dl_dir/seame $dl_dir/SEAME-dev-set data/manifests
|
|
fi
|
|
|
|
if [ $stage -le 2 ] && [ $stop_stage -ge 2 ]; then
|
|
log "Stage 2: Prepare musan manifest"
|
|
# We assume that you have downloaded the musan corpus
|
|
# to data/musan
|
|
mkdir -p data/manifests
|
|
lhotse prepare musan $dl_dir/musan data/manifests
|
|
fi
|
|
|
|
if [ $stage -le 3 ] && [ $stop_stage -ge 3 ]; then
|
|
log "Stage 3: Compute fbank features"
|
|
mkdir -p ${fbank}
|
|
python local/compute_fbank_gpu_seame.py
|
|
gunzip -c $fbank/cuts_train.jsonl.gz | shuf | gzip -c > ${fbank}/cuts_train_shuf.jsonl.gz
|
|
fi
|
|
|
|
if [ $stage -le 6 ] && [ $stop_stage -ge 6 ]; then
|
|
log "Stage 6: Prepare BPE based lang"
|
|
for vocab_size in ${vocab_sizes[@]}; do
|
|
lang_dir=data_seame/lang_bpe_${vocab_size}
|
|
mkdir -p ${lang_dir}
|
|
if [ ! -f $lang_dir/transcript_words.txt ]; then
|
|
log "Generate text for BPE training from data_seame/fbank/cuts_train_shuf.jsonl.gz"
|
|
python local/prepare_transcripts.py --cut ${fbank}/cuts_train_shuf.jsonl.gz --langdir ${lang_dir}
|
|
fi
|
|
source data_seame/manifests/token.man.1
|
|
./local/train_bpe_model.py \
|
|
--lang-dir $lang_dir \
|
|
--vocab-size $vocab_size \
|
|
--transcript $lang_dir/transcript_words.txt \
|
|
--predef-symbols "$bpe_nlsyms"
|
|
done
|
|
fi
|
|
|