bash script to remove silent PCM files

When you have a lot of input channels coming into your DAW, arming channels individually for recording can be a real pain. It’s much easier to just arm them all and remove any wave files for channels that didn’t record anything useful. Well, it is if you have some automated way to go through and remove them.

I’ve made a simple bash script to deal with this. It depends on sox. Its options are:

  • -d debug mode: actions are listed but not carried out
  • -v verbose mode: actions are carried out and listed
  • -l list mode: files that will be deleted are listed, surrounded by single quotes. This allows the list to sent to xargs for example, to open in an audio editor to double check if there’s anything worth keeping.
  • -t THRESHOLD set the threshold below which a PCM file is considered silent
  • INPUT list of files to check for silence

The script also removes any zero-length files.

I would try it a few times with the -d switch to see what would be deleted. The default threshold of 0.0001 will most likely let through some files with just background noise on them, so you might want to increase it. I often use 0.0005 which almost certainly wouldn’t delete anything useful.

Using the -d switch also shows the size of the file that would be deleted.

You can run it with the -l switch and xargs to find out how much space you’re saving:

$ silentpcmrm -l *aif | xargs du -hcs
93M    Anode POST 0001 [2020-04-26 122446].aif
96M    Anode PRE 0004 [2020-04-26 122446].aif
96M    Clap POST 0001 [2020-04-26 122446].aif
96M    Clap PRE 0004 [2020-04-26 122446].aif
192M    D-20 POST 0001 [2020-04-26 122446].aif
190M    D-20 PRE 0005 [2020-04-26 122446].aif
96M    DK-80 POST 0001 [2020-04-26 122446].aif
96M    DK-80 PRE 0003 [2020-04-26 122446].aif
96M    Microbrute POST 0001 [2020-04-26 122446].aif
96M    Microbrute PRE 0004 [2020-04-26 122446].aif
96M    Minilogue POST 0001 [2020-04-26 122446].aif
192M    Patchblock POST 0001 [2020-04-26 122446].aif
96M    Snare POST 0001 [2020-04-26 122446].aif
96M    Snare PRE 0004 [2020-04-26 122446].aif
96M    Volca Bass POST 0001 [2020-04-26 122446].aif
93M    Volca FM POST 0001 [2020-04-26 122446].aif
96M    Volca FM PRE 0003 [2020-04-26 122446].aif
185M    Zoom B3n PRE 0001 [2020-04-26 122446].aif
2.0G    total

I use this for my setup which is 48 channels coming into Ableton Live, so selecting 10 or 12 channels to arm is super fiddly, especially when you don’t have the computer as a central part of the workflow – it’s more like a 48-track tape machine in the corner. It’s very easy to accidentally not arm one of the tracks you later need – I record each instrument both PRE and POST so that I have all the effects and live fader/muting messing. If for some reason you come back to mix the track and find that there was too much delay (what?!) or you muted the channel too early, the PRE version lets you fix it. Or you can use the POST channels as a guide to how you later use the PRE channels to mix from the untouched source.

The script is provided as-is, and how you use it is up to you, and at your own risk. Back up files before running anything that can and will delete them!

Update: file has moved to GitHub repo