LinuxCommandLibrary

rec

Record audio from the command line

SYNOPSIS

rec [global options] [format options] [input options] <output_file> [output options] [effect options] [effect arguments]

Example: rec -r 44100 -c 2 output.wav trim 0 10s

PARAMETERS

-q
    Enables quiet mode, suppressing progress messages.

-V
    Increases verbosity, showing detailed information and warnings.

-v <volume>
    Adjusts the input volume multiplicatively. A value of 1.0 means no change.

-t <type>
    Specifies the output audio file type (e.g., wav, flac, mp3).

-r <rate>
    Sets the sample rate (in Hz) for the recording (e.g., 44100 for CD quality).

-c <channels>
    Defines the number of audio channels (e.g., 1 for mono, 2 for stereo).

--input-device <device> or -d <device>
    Selects the specific audio input device (e.g., default, alsa, pulseaudio).

trim <start> [<length>]
    Records for a specific duration. start is usually 0 for recording from the beginning. length specifies the duration (e.g., 10s for 10 seconds).

silence <threshold_percent>
    Stops recording automatically when silence is detected. Requires additional parameters for duration and threshold.

gain <level>
    Applies a gain effect to the recorded audio.

norm
    Normalizes the recorded audio to a standard peak level.

DESCRIPTION

The rec command is a powerful utility derived from the SoX (Sound eXchange) audio processing suite. It serves as a convenient wrapper for the sox command, specifically designed for recording audio from an input device, such as a microphone or line-in, to an output file. rec supports a wide array of audio formats (e.g., WAV, MP3, FLAC) and allows for real-time application of various audio effects and transformations during the recording process. It offers precise control over recording parameters like sample rate, channels, and duration, making it a versatile tool for capturing high-quality audio directly from the command line. Its capabilities extend beyond simple recording, enabling users to monitor input levels, apply noise reduction, or automatically stop recording based on silence.

CAVEATS

rec relies heavily on the underlying audio system (e.g., ALSA, PulseAudio, OSS) and its proper configuration. Issues with device access, permissions, or system mixer settings can prevent successful recording. When recording to compressed formats like MP3, external encoders (e.g., LAME) might be required and need to be present on the system.

COMMON USAGE EXAMPLES

rec my_recording.wav
Records audio to my_recording.wav until manually stopped.

rec -r 48000 -c 1 speech.flac trim 0 30s
Records 30 seconds of mono audio at 48kHz to speech.flac.

rec presentation.mp3 silence 1 0.1 3% 1 2.0 3%
Records to presentation.mp3, stopping after 2 seconds of silence below 3% volume.

HISTORY

The rec command is an integral part of the SoX (Sound eXchange) project, which originated in the early 1990s. SoX was developed as a command-line utility for converting and processing various audio file formats. As a convenience, rec was introduced as a specific alias or wrapper for sox itself, simplifying the syntax for audio recording tasks by implicitly setting the input to an audio device. Its long history reflects the continuous evolution of digital audio processing on Unix-like systems.

SEE ALSO

sox(1), play(1)

Copied to clipboard