Sox Command Examples - Audio Conversion & Manipulation

Explore Sox command examples for audio conversion and manipulation. Learn to merge, trim, normalize, reverse, change sample rate, generate sounds, and adjust volume with Sox.

Sox Command Examples

Sox (Sound eXchange) is a powerful command-line utility for playing, recording, and converting audio files. Its versatility makes it an essential tool for audio engineers, developers, and anyone working with sound. This page provides a collection of practical Sox command examples to help you perform common audio manipulation tasks efficiently.

Audio File Conversion and Merging

Sox identifies audio formats primarily by their file extensions. Here's how to merge multiple audio files into a single output file.

# Merge two audio files into one:
sox -m ${input_audiofile1} ${input_audiofile2} ${output_audiofile}

Trimming and Editing Audio

Precisely trim audio files to specific start and end times, ensuring you capture only the desired segments.

# Trim an audio file to the specified times:
sox ${input_audiofile} ${output_audiofile} trim ${start} ${end}

Volume and Normalization Control

Adjust the volume of your audio files. Normalization helps to ensure consistent loudness across different tracks by adjusting the volume to the maximum peak level without causing clipping.

# Normalize an audio file
# (adjust volume to the maximum peak level, without clipping):
sox --norm ${input_audiofile} ${output_audiofile}

# Increase the volume of an audio file by 2x:
sox -v 2.0 ${input_audiofile} ${output_audiofile}

Advanced Audio Transformations

Explore more advanced operations like reversing audio, changing sample rates, and converting mono to stereo.

# Reverse and save an audio file:
sox ${input_audiofile} ${output_audiofile} reverse

# Changing sample rate of a file
sox ${input_file} -r 16000 ${output_file}

# Changing the Number of Channels
# For example: convert mono audio files to stereo
sox ${mono_wav} -c 2 ${stereo_wav}

Sound Synthesis and Generation

Sox can generate various types of sounds from scratch, useful for creating sound effects or test tones.

# Generate Different Types of Sounds
# ${len} - length of audio to synthesize, hh:mm:ss.frac
# ${freq} - frequencies at the beginning/end of synthesis in Hz
# ${type} is one of sine, square, triangle, sawtooth, trapezium, exp,
#   [white]noise, pinknoise, brown-noise
# sox -n synth ${len} ${type} ${freq}
sox -r 8000 -n output.wav synth 3 sine 300-3300

Speed Adjustment

Modify the playback speed of an audio file without altering its pitch.

# Speed up the Sound in an Audio File
sox input.wav output.wav speed 2.0

Statistical Analysis

Gain insights into your audio files by printing statistical data.

# Print statistical data of an audio file:
sox ${input_audiofile} -n stat

These examples cover a range of common tasks. For more detailed information and advanced options, refer to the official Sox documentation.

External Resources: