Skip to content

Instantly share code, notes, and snippets.

@esoterydactyl
Last active August 19, 2025 04:11
Show Gist options
  • Select an option

  • Save esoterydactyl/0a3484dcf1c9634c98f2cfebbc83eff6 to your computer and use it in GitHub Desktop.

Select an option

Save esoterydactyl/0a3484dcf1c9634c98f2cfebbc83eff6 to your computer and use it in GitHub Desktop.
Bash Script for Processing Drum Sounds with SoX Audio Convertor
#!/bin/bash
# Script by: @esoterydactyl
# Ver: 1.1.1
# 8/18/2025
check_sox() {
if ! command -v sox &> /dev/null
then
echo "Error: SoX is not installed. Please install it to run this script."
echo "On Ubuntu/Debian, use: sudo apt-get install sox libsox-fmt-mp3"
echo "On macOS, use: brew install sox"
exit 1
fi
}
main() {
check_sox
output_dir="normalized"
if [ ! -d "$output_dir" ]; then
mkdir -p "$output_dir"
echo "Created output directory: $output_dir"
else
echo "Using existing output directory: $output_dir"
fi
echo "Starting audio processing..."
for file in *; do
if [ -f "$file" ]; then
# Had to use case instead of normal globbing because ableton likes to create files with ".wav.asd" extensions. 🤦🏼‍♂️
case "$file" in
*.wav|*.mp3|*.flac|*.aiff)
filename=$(basename -- "$file")
filename_no_ext="${filename%.*}"
sanitized_name=$(echo "$filename_no_ext" | tr '[:upper:]' '[:lower:]' | tr -d ' ' | tr '_' '-' | tr -d '.')
echo ""
echo "--------------------------"
echo "⏳ Processing '$file'..."
output_path="$output_dir/${sanitized_name}_norm.wav"
# https://explainshell.com/explain?cmd=sox+%22%24file%22+-r+44100+-b+16+-c+2+%22%24output_path%22+silence+1+0.05+0.05%25+reverse+silence+1+0.05+0.05%25+reverse+gain+-n+-3
sox "$file" -r 44100 -b 16 -c 2 "$output_path" silence 1 0.05 0.01% reverse silence 1 0.05 0.01% reverse gain -n -3
# Check if the sox command was successful and the output file is not empty
if [ $? -eq 0 ] && [[ -s "$output_path" ]]; then
echo "✅ Successfully processed '$file'. Output saved to '$output_path'."
else
echo "⛔️ Error processing '$file'. The file may have failed to process or the output file is empty."
fi
;;
*)
esac
fi
done
echo ""
echo "🌈 Audio processing complete. Have a nice day!"
}
main
@esoterydactyl
Copy link
Author

esoterydactyl commented Aug 19, 2025

About this Script

General Notes:

This script is designed to be put in a path that you've added to $PATH in your profile - I like ~/bin .
It uses the SoX Audio Convertorto convert from wav, flac, or mp3 into 16-bit, 44.1kHz, stereo .wav files. This is helpful for drum sounds that will get loaded into samplers or similar contexts, and hopefully reduces sample hygiene work done on-device.

What it Does:

This script takes the following actions in your current folder once properly installed:

  • Creates a sub-folder called ./normalized
  • Runs a SoX command.
  • Trims silence from the beginning and end of the file (thresholds expressed in %, chosen conservatively)
  • Normalizes to -3dB (to avoid clipping issues)
  • Writes the new file.

How To Use:

  • cd to a folder of drum sound files.
  • Run process_sounds.sh or whatever you've named this.
  • Review output for problems
  • Check sounds in your DAW prior to deleting the original files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment