Question

I have a set of stereo .AIFF piano samples from http://theremin.music.uiowa.edu/MISpiano.html

Each sample is preceded by ~5 sec silence, and fades into ~30 seconds of silence; i.e. it continues well below the threshold of my hearing.

I wish to trim both ends. This will involve fading out, so as to avoid a sharp discontinuity.

Furthermore I am only interested in the left channel.

How can I accomplish this from my OS X terminal?

π

PS hold your horses, I'm going to answer this one myself :)

Was it helpful?

Solution

Here we go:

for filePath in IN/*.aiff
do
    # Trim silence both ends
    #   http://digitalcardboard.com/blog/2009/08/25/the-sox-of-silence/
    ./sox $filePath ./TMP/1_trim.wav silence 1 0.1 1%  1 0.1 0.5%

    # LEFT channel
    #   https://www.nesono.com/node/275
    ./sox TMP/1_trim.wav ./TMP/2_mono.wav remix 1


    # Get length (seconds)
    #   http://stackoverflow.com/questions/4534372/get-length-of-wav-from-sox-output
    #     file_length=`./sox ./TMP/2_mono.wav 2>&1 -n stat | grep Length | cut -d : -f 2 | cut -f 1`
    file_length=`./soxi -D ./TMP/2_mono.wav`

    # amount to truncate
    trunc=$(echo "$file_length*0.75" | bc -l)

    #   http://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash
   filename=$(basename "$filePath")

    # fade out
    #   http://www.benmcdowell.com/blog/2012/01/29/batch-processing-audio-file-cleanup-with-sox/
    ./sox ./TMP/2_mono.wav ./OUT/$filename fade t 0 $file_length $trunc
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top