Untitled
unknown
plain_text
a year ago
1.5 kB
2
Indexable
Never
#!/bin/bash help() { echo "Usage:" echo "audio_normalization.sh [-i input directory] [-o output directory] [-s sample rate] [-j number of jobs (default=1)]" exit -1 } thread_num=1 while getopts 'i:o:s:j:h' OPT; do case $OPT in i) dir_in="$OPTARG";; o) dir_out="$OPTARG";; s) sample_rate="$OPTARG";; j) thread_num="$OPTARG";; r) recursive="$OPTARG";; h) help;; ?) help;; esac done # dir_in=$1 # dir_out=$2 # sample_rate=$3 # thread_num=1 if [ ! -n "$sample_rate" ]; then echo "Sample rate is unknown!" exit 1 fi mkdir -p $dir_out if [ $thread_num == 1 ]; then # Single threads for filename in `ls $dir_in`; do if [ ${filename##*.} != 'wav' ]; then continue fi echo $filename sox $dir_in/$filename -c 1 -r $sample_rate -b 16 --norm=-7 $dir_out/$filename done else tmp_fifofile="/tmp/$$.fifo" mkfifo $tmp_fifofile exec 6<>$tmp_fifofile rm $tmp_fifofile # Initialization for ((i=0;i<${thread_num};i++));do echo done >&6 # Multiple threads for filename in `ls $dir_in`; do read -u6 { if [ ${filename##*.} != 'wav' ]; then continue fi echo $filename sox $dir_in/$filename -c 1 -r $sample_rate -b 16 --norm=-7 $dir_out/$filename echo >&6 } & done wait exec 6>&- echo "Done!" fi