How To Find (and Delete) Silent Audio Files

Posted on February 6, 2013 by David Hilowitz

The Problem

If you’re anything like me, you have a ton of audio files on your hard drive. When I’m working on music (or an audio synthesis project), I will export out songs that I’m working on in one piece of software in order to import them into another. I keep the intermediary tracks in my Dropbox so that I can use and reuse the little snippets when I’m building my compositions. Life has gotten much easier for me in the past few years as most modern audio sequencers (Cubase, Live, PreSonus Studio One) now offer the possibility of exporting all the component tracks of a composition. The problem is, if you have 12 tracks in your song file and only 4 of them are actually being used in the section of song you are exporting, you’ll end up with 12 audio files—8 of which will be blank. If only there were some easy way of find and deleting those blank files so that they didn’t take up so much of my valuable Dropbox space…

The Solution

Luckily, if you’re using a Mac/Linux box, it’s possible to find (and yes, delete) silent audio files en masse using the command-line. It’s undoubtedly possible in Windows, too, using Cygwin, but I haven’t tried it. NOTE: This is very much a use-at-your-own-risk solution. When I do this, I never delete the files directly. I always just use this system to generate a file list. Then I drop the list of files into Winamp and have a relaxing “silent file listening session.” In other words, I check to make sure they are, in fact, actually silent.

OK, so how does it work?

For starters, you will need to install a super useful tool call SoX. SoX is a command-line tool which can be used to perform conversions from one audio file format to another, to apply filters to your files, as well as to generate useful statistics about your audio. In OS X, you can install it via MacPorts (simply type “sudo port install sox” at the Terminal) and on Linux via apt-get. You can also go the old-fashioned route by downloading the source files and compiling it.

Once you have it installed, try it out. Open up a Terminal window, cd into a directory that contains some audio files, and type this:

sox <name_of_audio_file> -n stat

You should get a response that looks like this:

~/loops $ sox <name_of_audio_file> -n stat
Samples read: 2596058
Length (seconds): 13.521135
Scaled by: 2147483647.0
Maximum amplitude: 0.848263
Minimum amplitude: -0.943067
Midline amplitude: -0.047402
Mean norm: 0.083552
Mean amplitude: -0.000062
RMS amplitude: 0.120734
Maximum delta: 0.157007
Minimum delta: 0.000000
Mean delta: 0.024596
RMS delta: 0.034412
Rough frequency: 4354
Volume adjustment: 1.060

We can see from the output that this .wav file is definitely not silent. If it were silent, the Max, Min, and Midline amplitudes would all be 0.000000.

OK, now that we’ve seen what SoX provides us with, how do we find the silent files?

Open up your favorite text editor and paste this into a text file:

#!/bin/bash

## A quick hack like script to list all the files that have
## a low amplitude.
##
## Input is a bash file list or glob.
##
## $ find_silent_audio_files *.wav
##
## Each time the script runs it will remove the output list
## and regenerate it. Stderr will output each file and it's
## amplitude.

Max=0.0 # Any amplitude greater than this will NOT be listed
OutList=~/output.list # The name of the file that contains a
# list of file names only of all the
# low-amplitude files.

# rm $OutList
for each in "$@"
do amplitude=$(sox "$each" -n stat 2>&1 | grep "Maximum amplitude" | cut -d ":" -f 2 | sed 's/ g')
if [[ $(echo "if (${amplitude} > ${Max}) 1 else 0" | bc) -eq 0 ]]
then echo "$each --> $amplitude" >&2
echo "$each" >> $OutList
fi
done

Save this as find_silent_audio_files somewhere in your PATH (maybe in /usr/local/bin or a ~/bin directory if you have one). chmod it so that it’s executable (chmod +x ./find_silent_audio_files).

Great. You are now ready to use this tool. Run it as follows:

dave:~ dhilowitz$ cd ~/wave_files
dave:wave_files dhilowitz$ find_silent_audio_files *.wav
202_what_you_working_on_chorus 13-Audio.wav --> 0.000000
202_what_you_working_on_chorus 2 - 12 C HEND.wav --> 0.000000
202_what_you_working_on_chorus A-Return.wav --> 0.000000
202_what_you_working_on_chorus B-Return.wav --> 0.000000
202_what_you_working_on_chorus MIDI Tracks.wav --> 0.000000
202_what_you_working_on_chorus MOOG.wav --> 0.000000
202_what_you_working_on_verse 13-Audio.wav --> 0.000000
202_what_you_working_on_verse 2 - 12 C HEND.wav --> 0.000000
202_what_you_working_on_verse A-Return.wav --> 0.000000
202_what_you_working_on_verse B-Return.wav --> 0.000000
202_what_you_working_on_verse MIDI Tracks.wav --> 0.000000
202_what_you_working_on_verse MOOG.wav --> 0.000000

The output of the command will be echoed to stdout as well as to a file in your user directory called ~/output.list. As you can see from the code listing above, this file name can be changed. Once you know the names of the files, it should be pretty easy to delete them. Obviously, changing “echo” to “rm” in the script above will accomplish this, but, as I said before, I wouldn’t recommend it unless you have backups or really don’t care.

OK. That’s about it. Good luck! I hope this is useful to someone out there.

–David

7 Comments »

  1. Thanks! The ” sed ‘s/ g'” should probably be ” sed ‘s/ //g’ though

    It does work on cygwin; you need to install the non-base packages ‘sox’ and ‘bc’

    Comment by Chris — September 27, 2015 @ 7:17 pm

  2. Hi! Thanks for this input. This did not work for my purposes, and I would like to point people in the same shoes as me toward “VAD”. I still haven’t solved my issue, but believe that to be the correct direction.

    Comment by Matt — December 15, 2016 @ 9:15 am

  3. Awesome, took me a while to get this working. Maybe this helps somebody.

    –> Easiest way to install sox is via Homebrew (https://brew.sh). Follow the instructions on the webpage then enter this in the terminal.
    –> “brew install sox”

    To get to the /usr/local/bin in Terminal
    –> “cd /usr/local/bin”

    To open it up in the Finder, because you can’t access it comfortably and want to drag the script there.
    –> open -a Finder /usr/local/bin

    Also, i can confirm, you need to add “//” before the g, as the first comment pointed out, your script will not work unless you do this

    Comment by Arjaan Auinger — August 3, 2017 @ 7:27 pm

  4. find * -type f -name “*.wav” | while read file; do
    is_silence=”$(sox $file -n stat 2>&1 | awk ‘/Maximum amplitude/ {print $NF}’| awk ‘{print ($1 < 0.1)}')"
    if [ "$is_silence" -eq "1" ]; then
    echo $file $is_silence
    fi
    done

    Comment by rafael — April 6, 2018 @ 4:48 pm

  5. Awesome, I was looking for this for a long time
    Thanks a lot

    We could even use “Volume adjustment” to say whether audio is silent.
    In my examples below I have 3 files in that 2 files are silent and one file has some audio, Volume adjustment is computed for the non silent file but for the other two Volume adjustment is not computed

    sox A2DP_record-3-ch4.wav -n stat
    Samples read: 480000
    Length (seconds): 10.000000
    Scaled by: 2147483647.0
    Maximum amplitude: 0.000000
    Minimum amplitude: 0.000000
    Midline amplitude: 0.000000
    Mean norm: 0.000000
    Mean amplitude: 0.000000
    RMS amplitude: 0.000000
    Maximum delta: 0.000000
    Minimum delta: 0.000000
    Mean delta: 0.000000
    RMS delta: 0.000000
    Rough frequency: -2147483648

    sox A2DP_record-2-ch4.wav -n stat
    Samples read: 480000
    Length (seconds): 10.000000
    Scaled by: 2147483647.0
    Maximum amplitude: 0.000000
    Minimum amplitude: 0.000000
    Midline amplitude: 0.000000
    Mean norm: 0.000000
    Mean amplitude: 0.000000
    RMS amplitude: 0.000000
    Maximum delta: 0.000000
    Minimum delta: 0.000000
    Mean delta: 0.000000
    RMS delta: 0.000000
    Rough frequency: -2147483648

    sox A2DP_record-6-ch4.wav -n stat
    Samples read: 480000
    Length (seconds): 10.000000
    Scaled by: 2147483647.0
    Maximum amplitude: 0.082489
    Minimum amplitude: -0.085480
    Midline amplitude: -0.001495
    Mean norm: 0.005193
    Mean amplitude: -0.000015
    RMS amplitude: 0.007801
    Maximum delta: 0.094940
    Minimum delta: 0.000000
    Mean delta: 0.003313
    RMS delta: 0.005821
    Rough frequency: 5700
    Volume adjustment: 11.699

    Comment by Prakasha — August 18, 2018 @ 2:40 am

  6. […] the script itself, I was lucky enough to find this blog post by David Hilowitz. His goal is the same as mine, deleting silent WAV files, but his execution is a bit different. I […]

    Pingback by Topslakr.com » Blog Archive » Behringer X-Live – Splitting 32 Channel WAV Files and Deleting Silence — March 11, 2020 @ 11:56 am

  7. Don’t suppose anyone can help with converting those find_silent_audio_files commands to a windows batch file?

    Comment by Bert — March 14, 2024 @ 8:00 pm

Leave a comment