Sound eXchange (SoX) is the Swiss Army knife of sound processing programs. It is a cross-platform command line utility that can convert various formats of computer audio files into other formats. It can also apply various effects to these sound files as well as do recording and playback.
This lesson will list many sox
examples as well as other related audio commands.
- Install
- Record
- Play
- Effects
- Combine
- Volume
- Extract
- Noise Removal
- Trim Silence
- Split by Silence
- Reverse
- Normalize
- Convert to Stereo
- Convert to Mono
- Change Sample Rate
- Change Sample Size
- Raw to Wav
- Wav to MP3
- MP3 to Wav
- Info
- Spectrogram
- Waveforms
- Batch
Install
sudo apt-get install sox mpv ffmpeg lame mplayer
Record
sox -t alsa default test.wav
sox -t ossdsp /dev/dsp test.wav (for some)
rec test.wav
rec test.wav trim 0 30:00
rec -r 8000 -c 1 test.wav
Play
play test.wav
play test.wav speed 0.5
mplayer test.wav
mplayer test.mp3
mpv test.wav
mpv test.mp3
Effects
allpass, band, bandpass, bandreject, bass, bend, biquad, channels, chorus, compand, contrast, dcshift, deemph, delay, dither, downsample, earwax, echo, echos, equalizer, fade, fir, flanger, gain, highpass, hilbert, ladspa, loudness, lowpass, mcompand, noiseprof, noisered, norm, oops, overdrive, pad, phaser, pitch, rate, remix, repeat, reverb, reverse, riaa, silence, sinc, spectrogram, speed, splice, stat, stats, swap, stretch, synth, tempo, treble, tremolo, trim, upsample, vad, vol
Combine
sox -m first_part.wav second_part.wav whole_part.wav
sox --combine mix countdown.mp3 intro.ogg output.flac (at same time)
Volume
sox -v -0.5 srcfile.wav dstfile.wav
Extract
sox input.wav output.wav trim 0 10 (location, duration)
Noise Removal
sox foo.wav -t nul /dev/null trim 0 0.5 noiseprof profile
play foo.wav noisered profile
Trim Silence
sox infile.wav outfile.wav silence 1 0.1 1% (beginning)
sox infile.wav outfile.wav silence 1 0.1 1% 1 0.1 1% (beginning and end)
sox in.wav out.wav silence 1 0.1 1% -1 0.1 1% (middle)
sox in.wav out.wav silence -l 1 0.1 1% -1 2.0 1% (trims long silence)
play speech.wav vad (beginning)
play speech.wav vad reverse vad reverse (beginning and end)
Split By Silence
sox in.wav out.wav silence 1 0.5 1% 1 5.0 1% : newfile : restart
Reverse
play test.wav reverse
Normalize
sox in.wav out.wav norm
for file in *.wav; do sox "$file" "n_$file" norm -0.1; done
Convert to Stereo
sox mono.wav -c 2 stereo.wav
Convert to Mono
sox stereo.wav mono.wav channels 1
sox stereo.wav -c 1 mono.wav avg -l
sox stereo.wav -c 1 mono.wav avg
for file in *.wav; do sox "$file" "mono_$file" channels 1; done
Change Sample Rate
sox in.wav out.wav rate 48k (8k, 11.025k, 16k, 22.05k, 32k, 37.8k, 44.056k, 44.1k, 47.25k, 48k, 50k, 50.4k, 64k, 88.2k, 96k, 176.4k, 192k, 352.8k, 2822.4k, 5644.8k, 11289.6k, 22579.2k)
for file in *.wav; do sox "$file" "48khz_$file" rate 48k; done
Change Sample Size
sox in.wav -b 16 out.wav
for file in *.wav; do sox "$file" -b 16 "16bit_$file"; done
Raw to Wav
sox -c 2 -r 8000 audio1.raw audio1.wav
sox -w -c 2 -r 8000 audio1.raw audio1.wav (-w not recognized)
Wav to MP3
ffmpeg -i foo.wav foo.mp3
lame -h audio1.wav audio1.mp3
mplayer audio1.mp3
MP3 to Wav
ffmpeg -i foo.mp3 foo.wav
Info
soxi test.wav
soxi *.wav > database.csv
sox inputFile.wav -n stat
Spectrogram
sox input.wav -n spectrogram -t "top label" -c "corner label" -o inputFileName.png
Waveforms
ffmpeg -i inputFile.wav -lavfi showwavespic=split_channels=1:s=1024x800 outputWaveform.png
Batch
for file in *.wav; do sox "$file" "n_$file" norm -0.1; done