Editing Multiple Mono Sound Files in SoX

with No Comments

The command listed below enables you to carry out the following processes to a batch of mono sound files:

  • Normalize the sound file to -3 dBFS.
  • Trim the audio at the beginning of the sound file up to the point where the amplitude level is greater than 1% (i.e., -40dBFS) for longer than 0.1s (100ms). Note: when it detects a signal that exceeds 1% for more than 0.1s, it trims up to the start of that time-frame.
  • Apply a 10ms linear fade in.
  • Reverse the sound file.
  • Trim the audio at the beginning of the sound file again, but up to the point where the amplitude level is greater than 0.2% (i.e., -54dBFS) for longer than 0.1s (100ms). Note: similar to the earlier trimming step, it trims up to the start of the time-frame where the level exceeds 0.2% for 0.1s.
  • Apply a 2s linear fade in.
  • Reverse the sound file again.

Note: This example assumes that the audio files you want to edit are in your home folder (you can always change directories with the cd command). Also, be sure that you use the correct audio format suffix. In the example below I use .aif. Just edit the command according to what you have.

for i in *.aif; do sox -S "${i}" "NormTrimFade_${i}" gain -n -3 silence 1 0.1 1% fade t 0:0:0.01t reverse silence 1 0.1 0.2% fade t 0:0:2t reverse; done

Note: This method trims off the beginning silence and applies a fade in; it then reverses the file and repeats the process; finally, it reverses the file back to normal. This approach ensures that the silence at the end is more reliably trimmed off. Also, it avoids the error “audio length is neither known nor given” that would result from attempting to fade in and out with a single fade effect (because the file length changes within the process of this single command).

See:
How to install and use Sound eXchange (SoX).
How to convert amplitude representations.
More info on using the “silence” effect in SoX (external link).
Info on different fade shapes (external link).

Leave a Reply