How to use the command 'arecord' (with examples)
- Linux
- December 25, 2023
The arecord
command is a sound recorder for ALSA soundcard driver. It allows users to record audio snippets and save them in different formats. This article will provide examples of different use cases for the arecord
command.
Use case 1: Record a snippet in “CD” quality (finish with Ctrl-C when done)
Code:
arecord -vv --format=cd path/to/file.wav
Motivation: This use case is useful when you want to record a snippet of audio in high-quality “CD” format.
Explanation:
-vv
: Increase verbosity level, providing more detailed information while recording.--format=cd
: Set the audio format to “CD” quality (16-bit, 44.1 KHz sampling rate).path/to/file.wav
: Specify the file path where the recorded audio will be saved.
Example output:
Recording WAVE 'path/to/file.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Use case 2: Record a snippet in “CD” quality, with a fixed duration of 10 seconds
Code:
arecord -vv --format=cd --duration=10 path/to/file.wav
Motivation: Sometimes, you may need to record audio snippets of a specific duration, such as for creating short audio clips or voice memos.
Explanation:
-vv
: Increase verbosity level, providing more detailed information while recording.--format=cd
: Set the audio format to “CD” quality (16-bit, 44.1 KHz sampling rate).--duration=10
: Specify the duration of the recording in seconds.path/to/file.wav
: Specify the file path where the recorded audio will be saved.
Example output:
Recording WAVE 'path/to/file.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Recording WAVE 'path/to/file.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Recording WAVE 'path/to/file.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
...
Use case 3: Record a snippet and save it as an MP3 (finish with Ctrl-C when done)
Code:
arecord -vv --format=cd --file-type raw | lame -r - path/to/file.mp3
Motivation: This use case is useful when you want to save the recorded audio snippet in the popular MP3 format for easier sharing or playback on various devices.
Explanation:
-vv
: Increase verbosity level, providing more detailed information while recording.--format=cd
: Set the audio format to “CD” quality (16-bit, 44.1 KHz sampling rate).--file-type raw
: Specify the input file type as raw audio.lame -r - path/to/file.mp3
: Use thelame
command to encode the raw audio input into an MP3 file.-r
flag tellslame
to interpret the raw audio input.
Example output:
Recording WAVE 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
to 'path/to/file.mp3' : (automatic)
Use case 4: List all sound cards and digital audio devices
Code:
arecord --list-devices
Motivation: It is helpful to know the available audio devices on your system, especially when troubleshooting audio-related issues or setting up audio configurations.
Explanation:
--list-devices
: Command option to list all sound cards and digital audio devices.
Example output:
**** List of CAPTURE Hardware Devices ****
card 1: PCH [HDA Intel PCH], device 0: ALC3232 Analog [ALC3232 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
Use case 5: Allow interactive interface
Code:
arecord --interactive
Motivation: This use case provides an interactive interface for recording audio, allowing the user to control the recording using spacebar or enter key to play or pause.
Explanation:
--interactive
: Command option to enable the interactive interface.
Example output:
Press ENTER or SPACE key to start capturing audio.
Press ENTER or SPACE key again to stop capturing audio.
Press CTRL+C to quit.
Conclusion:
The arecord
command provides a versatile sound recording functionality. Whether you need to record snippets in high-quality formats, save them in different file types, interactively record audio, or explore available audio devices, arecord
has you covered. Experiment with the provided examples to unleash the full potential of this powerful command.