SoX – Sound eXchange ubuntu commands

SoX is a cross-platform (Windows, Linux, MacOS X, etc.) command line utility that can convert various formats of computer audio files in to other formats. It can also apply various effects to these sound files, and, as an added bonus, SoX can play and record audio files on most platforms.

The screen-shot to the right shows an example of SoX first being used to process some audio, then being used to play some audio files.

10 Awesome Examples to Manipulate Audio Files Using Sound eXchange (SoX)

1. Combine Multiple Audio Files to Single File

using sox -m command mix the two audio file using terminal

$ sox -m first_part.wav second_part.wav whole_part.wav


$ soxmix first_part.wav second_part.wav whole_part.wav

2. Extract Part of the Audio File

Trim can trim off unwanted audio from the audio file. and set the custome starting and end time.

$ sox old.wav new.wav trim [SECOND TO START] [SECONDS DURATION].

  • SECOND TO START – Starting point in the voice file.
  • SECONDS DURATION – Duration of voice file to remove

The command below will extract first 15 seconds from input.wav and stored it in output.wav

$ sox input.wav output.wav trim 0 10

3. Increase and Decrease Volume Using Option -v

Option -v is used to change (increase or decrease ) the volume.

increase volume : –

$ sox -v 2.0 foo.wav bar.wav

decrease volume : –

$ sox -v -0.5 srcfile.wav test05.wav

$ sox -v -0.1 srcfile.wav test01.wav

4. Play an Audio Song

Sox provides the option for playing and recording sound files. This example explains how to play an audio file on Unix, Linux.

Syntax :play options Filename audio_effects

$ play -r 8000 -w music.wav

5. Play an Audio Song Backwards

Use the ‘reverse’ effect to reverse the sound in a sound file. This will reverse the file and store the result in output.wav

$ sox input.wav output.wav reverse

You can also use play command to hear the song in reverse without modifying the source file as shown below.

$ play test.wav reverse

6. Record a Voice File

You can also use rec command for recording voice. If SoX is invoked as ‘rec’ the default sound device is used as an input source.

$ rec -r 8000 -c 1 record_voice.wav

7. Changing the Sampling Rate of a Sound File

To change the sampling rate of a sound file, use option -r followed by the sample rate to use, in Hertz. Use the following example, to change the sampling rate of file ‘old.wav’ to 16000 Hz, and write the output to ‘new.wav’

$ sox old.wav -r 16000 new.wav

8. Changing the Sampling Size of a Sound File

If we increase the sampling size , we will get better quality. Sample Size for audio is most often expressed as 8 bits or 16 bits. 8bit audio is more often used for voice recording.

-b Sample data size in bytes
-w Sample data size in words
-l Sample data size in long words
-d Sample data size in double long words

$ sox -b input.wav -w output.wav

9. Changing the Number of Channels

The following example converts mono audio files to stereo.  Use Option -c to specify the number of channels .

$ sox stereo.wav -c 1 mono.wav avg -l

10. Speed up the Sound in an Audio File

To speed up or slow down the sound of a file, use speed to modify the pitch and the duration of the file. This raises the speed and reduces the time. The default factor is 1.0 which makes no change to the audio. 2.0 doubles speed, thus time length is cut by a half and pitch is one interval higher.

Syntax: sox input.wav output.wav speed factor

$ sox input.wav output.wav speed 2.0

Happy coding ..


Leave a Reply

Your email address will not be published. Required fields are marked *