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 http://www.linuxfromscratch.org/blfs/view/cvs/multimedia/libogg.html

 ./configure --prefix=$HOME/apps/libogg \
             --disable-static 
             --docdir=$HOME/apps/libogg/share/doc/libogg-1.3.3
 make
 make install

Install libvorbis

Download libvorbis from http://www.linuxfromscratch.org/blfs/view/cvs/multimedia/libvorbis.html

 ./configure --prefix=$HOME/apps/libvorbis 
             --disable-static 
             --with-ogg-libraries=$HOME/apps/libogg/lib 
             --with-ogg-includes=$HOME/apps/libogg/include
 make
 make install

Install SoX

Download SoX from http://sox.sourceforge.net/

 ./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
 make install
            

Working with SoX

Downsample

 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