SoX (Sound eXchange) is a versatile command-line tool for manipulating audio.
It is capable of taking input from microphones, files, and standard input, and sending output to speakers, files, and standard output.
All functionality can be achieved using the sox command, but the play and rec commands are provided for added convenience.
The sox command takes some audio input, manipulates it, and outputs it (usually to a file). It can work with familiar formats such as WAV, FLAC, OGG. Converting WAV to MP3:sox oldfile.wav newfile.mp3
In some cases it is necessary to specify the file format with the -t/--type argument, e.g. sox -t wav oldfile.wav -t flac newfile.mp3
will convert to the FLAC format even though the file extension says MP3. A full list of file types can be found in "man 7 soxformat".
It can also work with uncompressed, headerless "raw" formats, which can be described using the following arguments:
-t raw: specifies file type as raw.-r/--rate: sample rate in Hz (number of data points per second). Allows "-r 8k" for 8000 Hz, etc.-c/--channels: number of channels (mono: 1, stereo 2). Allows any positive number.-e/--encoding: data encoding. The most useful options for tinkerers like me are:signed-integerunsigned-integerfloating-point: 32-bit or 64-bit (I haven't tried this)-b/--bits: number of bits in each sample. 8, 16, 24 bits definitely work; I seem to be able to record 7-bit but not play it (not that I have any reason to work with 7-bit audio right now...)If you specify a raw audio format, you can treat ANY file as if it's audio! For example, here's how to play a PDF: sox -t raw -c 1 -e unsigned-integer -b 8 -r 8000 book.pdf -d
To use the default input or output device, replace the file name & format with -d. TODO sometimes this plays funny with the number of channels...
To use standard input or standard output, replace the file name with -. You will need to provide a filetype!
TODO see "Stopping SoX" in the man 1 sox manual page. also TODO figure out the double-recording mystery; I think it's related.