Install SoX with vorbis from source

Install SoX in a Ubuntu computer with ‘Sudo’ privileges is fast and easy. A simple sudo apt install sox will do the job.
But, do it in a computer without sudo needs more steps, specially if is needed to handle FLAC or OGG Vorbis files.

The following steps will install SoX from source with OGG Vorbis libraries.

1- Install libogg
2- Install libvorbis
3- Install SoX

Install libogg

Download libogg installer from

 ./configure --prefix=$HOME/apps/libogg \
 make install

Install libvorbis

Download libvorbis from

 ./configure --prefix=$HOME/apps/libvorbis 
 make install

Install SoX

Download SoX from

 ./configure --prefix=$HOME/apps/sox 
             LIBS="-L$HOME/apps/libogg/lib -L$HOME/apps/libvorbis/lib" 
             CPPFLAGS="-I$HOME/apps/libogg/include -I$HOME/apps/libvorbis/include"
 make install

Working with SoX


 sox input.wav -r 16000 output.wav

Remix Stereo to Mono

 sox input.wav output.wav remix 1,2

Change Volume

 sox -v FACTOR input.wav output.wav
 # or
 sox --volume FACTOR input.wav output.wav

# In volume pertutbance in Kaldi
sox --vol FACTOR -t wav input -t wav  output

Change Speed

 sox -t wav input.wav -t wav output.wav speed FACTOR 

Trim audio

 sox -t wav input.wav -t wav output.wav trim START DURATION

Pipe command

The following command downsample to 16K and remix to MONO. Then slow down the speed to 90% of the original. Then change volume To finally use trim to extract 10.82 seconds of audio starting at 125.34 seconds.

Note that the input and output are indicated as - in the pipe

 sox input.m4a -G -t wav -r 16000 - remix 1,2  | sox -t wav - -t wav - speed 0.9 sox --vol 0.316 -t wav - -t wav - | sox -t wav - -t wav output.wav trim 125.34 10.82