Removing silent wav files

I use the following script to copy files from my 16 track stems. The script copies the files over, then uses sox to find “silent” files and remove them.

#!/bin/bash
#
# February 12, 2025 (Wednesday)
#

echo "Copying files to ~/Music/incoming_mixer_files/"
#rsync -va /Volumes/NO\ NAME/Records ~/Music/incoming_mixer_files/
EXIT_STATUS=$?

# Check if rsync was successful
if [ $EXIT_STATUS -ne 0 ]; then
    echo "Error: rsync failed with status $EXIT_STATUS"
    exit $EXIT_STATUS
else
    echo "Files copied successfully to ~/Music/incoming_mixer_files/."
fi


find ~/Music/incoming_mixer_files/ -type f -name "*.wav" -exec sh -c '
    for file; do
#        echo "Processing: $file"
        
        # Get RMS level in dB directly
        rms_db=$(sox "$file" -n stats 2>&1 | awk "/RMS lev dB/ {print \$4}")
        
        # Check if below threshold (-65dB) - comparing as a number
        if [ -n "$rms_db" ] && [ $(echo "$rms_db < -65" | bc) -eq 1 ]; then
            #echo "SILENT FILE DETECTED: $file (${rms_db}dB)"           
            mv "$file" ~/.Trash/
        else
            echo "Active file - keeping: $file (${rms_db}dB)"
        fi
    done
' sh {} +

Leave a comment

Your email address will not be published. Required fields are marked *