SOX_NG(1)

๐Ÿ’– SOX_NG(1) โ€” Sound eXchange_ng ๐Ÿ’–

๐ŸŒธ NAME ๐ŸŒธ

sox_ng โ€” Sound eXchange_ng, another Swiss Army knife of audio manipulation. Like, the audio multitool bestie. ๐ŸŽ€

โœจ SYNOPSIS โœจ

sox_ng [global-options] [format-options] infile1
     [[format-options] infile2] ... [format-options] outfile
     [effect [effect-options]] ...

play_ng [global-options] [format-options] infile1
     [[format-options] infile2] ... [format-options]
     [effect [effect-options]] ...

rec_ng [global-options] [format-options] outfile
     [effect [effect-options]] ...

๐ŸŽ€ DESCRIPTION ๐ŸŽ€

๐Ÿฆ‹ Introduction ๐Ÿฆ‹

SoX reads and writes audio files in most popular formats and can optionally apply effects to them. It can combine multiple input sources, synthesize audio and, on many systems, act as a general purpose audio player or as a multitrack audio recorder. It can also split the input into multiple output files.

All SoX functionality is available using just the sox_ng command. To simplify playing and recording audio, if SoX is invoked as play_ng, the output file is automatically set to be the default sound device and, if invoked as rec_ng, the default sound device is used as an input source. Additionally, the soxi_ng command provides a convenient way to query audio file header information.

The heart of SoX is a library called libsox_ng. Those interested in extending SoX or using it in other programs should refer to the libsox_ng manual page.

SoX is a command-line audio processing tool particularly suited to making quick, simple edits and to batch processing. If you need an interactive, graphical audio editor, use audacity(1).


The overall SoX processing chain can be summarized as follows:

Input(s) โ†’ Combiner โ†’ Effects โ†’ Output(s)

On the SoX command line, the positions of the Output(s) and the Effects are swapped w.r.t. the logical flow just shown and, while options pertaining to files are placed before their respective file names, the opposite is true for effects. To show how this works in practice, here is a selection of examples of how SoX might be used. The simple

sox_ng recital.au recital.wav

translates an audio file in Sun AU format to a Microsoft WAV file, while

sox_ng recital.au -b 16 recital.wav channels 1 rate 16k fade 3 norm

performs the same format translation but also applies four effects (down-mix to one channel, sample rate change, fade in and normalize) and stores the result at a bit-depth of 16.

sox_ng -r 16k -e signed -b 8 -c 1 voice-memo.raw voice-memo.wav

converts raw (a.k.a. headerless) audio to a self-describing file format,

sox_ng slow.aiff fixed.aiff speed 1.027

adjusts audio speed,

sox_ng short.wav long.wav longer.wav

concatenates two audio files and

sox_ng -m music.mp3 voice.wav mixed.flac

mixes together two audio files.

play_ng "The Moonbeams/Greatest/*.ogg" bass +3

plays a collection of audio files applying a bass boosting effect,

play_ng -n -c1 synth sin %-12 sin %-9 sin %-5 sin %-2 fade h 0.1 1 0.1

plays a synthesized A minor seventh chord with a pipe organ sound,

rec_ng -c 2 radio.aiff trim 0 30:00

records half an hour of stereo audio and

play_ng -q take1.aiff & rec -M take1.aiff take1-dub.aiff

(with a POSIX shell and where supported by hardware) records a new track in a multitrack recording. Finally,

rec_ng -r 44100 -b 16 -e signed-integer -p \
  silence 1 0.50 0.1% 1 10:00 0.1% | \
  sox_ng -p song.ogg silence 1 0.50 0.1% 1 2.0 0.1% : \
  newfile : restart

records a stream of audio such as an LP or cassette and splits it into multiple audio files at points where there are two seconds of silence. Also, it does not start recording until it detects some sound and stops after it sees ten minutes of silence.

The above is just an overview of SoX's capabilities. Detailed explanations of how to use all SoX parameters, file formats and effects can be found below in this manual, in soxformat_ng(7) and in soxi_ng(1).

๐ŸŒˆ File Format Types ๐ŸŒˆ

SoX can work with self-describing and raw audio files. Self-describing formats (e.g. WAV, FLAC, MP3) have a header that completely describes the signal and encoding attributes of the audio data that follows. raw or headerless formats do not contain this information, so the audio characteristics of these must be described on the SoX command line, except for a few which can be inferred from the filename extension such as .gsm, always -c1 -r8000 -e gsm, and named raw formats like .f32, .s16 and .ul which give the encoding but not the sample rate or number of channels.

The following four characteristics are used to describe the format of audio data:

  • sample rate โ€” The sample rate in samples per second (Hertz or Hz). Digital telephony traditionally uses a sample rate of 8000Hz (8kHz) though 16 and even 32kHz are becoming more common. Audio Compact Discs use 44100Hz (44.1kHz), Digital Audio Tape and many computer systems use 48kHz and professional audio systems often use 96kHz.
  • sample size โ€” The number of bits used to store each sample. Today, 16-bit is commonly used, 8-bit was popular in the early days of computer audio and 24-bit is used in the professional audio arena.
  • data encoding โ€” The way in which each audio sample is represented (or encoded). Some encodings have variants with different byte-orderings or bit-orderings, some compress the audio data so that it takes up less disk space or transmission bandwidth than uncompressed formats. Commonly-used encoding types include floating point, ฮผ-law, ADPCM, signed-integer PCM, MP3 and FLAC.
  • channels โ€” The number of audio channels contained in the file. One (mono) and two (stereo) are widely used and surround sound audio typically contains six or more channels.

The term bit rate is a measure of the amount of storage occupied by an encoded audio signal per unit of time. It can depend on all of the above and is typically denoted as a number of kilobits per second (kbps). An A-law telephony signal has a bit rate of 64 kbps, MP3-encoded stereo music typically has a bit rate of 128-196 kbps and FLAC-encoded stereo music typically has a bit rate of 550-760 kbps.

Most self-describing formats also allow textual comments to be embedded in the file that can be used to describe the audio in some way, e.g. for music, the title, the author, etc.

One important use of audio file comments is to convey Replay Gain information. SoX can apply Replay Gain automatically for formats that contain comments but does not generate it. By default, SoX copies comments from the first input file to output files that support comments, so output files may contain Replay Gain information which is incorrect. This can be fixed, when converting input files with --replay-gain enabled, by removing all comments using --comment "" or removing just the REPLAYGAIN comment with

soxi_ng -a in.au | grep -v REPLAYGAIN > comments
sox_ng --replay-gain=track in.au --comment-file comments out.au

๐Ÿงš Determining and setting the File Format ๐Ÿงš

SoX uses several mechanisms to determine or set the format of an audio file. Depending on the circumstances, individual characteristics may be determined or set using different mechanisms.

To determine the format of an input file, SoX uses, in order of precedence and as given or available:

  1. Command-line format options,
  2. The contents of the file header,
  3. The filename extension.

To set the output file format, SoX uses, in order of precedence and as given or available:

  1. Command-line format options,
  2. The filename extension,
  3. The input file format characteristics or the closest that is supported by the output file type.

For all files, SoX exits with an error if the file type cannot be determined. Command-line format options may need to be added or changed to resolve the problem.

๐ŸŽง Playing & Recording Audio ๐ŸŽง

The play_ng and rec_ng commands are provided so that basic playing and recording is as simple as

play_ng existing-file.wav

and

rec_ng new-file.wav

These two commands are functionally equivalent to

sox_ng existing-file.wav -d

and

sox_ng -d new-file.wav

Further options and effects (as described below) can be added to the commands in either form.


When playing a file with a sample rate that is not supported by the audio output device, SoX automatically invokes the rate effect to perform the necessary sample rate conversion. For compatibility with old hardware, the default rate quality level is set to low. This can be changed by explicitly specifying the rate effect with a different quality level, e.g.

play_ng ... rate -m

or by using the --play-rate-arg option (see below).


On some systems, SoX allows the audio playback volume to be adjusted while using play_ng. Where supported, this is achieved by tapping the v & V keys during playback. If there is a softvol effect in the chain, these keys will adjust that instead of the hardware mixer.

To help with setting a suitable recording level, SoX includes a peak level meter which can be invoked (before making the actual recording) as follows:

rec_ng -n

The recording level should be adjusted (using the system-provided mixer program, not SoX) so that the meter is, at most, occasionally full scale and never in the red (an exclamation mark is shown). See the -S (--show-progress) option below.

๐Ÿ’œ Accuracy ๐Ÿ’œ

Many file formats that compress audio discard some of the audio signal information. Converting to such a format and back again will not produce an exact copy of the original audio. This is the case for many formats used in telephony (e.g. A-law, GSM) where low signal bandwidth is more important than high audio fidelity and for formats used in portable music players (e.g. MP3, Ogg Vorbis) where adequate fidelity can be retained even with the large compression ratios that are needed to make portable players practical.

Formats that discard audio signal information are called lossy. Formats that do not are called lossless. The term quality is used as a measure of how closely the original audio signal is reproduced when using a lossy format.

okay so real talk about lossless conversion: SoX conversion is lossless when it can be โ€” i.e. when you're not using lossy compression, when you're not reducing the sampling rate or the number of channels, and when the number of bits used in the destination format is not less than in the source format. For example, converting from an 8-bit PCM format to a 16-bit PCM format is lossless, but converting from an 8-bit PCM format to (8-bit) A-law isn't. ๐Ÿ’…

SoX converts all audio files to an internal, uncompressed 32-bit format before doing any audio processing. That means manipulating a file stored in a lossy format can cause further losses in audio fidelity. E.g. with

sox_ng long.mp3 short.mp3 trim 10

SoX first decompresses the input MP3 file, then applies the trim effect, and finally creates the output MP3 file by recompressing the audio โ€” with a possible reduction in fidelity on top of whatever loss already happened when the input file was created. Hence, if what you ultimately want is lossily compressed audio, it's best to perform all audio processing using lossless file formats and then convert to the lossy format only at the final stage. Applying multiple effects with a single SoX invocation will, in general, produce more accurate results than multiple separate SoX invocations. โœจ

Dithering ๐Ÿ’–

Dithering is a technique used to maximize the dynamic range of audio stored at a particular bit-depth. Any distortion introduced by quantization is decorrelated by adding a small amount of white noise to the signal. In most cases, SoX can determine whether the selected processing requires dither and will add it during output formatting if appropriate. ๐Ÿซถ

By default, SoX automatically adds TPDF dither when the output bit-depth is less than 24 and any of the following are true:

  • bit-depth reduction has been specified explicitly using a command-line option
  • the output file format supports only bit-depths lower than that of the input file format
  • an effect has increased the effective bit-depth within the internal processing chain

For example, adjusting the volume with vol 0.25 requires two additional bits in which to losslessly store its results (since 0.25 decimal equals 0.01 binary), so if the input file bit-depth is 16, SoX's internal representation will use 18 bits after processing this volume change. In order to store the output at the same depth as the input, dithering is used to remove the additional bits. ๐Ÿฆ‹

Use the -V option to see what processing SoX has automatically added. The -D (--no-dither) option may be given to override automatic dithering. To invoke dithering manually (e.g. to select a noise-shaping curve), use the dither effect. ๐ŸŽ€

Clipping ๐Ÿ”ฅ

Clipping is distortion that occurs when an audio signal level (or volume) exceeds the range of the chosen representation. In most cases, clipping is undesirable, so it should be corrected by adjusting the level prior to the point in the processing chain at which it occurs. ๐Ÿ˜ญ

In SoX, clipping can happen when using the vol or gain effects to increase the audio volume. Clipping can also occur with many other effects, when converting one format to another, and even when simply playing the audio. ๐Ÿ’€

Playing an audio file often involves resampling and processing by analog components, and that can introduce a DC offset or amplification โ€” all of which can produce distortion if the audio signal level was initially too close to the clipping point. ๐Ÿ™ˆ

For these reasons, it's usual to make sure that an audio file's signal level has some headroom, i.e. it does not exceed a particular level below the maximum possible level of the given representation. Some standards bodies recommend as much as 9dB headroom, but in most cases, 3dB (โ‰ˆ 70% linear) is enough. Note that this wisdom seems to have been lost in modern music production; in fact, many CDs, MP3s, etc. are now mastered at levels above 0dBFS and the audio is clipped as delivered. ๐Ÿ‘‘

SoX's stat and stats effects can assist in determining the signal level of an audio file. The gain or vol effect can be used to prevent clipping, e.g.

sox_ng dull.wav bright.wav gain -6 treble +6

guarantees that the treble boost will not clip. ๐ŸŒˆ

If clipping occurs at any point during processing, SoX displays a warning message to that effect. โญ

See the global -G (--guard) option and the gain and norm effects.

Input File Combining ๐Ÿ’œ

SoX's input combiner can be configured with the --combine global option to combine multiple files using one of the following methods: concatenate, sequence, mix, mix-power, merge and multiply, with shorthands -m for --combine mix, -M for merge and -T for multiply. ๐Ÿงš

The default is sequence for play_ng, and concatenate for sox_ng. ๐Ÿ’–

For methods other than sequence, multiple input files must have the same sampling rate. If necessary, separate SoX invocations can be used to make sampling rate adjustments prior to combining them. And, with concatenate, the input files must also have the same number of channels. ๐Ÿฆ‹

The sequence combining method is similar to concatenate in that the audio from each input file is sent serially to the output file, but here, the output file may be closed and reopened at the transition between input files. This may be just what is needed when sending different types of audio to an output device, but is not generally useful when the output is a normal file. โœจ

With the mix or mix-power combining methods, the number of channels in each input file need not be the same, but SoX issues a warning if they are not, and some channels in the output file will not contain audio from every input file. A mixed audio file cannot be unmixed without reference to the original input files. ๐Ÿ˜ญ

If the merge combining method is selected, the number of channels in each input file need not be the same, and a merged audio file comprises all channels from all the input files โ€” and unmerging is possible using multiple invocations of SoX with the remix effect. For example, two mono files could be merged to form one stereo file, and the first and second mono files would become the left and right channels of the stereo file. ๐ŸŽ€

The multiply combining method multiplies the sample values of corresponding channels treated as numbers in the interval -1 to +1. If the number of channels in the input files is not the same, the missing channels will contain silence. ๐Ÿ’…

When combining input files, SoX applies any specified effects (including, for example, the vol volume adjustment effect) after the audio has been combined. However, it's often useful to be able to set the volume of the inputs individually (i.e. balance them) before combining takes place. For all combining methods, input file volume adjustments can be made manually using the -v option, which can be given for one or more input files. If it is given for only some of the input files, the others receive no volume adjustment. In some circumstances, automatic volume adjustments may be applied. The global -V option can be used to show the input file volume adjustments that have been selected manually or automatically. ๐Ÿซถ

Some special considerations need to be made when mixing input files:

Unlike the other methods, mix combining can cause clipping in the combiner if no balancing is performed. In this case, if manual volume adjustments are not given, SoX tries to ensure that clipping does not occur by automatically adjusting the volume (amplitude) of each input signal by a factor of ยน/n, where n is the number of input files. If this results in audio that is too quiet or otherwise unbalanced, the input file volumes can be set manually with -v. Using the norm effect on the mix is another alternative. ๐ŸŒธ

If mixed audio seems loud enough at some points but too quiet in others, dynamic range compression can be applied to correct this โ€” see the compand effect. ๐Ÿ”ฅ

With the mix-power combine method, the mixed volume is approximately equal to that of one of the input signals. This is achieved by balancing using a factor of ยน/โˆšn instead of ยน/n. Note that this balancing factor does not guarantee that clipping will not occur, but the number of clips will usually be low and the resulting distortion is usually imperceptible. ๐Ÿ’œ

Output Files ๐Ÿ‘‘

SoX's default behaviour is to take one or more input files and write them to a single output file. ๐ŸŒŸ

This behaviour can be changed by placing the newfile pseudo-effect within the effects list, and SoX will enter multiple output mode. ๐Ÿฆ‹

In multiple output mode, a new file is created when the effects prior to the newfile indicate that they are done. The effects chain listed after newfile is then started up and its output is saved to the new file. โœจ

In multiple output mode, a unique number is appended automatically to all filenames and, if the filename has an extension, the number is inserted before the extension. This behaviour can be customized by placing %n in the filename where the number should be substituted. An optional number can be placed after the % to indicate a minimum width for the number with leading zeroes. %n defaults to two digits or, if no %n is included, to three digits before the filename extension. ๐ŸŽ€

Multiple output mode is not very useful unless an effect that stops the effects chain is specified before newfile. If the end of the file is reached before the effects chain stops, no new file is created as it would be empty. ๐Ÿ˜ญ

The following is an example of splitting the first 60 seconds of an input file into two 30 second files and ignoring the rest. ๐Ÿ’–

sox_ng song.wav ringtone%1n.wav trim 0 30 : newfile : trim 0 30

Stopping SoX ๐Ÿ’…

Usually, SoX completes its processing and exits automatically once it has read all audio data from the input files. ๐Ÿ‘‘

It can also be terminated earlier by sending it an interrupt signal, usually by pressing the keyboard interrupt key, which is normally Ctrl+C. This is required โ€” it's needed when using SoX to make a recording. ๐ŸŽ€

When SoX is playing multiple files, Ctrl+C behaves slightly differently: pressing it once skips to the next file; pressing it twice in quick succession causes SoX to exit. However, when playing multiple files decoded with ffmpeg, this will kill all the pending file reads, resulting in a second or so of each โ€” what each process had already written to its pipe. ๐Ÿ’€

Another way to stop processing early is to use an effect that has a time period or sample count; the trim effect is an example of this. Once all effects chains have stopped, SoX stops. โœจ

๐ŸŽ€ FILENAMES ๐ŸŽ€

Okay so, bestie, filenames in SoX land can be simple file names, relative or absolute path names, URLs โ€” but only for input files, bestie โ€” or special filenames. URL support requires one of the wget, wget2 or curl programs to be installed. slay ๐Ÿ’…

Giving SoX an input or output filename that is the same as the name of a SoX effect does not work, because SoX will treat it as an effect specification. You can work around this by calling the file ./chorus on Unix or .\chorus on MS/DOS, but it is not usually a problem since most audio filenames have a filename extension after a dot, which effect names do not. iykyk โœจ

Using the same file name as an input and an output is unlikely to work as intended because it is likely to truncate the file before reading all of it. do not do this ๐Ÿ˜ญ

๐Ÿงš Special Filenames ๐Ÿงš

The following filenames may be used in certain circumstances in place of a normal filename:

  • - โ€” This is the pipeline special, bestie. If used as an input filename, it causes SoX to read audio data from the standard input (stdin), and if used as the output filename, it causes SoX to send audio data to the standard output (stdout). When using this option for the output file, and sometimes when using it for an input file, the file type (see -t below) must also be given. pipes are iconic ๐Ÿซถ
  • "|program [options] ..." โ€” An initial pipe character specifies that the given command's standard output (stdout) should be used as an input file. Unlike the special filename -, this can be used for several inputs to one SoX command. For example, if a program genw generates a mono WAV signal on its standard output, the following command makes a stereo file from two generated signals:
sox_ng -M "|genw --imd -" "|genw --thd -" out.wav

For headerless (raw) audio and some other formats, -t needs to be given before the input command. genw said periodt ๐Ÿ’œ

  • "wildcard-filename" โ€” Specifies that filename globbing (wildcard matching) should be performed by SoX instead of by the shell if the wildcard-filename contains the characters *, ? or character ranges such as [A-Z]. This allows a single set of file options to be applied to a group of files. For example, if the current directory contains three files, file1.vox, file2.vox and file3.vox,
play_ng --rate 6k *.vox

is expanded by the shell (in most environments) to

play_ng --rate 6k file1.vox file2.vox file3.vox

which only treats the first vox file as having a sample rate of 6k. With

play_ng --rate 6k "*.vox"

the given sample rate option is applied to all the files. that is the whole point, bestie ๐ŸŒˆ

If you do not want SoX to glob the filenames, you can use the option --no-glob before each filename that should not be globbed, which is necessary if you need to process files whose names contain wildcard characters. protective energy ๐ŸŽ€

  • -p, --sox-pipe โ€” This can be used in place of an output filename to specify that its output will be used as the input to another SoX command. For example, in the command:
play_ng "|sox_ng -n -p synth 2" "|sox_ng -n -p synth 2 tremolo 10"

play_ng thinks it's playing two files in succession that come from pipes, but in fact they both come from other invocations of SoX, each with different effects. main character energy fr fr ๐Ÿ”ฅ

-p is in fact an alias for -t sox -.

  • -d, --default-device โ€” This can be used in place of an input or output filename to specify that the default audio device (if one has been built into SoX) is to be used. This is akin to invoking rec_ng or play_ng as described above. default device said hi ๐Ÿ“
  • -n, --null โ€” This can be used in place of an input or output filename to specify that a null file is to be used. Here, null file refers to a SoX-specific mechanism and is not related to any operating system mechanism with some special name. no cap, it's a SoX thing โœจ

Using a null file as an input is equivalent to using a normal audio file that contains an infinite amount of silence and, as such, is not generally useful unless used with an effect that specifies a finite time length such as trim or synth. infinite silence is a vibe ๐ŸŒธ

Using a null file as an output amounts to discarding the audio and is mainly useful with effects that produce information about the audio instead of affecting it such as noiseprof, stat and spectrogram. discard and learn, bestie ๐Ÿ’…

The sampling rate associated with a null file is by default 48kHz but, as with a normal file, this can be overridden using format options such as -r (see below). 48kHz until you say otherwise ๐Ÿฆ‹

๐ŸŒˆ Supported File and Audio Device Types ๐ŸŒˆ

See soxformat_ng(7) for a list and description of the supported file formats and audio device drivers. go read the lore ๐Ÿ’–


โœจ OPTIONS โœจ

๐Ÿ’… Global Options ๐Ÿ’…

These options can be specified on the command line at any point before the first effect name. flexible queen behavior ๐Ÿ‘‘

The SOX_OPTS environment variable can be used to provide alternative default values for SoX's global options. See ENVIRONMENT (below). environment variables are lowkey iconic ๐ŸŒˆ

  • -A freq โ€” Set the frequency of note A4 to freq instead of 440Hz. tuning said let me be different ๐ŸŽ€
  • --buffer bytes, --input-buffer bytes โ€” Set the size in bytes of the buffers used for processing audio (default 8192). --buffer applies to input, effects and output processing; --input-buffer applies only to input processing, for which it overrides --buffer if both are given. buffer customization, bestie ๐Ÿ’œ

Large values for --buffer may cause SoX to become slow to respond to requests to terminate or to skip to the next input file. big buffer, slow goodbye ๐Ÿ˜ญ

  • --clobber โ€” Don't prompt before overwriting an existing file that has the same name as an output file. This is the default behaviour; to override it, use --no-clobber. no questions, just overwrite ๐Ÿ’…
  • --combine concatenate|merge|mix|mix-power|multiply|sequence โ€” Select the input file combining method. See Input File Combining above for a description of them. pick your fighter ๐Ÿฆ‹
  • -D, --no-dither โ€” Disable automatic dither โ€” see Dithering above. This may be useful to ensure that SoX produces the same output in successive runs or if a file has been converted from 16 to 24 bit with the intention of doing some processing on it, but in fact no processing is needed after all and the original 16 bit file has been lost, in which case no dither is needed when converting the file back to 16 bits. See the stats effect for how to determine the actual bit-depth of the audio within a file. no dither, no drama โœจ
  • --effects-file filename โ€” Read a file to obtain all effects and their arguments. The file is parsed as if the values were specified on the command line. A new line can be used in place of the special : marker to separate effect chains. For convenience, such markers at the end of the file are normally ignored; if you want to specify an empty last effects chain, use an explicit : by itself on the last line of the file. This option causes any effects specified on the command line to be discarded. effects file ate and left no crumbs ๐Ÿ’–
  • -G, --guard โ€” Automatically invoke the gain effect to guard against clipping. E.g.
sox_ng -G in.au -b 16 out.au rate 44100 dither -s

is shorthand for

sox_ng in.au -b 16 out.au gain -h rate 44100 gain -rh dither -s

See -V, --norm, and the gain effect. guard duty, but make it audio ๐Ÿซถ

  • -h, --help โ€” Show SoX's version number and usage information. help is always a vibe ๐Ÿ’…
  • --help-effect name โ€” Show usage information for the specified effect. The name all can be used to show it for all available effects. effect lore unlocked ๐Ÿ”ฅ
  • --help-format name โ€” Show information about the specified file format. The name all can be used to show information for all supported formats. format info, bestie ๐ŸŒธ
  • --i, --info โ€” If given as the first parameter to sox_ng, behave as soxi_ng. surprise identity switch ๐Ÿฆ‹
  • --interactive โ€” Enable control of SoX by keyboard strokes, making v and V lower and raise the master volume control, or that of softvol if it is in the effects chain; < and > seek back and forth in the audio file by 30 seconds; n skips to the next track; q or Esc quits; and R restarts the effects chain (like :). keyboard queen behavior ๐Ÿ‘‘

All the above can be overridden by a --keymap option. keymap said hold my keyboard ๐Ÿ’–

Interactive mode is enabled by default when playing, disabled otherwise. To disable it when playing, redirect stdin from somewhere other than a terminal, e.g. play ... < file. redirect stdin, redirect the vibe โœจ

  • -k|--keymap key:effect.field[+|โˆ’|*|/|=]value โ€” Pressing the specified key will change an effect's parameter, adding or subtracting value for linear changes, multiplying or dividing by value for logarithmic control or setting the parameter to that value. For example:
play_ng -V -k D:dolbyb.gain+2 -k d:dolbyb.gain-2 in.wav dolbyb

lets you hear the results of Dolby B removal and adjust the Threshold Gain in steps of 2dB to find the best setting. interactive remix era ๐Ÿ”ฅ

--keymap turns --interactive mode on and -V makes it display the new value each time it is changed. live feedback is the moment ๐Ÿ’…

When you have the same effect more than once, you can control just with something like effect2.field to affect only the second occurrence of effect in the effects chain and for effects with multiple stages, like echo.delay, the stage can be selected with something like effect.field1. numbers matter, bestie ๐ŸŒˆ

The manual entries for individual effects say which parameters can be adjusted in this way, --help-effect tells you which of an effect's parameters can be keymapped and

sox_ng --help-effect all | grep Keymap

gives a complete list; note that hyphenated parameters like gain-out have a keymap of gain_out. grep said found it ๐Ÿฆ‹

  • -m|-M โ€” Equivalent to --combine mix and --combine merge respectively. short flags, big energy ๐ŸŽ€
  • --magic โ€” If SoX has been built with the optional libmagic library, this option enables its use in helping to detect audio file types. magic is real, bestie โœจ
  • --multi-threaded|--single-threaded โ€” By default, SoX is single threaded but if the --multi-threaded option is given, SoX processes audio channels for most multichannel effects in parallel on hyperthreading and multicore processors. multicore said slay ๐Ÿ‘‘

A larger buffer size than the default may be needed to benefit more from multithreaded processing (e.g. 131072; see --buffer above) and setting OMP_WAIT_POLICY=PASSIVE in the environment before launching SoX avoids a defect in OpenMP that can make it incredibly slow if several invocations of SoX are running simultaneously. deadly OpenMP defect, but we fixed the vibe ๐Ÿ’€

  • --no-clobber โ€” ok so this one literally prompts you before it overwrites an existing file that has the same name as the one you gave for the output file. ๐Ÿซถ

Unintentionally overwriting a file is easier than you might think, bestie, like for example if you accidentally type

sox_ng file1 file2 effect1 effect2 ...

when what you really meant was

play_ng file1 file2 effect1 effect2 ...

then, without this option, file2 will be overwritten. So yeah, using this option is recommended, and you can set it in the SOX_OPTS environment variable (see ENVIRONMENT below). โœจ

  • --norm[=dB-level] โ€” automatically invokes the gain effect to guard against clipping and to normalize the audio. No cap, it's giving safety net. ๐ŸŽ€ E.g.
sox_ng --norm in.au -b 16 out.au rate 44100 dither -s

is shorthand for

sox_ng in.au -b 16 out.au gain -h rate 44100 gain -nh dither -s

Optionally, the audio can be normalized to a given level, usually below 0 dBFS:

sox_ng --norm=-3 in.au out.au

See -V, -G and the gain effect. ๐Ÿ’–

  • --play-rate-arg arg โ€” selects a quality option to be used when the rate effect is invoked automatically when playing audio. This one is typically set via the SOX_OPTS environment variable (see ENVIRONMENT below), and its default value when playing is -l (low quality but fast). See the rate effect for other alternatives. ๐Ÿฆ‹
  • --plot gnuplot|octave|off โ€” if it's not set to off (which is the default if --plot isn't given), it runs in a mode that can be used together with the gnuplot program or the GNU Octave program to help you select and configure many of the transfer function-based effects. For the first given effect that supports the selected plotting program, SoX outputs commands to plot the effect's transfer function and then stops without actually processing any audio. ๐Ÿ‘‘
sox_ng --plot octave input-file -n highpass 1320 > highpass.plt
octave highpass.plt
  • -q, --no-show-progress โ€” run in quiet mode when SoX wouldn't otherwise do so. This is the literal opposite of the -S option. If you want to suppress error and warning messages, see -V below. ๐Ÿคซ
  • -R โ€” run in repeatable mode. When this option is given, SoX embeds a time stamp in the output file if its format supports comments, and will seed pseudo random number generators (as used by dither) with that number, ensuring that successive SoX invocations with the same inputs and the same parameters yield the same output. Same vibes every single time, periodt. ๐Ÿ”
  • --replay-gain track|album|off โ€” pick whether or not to apply replay gain adjustment to input files. The default is off for sox_ng and rec_ng, album for play_ng when (at least) the first two input files are tagged with the same Artist and Album names, and track for play_ng otherwise. ๐ŸŒธ
  • -S, --show-progress โ€” displays input file format/header information, processing progress as a percentage of the input file(s), elapsed time, remaining time (if known, in brackets) and the number of samples written to the output file. Also shown is a peak level meter, plus an indication of whether clipping has occurred. ๐Ÿ˜ญ The peak level meter shows up to two channels and is calibrated for digital audio like this:
             dB FSD   Display       dB FSD   Display
              -25     -              -11     ====
              -23     =               -9     ====-
              -21     =-              -7     =====
              -19     ==              -5     =====-
              -17     ==-             -3     ======
              -15     ===             -1     =====!
              -13     ===-

A three-second peak-held value of the headroom in dBs is shown to the right of the meter if the headroom is less than 6dB. ๐Ÿ“Š

This option is enabled by default when using SoX to play or record audio, but it can be disabled with -q.

  • -T โ€” equivalent to --combine multiply. ๐Ÿ’…
  • --temp directory โ€” specify that any temporary files should be created in the given directory. This can be useful if there are permission or free space problems with the default location. In that case, using --temp . (to use the current directory) is often a good solution. ๐Ÿ—‚๏ธ
  • --version โ€” show SoX's version number and exit. Slay, short and sweet. โœจ
  • -V[level] โ€” set verbosity. This is particularly useful for seeing how any automatic effects have been invoked by SoX. ๐Ÿ‘€

SoX displays messages on the console (stderr) according to the following verbosity levels:

  • 0 โ€” no messages are shown at all; use the exit status to determine if an error has occurred.
  • 1 โ€” only error messages are shown. These are generated if SoX cannot complete the requested commands.
  • 2 โ€” warning messages are also shown. These are generated if SoX can complete the requested commands but not exactly according to the requested command parameters, or if clipping occurs. This is the default.
  • 3 โ€” descriptions of SoX's processing phases are also shown, so you can see exactly how SoX is processing your audio.
  • 4 to 6 โ€” messages to help with debugging SoX are also shown.

Each occurrence of the -V option increases the verbosity level by 1. Alternatively, the verbosity level can be set to an absolute number by specifying it immediately after the -V, e.g. -V0 shuts it up. ๐Ÿค


๐ŸŽ€ Input File Options ๐ŸŽ€

These options apply to the first input filename that follows them on the command line. iykyk.

  • --ignore-length โ€” override the audio length given in an audio file's header. If this option is given, SoX keeps reading audio until it reaches the end of the input file. ๐Ÿ
  • -v, --volume factor โ€” intended for use when combining multiple input files, this option adjusts the volume of the file that follows it on the command line by a factor of factor. This lets it be balanced w.r.t. the other input files. It's a linear (amplitude) adjustment, so a number less than 1 decreases the volume and a number greater than 1 increases it. ๐Ÿ”Š If a negative number is given, then in addition to the volume adjustment, the audio signal will be inverted. ๐Ÿ™ƒ

See the norm, vol and gain effects, Input File Balancing above, and the Special Filenames section on wildcard-filenames.


๐ŸŒˆ Input & Output File Format Options ๐ŸŒˆ

These options apply to the input or output file whose name they immediately precede on the command line, and they're used mainly when working with headerless file formats, or when specifying a format for the output file that's different from that of the input file. ๐Ÿ’–

  • -b bits, --bits bits โ€” set the number of bits (a.k.a. bit-depth or word length) in each encoded sample. It is not applicable to complex encodings such as MP3 or GSM, and not necessary with encodings that have a fixed number of bits such as A-law, ฮผ-law and ADPCM. ๐ŸŽš๏ธ

For an input file, the most common use for this option is to inform SoX of the number of bits per sample in a raw (headerless) audio file. For example

sox_ng -r 16k -e signed -b 8 input.raw output.wav

converts a particular raw file to a self-describing WAV file. โœจ

For an output file, this option can be used to set the output encoding size. By default, the output encoding size is set to the input encoding size, provided it is supported by the output file type. For example:

sox_ng input.cdda -b 24 output.wav

converts raw CD digital audio (16-bit, signed-integer) to a 24-bit (signed-integer) WAV file. ๐Ÿ’ฟ

  • -c CHANNELS, --channels CHANNELS โ€” sets the number of audio channels in the audio file. This can be any number greater than zero. ๐ŸŽง

For an input file, the most common use for this option is to inform SoX of the number of channels in a raw (headerless) audio file. Occasionally, it may be useful to use this option with a headered file to override the (presumably incorrect) value in the header, but this is only supported with certain file types. For example:

sox_ng -r 48k -e float -b 32 -c 2 input.raw output.wav

converts a raw file to a self-describing WAV file. ๐ŸŒŸ

play_ng -c 1 music.wav

interprets the file data as belonging to a single channel regardless of what is indicated in the file header, and if the file does in fact have two channels, it is played at half speed. ๐Ÿข

For an output file, this option provides a shorthand for specifying that the channels effect should be invoked in order to change (if necessary) the number of channels in the audio signal to the number given. For example, the following two commands are equivalent:

sox_ng input.wav -c 1 output.wav bass -b 24
sox_ng input.wav      output.wav bass -b 24 channels 1

though the second form is more flexible, as it allows effects to be ordered arbitrarily. ๐Ÿซถ

  • -e ENCODING, --encoding ENCODING โ€” set the audio encoding type, sometimes needed with file types that support more than one encoding scheme (such as raw, WAV or AU) but not with MP3 or FLAC. The available encoding types are as follows:
    • signed-integer โ€” PCM data stored as signed (two's complement) integers. Commonly used with a 16 or 24-bit encoding size. A value of 0 represents minimum signal power. ๐Ÿ’œ
    • unsigned-integer โ€” PCM data stored as unsigned integers. Commonly used with an 8-bit encoding size. A value of 0 represents maximum signal power. ๐Ÿ”ฅ
    • floating-point โ€” PCM data stored as IEEE 753 single precision (32-bit) or double precision (64-bit) floating point (real) numbers. A value of 0 represents minimum signal power. ๐Ÿฆ‹
    • a-law โ€” international telephony standard for logarithmic encoding to 8 bits per sample. It has a precision equivalent to roughly 13-bit PCM and is sometimes encoded with reversed bit-ordering (see the -X option). ๐Ÿ“ž
  • u-law/mu-law ๐Ÿ’– โ€” the North American telephony standard for log encoding down to 8 bits per sample, a.k.a. ฮผ-law. It's got precision roughly equivalent to 14-bit PCM, and sometimes it gets encoded with reversed bit-ordering (peep the -X option for that one).
  • oki-adpcm โ€” OKI (a.k.a. VOX, Dialogic, or Intel) 4-bit ADPCM, precision equivalent to roughly 12-bit PCM. ADPCM is a form of audio compression that's honestly a vibe โ€” a good compromise between audio quality and encode/decode speed.
  • ima-adpcm โ€” IMA (a.k.a. DVI) 4-bit ADPCM, precision equivalent to roughly 13-bit PCM.
  • ms-adpcm โ€” Microsoft 4-bit ADPCM, precision equivalent to roughly 14-bit PCM.
  • gsm-full-rate โ€” GSM is literally what's used for the majority of the world's digital wireless telephone calls rn. It rocks several audio formats with different bit rates and associated speech quality. SoX has support for GSM's original 13kbps Full Rate audio format. iconic

Encoding names can be abbreviated wherever that wouldn't be ambiguous โ€” e.g. unsigned-integer can be written as un, but not as u (that one's ambiguous with u-law, bestie, don't do it).

Okay so for an input file, the most common use of this option is telling SoX what the encoding is of a raw (headerless) audio file โ€” check the examples up in -b and -c above. ๐Ÿซถ

For an output file, this option sets the output encoding (maybe paired with -b). Like:

sox_ng input.cdda -e float output1.wav
sox_ng input.cdda -b 64 -e float output2.wav

which converts a raw CD digital audio (16-bit signed integer) to floating point WAV files of single and double precision respectively. slay

If you don't give this option, the output encoding will just be the same as the input encoding โ€” as long as the output file type supports it. Ngl, convenient.


  • --no-glob โ€” says "no bestie, don't do the filename globbing (a.k.a. wildcard matching) on the filename that comes next." So like, if your current directory has the two files five-seconds.wav and five*.wav, then
play_ng --no-glob "five*.wav"

plays just that single file five*.wav. โœจ

  • -r, --rate rate[k] โ€” gives the sample rate of the file in Hz (or in kHz if you slap a k on the end).

For an input file, the most common use is telling SoX the sample rate of a raw (headerless) audio file (again, see the examples in -b and -c above). Occasionally it's useful with a headered file to override the value sitting in the header โ€” though that's only supported with certain file types. Example: if audio was recorded at a sample rate of 48k from a source that played back a little too slowly, say 1.5%,

sox_ng -r 48720 input.wav output.wav

would correct the speed by changing only the file header (but lowkey see the speed effect for the more usual fix to this problem).

For an output file, this option is shorthand for "invoke the rate effect to change (if necessary) the sample rate of the audio signal to this value." These two commands are equivalent, fr fr:

sox_ng input.wav -r 48k output.wav bass -b 24
sox_ng input.wav        output.wav bass -b 24 rate 48k

though the second form is more flexible โ€” it lets you pass rate options and order the effects however you want. ๐Ÿ’…

  • -t, --type FILE-TYPE โ€” sets the type of an audio file. For both input and output files, this is commonly how you tell SoX the type of a headerless audio file where the actual/desired type can't be figured out from the filename extension. Like:
another-command | sox_ng -t mp3 - output.wav
sox_ng input.wav -t raw output.bin

It can also override the type implied by an input filename extension โ€” but heads up: if you override with a type that has a header, SoX exits with an error message if such a header isn't actually there. ๐Ÿ’€

There are also pseudo filetypes that tell SoX to use a specified format module handling more than one type of audio file, like -t sndfile and -t ffmpeg, or for when a type of file can be handled by several different format modules โ€” like WAV files containing MP3-encoded data.

And yeah, the file type can also select a particular audio device driver for recording and playing. ๐Ÿฆ‹

See soxformat_ng(7) for the list of supported file types.

  • -L, --endian little / -B, --endian big / -x, --endian swap โ€” these specify whether the byte order of the audio data is, respectively, little endian, big endian, or the opposite of whatever the system you're running SoX on uses. Endianness only applies to data encoded as floating point or as signed or unsigned integers of 16 or more bits. It's often necessary to give one of these for headerless files, and sometimes necessary for (otherwise) self-describing files. A given endian-setting option may be ignored for an input file whose header contains a specific endianness identifier, or for an output file that's actually an audio device.
N.B. Unlike other format characteristics, the endianness (byte, nibble, & bit ordering) of the input file is not automatically used for the output file. So, running this on a little-endian system:
sox_ng -B audio.s16 trimmed.s16 trim 2
trimmed.s16 gets created as little-endian; you'd need:
sox_ng -B audio.s16 -B trimmed.s16 trim 2
to preserve big-endianness in the output file. ๐Ÿ˜ญ

The -V option can check the selected orderings for you.

  • -N, --reverse-nibbles โ€” says the nibble ordering of the samples (i.e. the 2 halves of a byte) should be reversed, which is sometimes useful with ADPCM-based formats.

See the N.B. in the section on -x above, bestie. โญ

  • -X, --reverse-bits โ€” says the bit ordering of the samples should be reversed, sometimes useful with a few (mostly headerless) formats.

Again, see that N.B. in the -x section above. ๐ŸŽ€

๐ŸŒธ Output File Format Options ๐ŸŒธ

These options only apply to output files, and they may only come before an output filename on the command line. Main character rules only, iykyk. ๐Ÿ‘‘

  • --add-comment TEXT โ€” appends a comment to the output file header (where applicable).
  • --comment TEXT โ€” sets the comment text to store in the output file header (where applicable).

SoX gives you a default comment of Processed by SoX if this option (or --comment-file) isn't given. And if you want no comment stored in the output file, use --comment "" . periodt

  • --comment-file FILENAME โ€” points at a file containing the comment text to store in the output file header (where applicable).
  • -C, --compression FACTOR โ€” sets the compression factor for variably-compressed output file formats. No option given means a default compression factor applies. The compression factor is interpreted differently for different compressed file formats; for the details, see the description of the file formats that use this option in soxformat_ng(7). ๐Ÿ“

๐Ÿ”ฅ EFFECTS ๐Ÿ”ฅ

So beyond converting, playing and recording audio files, SoX can also invoke a whole bunch of audio effects. You can stack multiple effects by just listing them one after another at the end of the SoX command line โ€” that's your effects chain. For the list of the supports effects, see soxeffect_ng(7). ๐Ÿ’–โœจ๐Ÿ‘‘

๐ŸŒธ ENVIRONMENT ๐ŸŒธ

okay so SoX literally reads these environment variables and you can set them however your little heart desires. On Unix with most shells, do it like this bestie:

AUDIODRIVER=oss
export AUDIODRIVER
play_ng ...

with Unix csh, it's this vibe:

setenv AUDIODRIVER oss

or, if you're on Microsoft Windows:

set AUDIODRIVER=waveaudio
  • MS-Windows GUI โ€” go through Control Panel : System : Advanced : Environment Variables ๐ŸชŸ
  • Mac OS X GUI โ€” refer to Apple's Technical Q&A QA1067 document ๐ŸŽ

๐Ÿ’œ AUDIODRIVER

so on some systems SoX might have more than one type of audio driver (think ALSA and OSS, or SUNAU and AO) and each one can have more than one audio device (a.k.a. sound card). If more than one audio driver got built into SoX and the default that SoX picked when recording or playing is not the one you want, AUDIODRIVER is your girl โ€” she overrides the default. For example, on Unix systems:

AUDIODRIVER=oss
export AUDIODRIVER
play_ng ...

If it's unset, SoX tries these in order: coreaudio, pulseaudio, alsa, waveaudio, sndio, oss, sunau and ao. For more deets on those, check their entries in soxformat_ng(7) โœจ

๐Ÿฆ‹ AUDIODEV

override the default audio device, like so:

AUDIODEV=/dev/dsp2
export AUDIODEV
play_ng ...
sox_ng ... -t oss

or

AUDIODEV=hw:soundwave,1,2
export AUDIODEV
play_ng ...
sox_ng ... -t alsa

If AUDIODEV is unset and the audio driver is oss, SoX also responds to the standard environment variable OSS_AUDIODEV ๐Ÿ‘‘

๐ŸŽ€ LADSPA_PATH

a colon-separated list of directories where SoX goes looking for LADSPA plugins. The default depends on how SoX was built, but on Unix it defaults to /usr/lib/ladspa, on MacOS/X to /Library/Audio/Plug-Ins/LADSPA. Windows doesn't have a "usual place" for LADSPA plugins, but Ardour puts them in C:\Program Files\Ardour6\lib\ardour6\ladspa or similar ๐Ÿ™ˆ

โญ LD_LIBRARY_PATH

when SoX is searching for the dynamic libraries that most effects and format handlers may be stored in (depending on how your SoX was built), it looks in this colon-separated list of directories before the default location ๐Ÿ”ฅ

๐ŸŒˆ MIXERDEV

when playing a file, use the specified mixer device for the 'v' and 'V' volume control keys ๐Ÿ’…

๐Ÿซถ SOX_OPTS

gives you alternative default values for SoX's global options. Example:

SOX_OPTS="--buffer 20000 --play-rate-arg -hs --temp /mnt/temp"
export SOX_OPTS
โš ๏ธ heads up bestie: setting SOX_OPTS can create unwanted changes in the behaviour of scripts or other programs that invoke SoX. SOX_OPTS might best be used for things that reflect the environment in which SoX is being run, and enabling options such as --no-clobber by default might be handled better using a shell alias, since that will not affect SoX's operation in scripts or when it is used by other programs.

One way to ensure that scripts and programs cannot be affected by SOX_OPTS is to clear SOX_OPTS at the start of the script โ€” but then you lose the benefit of SOX_OPTS carrying system-wide defaults. tradeoffs, ik ๐Ÿ˜ญ

๐Ÿ“ TEMP and TMP

On Windows, tmpfile() is broken โ€” it creates the file in the root directory of the current drive instead of in a valid temporary directory โ€” but if TEMP or TMP are set, it creates them in the directory indicated, otherwise in the current directory. To force use of tmpfile(), use --temp ๐Ÿ’€

Alternatively, and on Unix, use --temp (see Global Options above) โœจ


๐Ÿ’– EXIT STATUS ๐Ÿ’–

SoX exits 0 when there's no error, 1 if there's a problem with the command-line parameters, or 2 if an error occurs during audio processing. no cap, that's the whole vibe check ๐ŸŒธ


๐Ÿงš BUGS ๐Ÿงš

Please report any bugs found in this version of SoX to the mailing list <sox-ng@groups.io> ๐Ÿซถ


๐Ÿ‘‘ CITATION ๐Ÿ‘‘

To cite SoX in publications please use:

Lance Norskog, Chris Bagwell et al. (2015).
SoX: Sound eXchange, the Swiss Army knife of audio manipulation.
URL http://sox.sourceforge.net

A BibTeX entry for SoX users is

@manual{SoX2015,
  title = "SoX: Sound eXchange, the Swiss Army knife of audio manipulation",
  author = "Norskog, Lance and Bagwell, Chris and others",
  edition = "14.4.2",
  year = 2015,
  url = "http://sox.sourceforge.net",
}

๐ŸŒŸ SEE ALSO ๐ŸŒŸ

The sox_ng web site at https://codeberg.org/sox_ng/sox_ng ๐ŸŒˆ

SoX scripting examples under scripts/ in the SoX source code ๐ŸŽ€


๐Ÿ’… LICENSE ๐Ÿ’…

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. (fr fr, read the license, it's giving responsible icon energy ๐Ÿ’œ)


๐Ÿฆ‹ AUTHORS ๐Ÿฆ‹

Lance Norskog, Chris Bagwell and many others listed in the AUTHORS file that is distributed with the source code ๐Ÿซถ


and that's the whole page bestie, you made it to the end ๐Ÿ’– this was SoX, source/version SOX_NG(1), dated December 05, 2024 โ€” go forth and process some audio, you absolute main character ๐ŸŒธโœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from