Skip to content

Instantly share code, notes, and snippets.

@62mkv
Created May 16, 2016 06:27
Show Gist options
  • Select an option

  • Save 62mkv/7f0e37d10d8be28bfa5a542da63315f0 to your computer and use it in GitHub Desktop.

Select an option

Save 62mkv/7f0e37d10d8be28bfa5a542da63315f0 to your computer and use it in GitHub Desktop.
Bash script to convert all 2nd level wav files (without extension) to 16-bit wav files
#!/bin/bash
CONVERT="convert-tmp"
FILELIST=$(find . -maxdepth 2| xargs file | grep WAVE | awk -F':' '{ print $1}' | awk -F'/' '{ print $2, $3}')
while read -r line; do
FOLDER=$(echo $line | awk '{print $1}')
FILE=$(echo $line | awk '{print $2}')
INFILE="$FOLDER/$FILE"
OUTFILE="$FOLDER/$CONVERT/$FILE"
echo "Converting $INFILE to $OUTFILE"
if [ ! -d $FOLDER/$CONVERT ]; then
mkdir $FOLDER/$CONVERT
fi
sox -t wav $INFILE -b 16 -t wav $OUTFILE && mv $OUTFILE $INFILE && rmdir $FOLDER/$CONVERT
done <<< "$FILELIST"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment