Skip to content

Instantly share code, notes, and snippets.

@ideoforms
Last active February 23, 2024 02:08
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save ideoforms/d64143e2bad16b18de6e97b91de494fd to your computer and use it in GitHub Desktop.
Save ideoforms/d64143e2bad16b18de6e97b91de494fd to your computer and use it in GitHub Desktop.
sox cheat sheet
################################################################################
# sox cheat sheet
################################################################################
# Example commands for the sox command-line audio processing tool,
# for manipulating or batch processing audio files.
################################################################################
# Daniel Jones <dan-web@erase.net>
################################################################################
################################################################################
#### GENERAL USAGE AND HELP
################################################################################
# General usage.
sox [general_flags] [input_flags][infile] [output_flags][outfile] [effects...]
# Get help.
sox
# Deeper commentary on each function and effect.
man sox
# Help on arguments for a particular effect.
sox --help-effect reverb
################################################################################
#### GETTING INFORMATION
################################################################################
# Display general information (samplerate, bit depth, duration, ...)
sox --info input.wav
soxi input.wav
# Process the audio contents to calculate properties such as RMS.
sox input.wav -n stats
################################################################################
#### CONVERTING BETWEEN FILE FORMATS
################################################################################
# sox automatically infers file type from the extension.
# Convert to 8kHz, 1-channel wav.
sox input.wav -r 8000 -c 1 output.wav
# Convert to mp3.
sox input.wav output.mp3
# Convert to mp3 with specified bitrate in kbps.
sox input.wav -C 256 output.mp3
# Convert from a .raw file of known format to a wav file.
sox -r 44100 -e signed-integer -b 16 raw-audio.raw raw-audio.wav
################################################################################
#### SYNTHESIZING AUDIO
################################################################################
# Generate 1 second of white noise.
sox -n output.wav synth 1 noise
# Generate 1 second of pink noise.
sox -n output.wav synth 1 pinknoise
# Generate a 1-second sine tone.
sox -n output.wav synth 1 sine 440
# Generate a 10-second exponential sine sweep
sox -n -r 44100 sine-sweep.wav synth 10 sine 40/20000
# Generate a Dirac impulse, padded to 1 second
sox -n -r 44100 impulse.wav synth 1s square pad 0 44099s
################################################################################
#### PLAYING AUDIO
################################################################################
# Play an audio file through the default system audio output.
play input.wav
# Attenuate audio playback
play input.wav gain -12
# Play synthesized audio.
play -n synth sine 440 trim 0 1 gain -12
################################################################################
#### COMBINING AUDIO
################################################################################
# Combine two files by concatenation.
sox a.wav b.wav c.wav concatenated.wav
# Combine two files by mixing their contents.
sox -m a.wav b.wav c.wav mixed.wav
# Merge two mono files into a two-channel stereo file
sox -M left.wav right.wav stereo.wav
################################################################################
#### MODIFYING AUDIO
################################################################################
# Reduce level by 12dB
sox speech.wav output.wav gain -12
# Crop to the first 1 second of the file.
sox speech.wav output.wav trim 0 1
# Reverse the contents.
sox speech.wav output.wav reverse
# Normalise the contents to 0dBFS.
sox speech.wav output.wav norm
# Equaliser (-6dB @ 100Hz, -24dB @ 8000Hz)
sox speech.wav output.wav bass -6 100 treble -24 8000
# Add room modelling reverb.
sox speech.wav output.wav reverb 50 50 100
# Trim digital silence from start and end.
sox input.wav trimmed/output.wav silence 1 0.1 0 1 0.1 0
# Extract one channel from a multichannel file (numbering is from 1)
sox stereo.wav right.wav remix 2
# Extract the first, third and fifth channels from a multichannel file
sox multichannel.wav subset.wav remix 1 3 5
################################################################################
#### VISUALISATION
################################################################################
# Generate a spectrogram (output to spectrogram.png)
sox speech.wav -n spectrogram
@rubyFeedback
Copy link

Very nice list. The more examples the merrier!

@Gahlord
Copy link

Gahlord commented Apr 27, 2023

You are my hero. Thank you for making this!

@ed-xmos
Copy link

ed-xmos commented Aug 21, 2023

I love sox, but the options are hard to fathom. This is VERY helpful - Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment