Here’s another blog.

And another blog.

SoX

SoX stands for: Sound eXchange

http://sox.sourceforge.net/

Get Support for mp3 Files

https://packages.debian.org/wheezy/libsox-fmt-mp3

sudo apt-get install libsox-fmt-mp3; sudo apt-get upgrade sox

Maybe more simple mp3 support

sudo apt-get mp3info
# get time in seconds
for i in *mp3; do mp3info -p "%S" $i; echo ""; done

Convert Format

# very simple conversion
sox input.mp3 output.wav

Get Info about Files

# just one file
sox --i test.wav

# all files in dir
for i in *wav; do sox --i $i; done

Play Files (play is from sox)

# just one file
play text.wav

# all files in dir
for i in *wav; do play $i; done

Trim audio file

sox input output trim <start> <duration>

Downsample (to 16kHz)

# just one file
sox test.wav -r 16k test_16k.wav

# all files in dir
for i in *wav; do sox $i -r 16k ${i}_16k.wav; done

Merge Stereo Channels into One Mono

# just one file
sox test.wav test_mono_merged.wav remix 1,2

# all files in dir
for i in *wav; do sox $i ${i}_mono_merged.wav remix 1,2; done

Split file on silence

sox file.mp3 file_new_.mp3 silence -l 1 0.0 -40d 1 1.1 -40d : newfile : restart

SoXI

SoXI stands for: Sound eXchange Information.

SoXI will display sound file metadata.

http://sox.sourceforge.net/soxi.html#DESCRIPTION

Displays information from the header of a given audio file or files. Supported audio file types are listed and described in soxformat(7). Note however, that soxi is intended for use only with audio files with a self-describing header.

Get Duration of Audio Files

# just one file
soxi -D text.wav

# all files in dir
for i in *wav; do soxi -D $i; done

Calculate Combined Duration of all WAV Files in dir

OUTPUT="$(for i in *wav; do soxi -D $i; done)";
echo "${OUTPUT}"

## get total number of seconds of WAVs in dir
TOTAL_SECS=0
for i in *wav; do      
    SECS="$(soxi -D $i)"
    TOTAL_SECS=$(echo "$TOTAL_SECS + $SECS" | bc)
    done
printf "\n\nThere are a total of ${TOTAL_SECS}
       seconds of WAV files in the dir\n\n"