#!/usr/bin/env bash # fix segmentation fault reported in https://github.com/k2-fsa/icefall/issues/674 export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python set -eou pipefail nj=15 # run step 0 to step 5 by default stage=0 stop_stage=5 # Note: This script just prepare the minimal requirements that needed by a # transducer training with bpe units. # # If you want to use ngram or nnlm, please continue running prepare_lm.sh after # you succeed running this script. # # This script also contains the steps to generate phone based units, but they # will not run automatically, you can generate the phone based units by # bash prepare.sh --stage -1 --stop-stage -1 # bash prepare.sh --stage 6 --stop-stage 6 # We assume dl_dir (download dir) contains the following # directories and files. If not, they will be downloaded # by this script automatically. # # - $dl_dir/LibriSpeech # You can find BOOKS.TXT, test-clean, train-clean-360, etc, inside it. # You can download them from https://www.openslr.org/12 # # - $dl_dir/musan # This directory contains the following directories downloaded from # http://www.openslr.org/17/ # # - music # - noise # - speech num_per_split=4000 fbank_dir=data/fbank_mls 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 "Running prepare.sh" log "dl_dir: $dl_dir" log "fbank_dir: $fbank_dir" languages=( english german dutch spanish italian french polish portuguese ) if [ $stage -le 0 ] && [ $stop_stage -ge 0 ]; then log "Stage 0: Download data" # If you have pre-downloaded it to /path/to/MLS, # you can create a symlink # # ln -sfv /path/to/MLS $dl_dir/MLS # if [ ! -d $dl_dir/MLS/train-other-500 ]; then lhotse download mls --full $dl_dir fi # 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 if [ $stage -le 1 ] && [ $stop_stage -ge 1 ]; then log "Stage 1: Prepare MLS manifest" # We assume that you have downloaded the MLS corpus # to $dl_dir/MLS mkdir -p data/manifests if [ ! -e data/manifests/.mls.done ]; then lhotse prepare mls -j $nj $dl_dir/MLS data/manifests touch data/manifests/.mls.done fi 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 $dl_dir/musan mkdir -p data/manifests if [ ! -e data/manifests/.musan.done ]; then lhotse prepare musan $dl_dir/musan data/manifests touch data/manifests/.musan.done fi fi if [ $stage -le 3 ] && [ $stop_stage -ge 3 ]; then log "Stage 3: Split english subset into pieces (may take 30 minutes)" split_dir=${fbank_dir}/english_split if [ ! -f $split_dir/.split_completed ]; then lhotse split-lazy ${fbank_dir}/mls-english_train_raw.jsonl.gz $split_dir $num_per_split touch $split_dir/.split_completed fi fi if [ $stage -le 4 ] && [ $stop_stage -ge 4 ]; then log "Stage 4: Compute fbank for MLS (except English)" mkdir -p ${fbank_dir} if [ ! -e ${fbank_dir}/.mls.done ]; then ./local/compute_fbank_mls.py touch ${fbank_dir}/.mls.done fi fi if [ $stage -le 5 ] && [ $stop_stage -ge 5 ]; then log "Stage 5: Compute fbank for English split of MLS" if [ ! -e ${fbank_dir}/.mls-english.done ]; then num_splits=$(find ${fbank_dir}/english_split -name "mls-english_train_raw.*.jsonl.gz" | wc -l) ./local/compute_fbank_mls_splits.py \ --fbank-dir $fbank_dir \ --num-workers 20 \ --language english \ --num-splits $num_splits \ touch ${fbank_dir}/.mls-english.done fi if [ ! -e ${fbank_dir}/mls-english_train.jsonl.gz ]; then pieces=$(find ${fbank_dir}/english_split -name "mls-english_train.*.jsonl.gz") lhotse combine $pieces ${fbank_dir}/mls-english_train.jsonl.gz fi fi if [ $stage -le 6 ] && [ $stop_stage -ge 6 ]; then log "Stage 6: Validate the manifest of MLS" if [ ! -e ${fbank_dir}/.mls-validated.done ]; then log "Validating the fbank features for MLS" parts=( train dev test ) for lan in ${languages[@]}; do for part in ${parts[@]}; do python3 ./local/validate_manifest.py \ ${fbank_dir}/mls-${lan}_${part}.jsonl.gz done done touch ${fbank_dir}/.mls-validated.done fi fi if [ $stage -le 7 ] && [ $stop_stage -ge 7 ]; then log "Stage 7: Compute fbank for musan" mkdir -p ${fbank_dir} if [ ! -e ${fbank_dir}/.musan.done ]; then ./local/compute_fbank_musan.py touch ${fbank_dir}/.musan.done fi fi if [ $stage -le 8 ] && [ $stop_stage -ge 8 ]; then log "Stage 8: Prepare BPE based lang" for vocab_size in ${vocab_sizes[@]}; do lang_dir=data/lang_bpe_${vocab_size} mkdir -p $lang_dir if [ ! -f $lang_dir/transcript_words.txt ]; then log "Generate data for BPE training" files=( "$dl_dir/MLS/mls_english/train/transcripts.txt" "$dl_dir/MLS/mls_german/train/transcripts.txt" "$dl_dir/MLS/mls_dutch/train/transcripts.txt" "$dl_dir/MLS/mls_french/train/transcripts.txt" "$dl_dir/MLS/mls_spanish/train/transcripts.txt" "$dl_dir/MLS/mls_italian/train/transcripts.txt" "$dl_dir/MLS/mls_portuguese/train/transcripts.txt" "$dl_dir/MLS/mls_polish/train/transcripts.txt" ) for f in ${files[@]}; do head -n 1000000 $f | cut -d " " -f 2- done > $lang_dir/transcript_words.txt fi if [ ! -f $lang_dir/bpe.model ]; then ./local/train_bpe_model.py \ --lang-dir $lang_dir \ --vocab-size $vocab_size \ --character-coverage 0.999 \ --transcript $lang_dir/transcript_words.txt \ --byte-fallback fi done fi