samromur_asr / scripts /parallel_convert.sh
DavidErikMollberg's picture
init
950862d
#!/bin/bash
# Directory where the converted .wav files will be stored.
# The prompt mentioned storing them "directly under the upper test folder".
# Assuming the script is run from /home/dem/projects/k2/isl_zipformer/asr_data/samromur_asr/
# and the 'upper test folder' is 'test/', this script will place files in 'test/wav_files/'.
# If the script is run from /home/dem/projects/k2, it will be in isl_zipformer/asr_data/samromur_asr/test/wav_files
# Let's assume the script is run from where the `test` directory is.
the_set=train
OUTPUT_DIR="${the_set}/wav_files"
mkdir -p "$OUTPUT_DIR"
# Number of parallel jobs. `nproc` gets the number of CPU cores.
# You can change this to a fixed number, e.g., PARALLEL_JOBS=4
PARALLEL_JOBS=8
echo "Converting files in parallel using up to $PARALLEL_JOBS jobs..."
# Find all .flac files and pipe them to xargs for parallel processing.
# The `-P` option for xargs sets the maximum number of parallel processes.
# The `-I {}` option tells xargs to replace `{}` with the input line (the file path).
find ${the_set}/train_part_01 -type f -name "*.flac" | xargs -P "$PARALLEL_JOBS" -I {} bash -c '
flac_file="{}"
# Get the base filename without the .flac extension
base_filename=$(basename "$flac_file" .flac)
output_wav_file="'"$OUTPUT_DIR"'/${base_filename}.wav"
# Run the ffmpeg conversion.
# -y overwrites the output file if it exists.
ffmpeg -y -hide_banner -loglevel quiet -i "$flac_file" -ac 1 -ar 16000 "$output_wav_file"
'
echo "All conversions are complete. Check the '$OUTPUT_DIR' directory."