LinuxCommandLibrary

aplay

Play audio files from command line

TLDR

Play a specific file (sampling rate, bit depth, etc. will be automatically determined for the file format)

$ aplay [path/to/file]
copy

Play the first 10 seconds of a specific file at 2500 Hz
$ aplay [[-d|--duration]] [10] [[-r|--rate]] [2500] [path/to/file]
copy

Play the raw file as a 22050 Hz, mono, 8-bit, Mu-Law .au file
$ aplay [[-c|--channels]] [1] [[-t|--file-type]] [raw] [[-r|--rate]] [22050] [[-f|--format]] [mu_law] [path/to/file]
copy

List available audio devices
$ aplay [[-l|--list-devices]]
copy

SYNOPSIS

aplay [options] [filename...]

Common options:
-D device    Select ALSA device
-f format    Sample format
-c channels    Number of channels
-r rate       Sample rate
-t type       File type (e.g., wav, raw)
-s                 Show progress bar
-v                 Verbose output

PARAMETERS

-D device
    Specifies the ALSA playback device to use. Use 'aplay -L' to list available devices.

-f format
    Sets the sample format, e.g., S16_LE (signed 16-bit, little endian) or U8 (unsigned 8-bit).

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

-r rate
    Sets the sample rate in Hertz (e.g., 44100 for CD quality audio).

-t type
    Specifies the file type, such as 'wav' for WAV files or 'raw' for raw PCM data.

-s
    Displays a progress bar during playback, indicating the elapsed time and position.

-v
    Enables verbose output, showing more details about the playback process and device parameters.

-q
    Suppresses output messages during playback, operating in quiet mode.

-N
    Prevents aplay from touching existing mixer settings; playback is done without altering volume.

-i
    Enables interactive mode, allowing playback to be paused/resumed by pressing the Spacebar.

--period-size frames
    Sets the period size in frames, affecting latency and buffer handling.

--buffer-size frames
    Sets the total buffer size in frames, influencing how much audio data is buffered.

-L
    Lists all available PCM devices and their descriptions, useful for identifying device names for -D.

DESCRIPTION

aplay is a command-line utility within the ALSA (Advanced Linux Sound Architecture) project, designed for playing raw and WAV audio files through sound devices. It serves as the playback counterpart to the arecord command, which is used for recording audio. aplay provides a straightforward method to test sound card functionality, play back recorded audio, or simply output sound from scripts directly from the terminal.

While it primarily handles uncompressed formats like WAV and raw PCM data, its robust integration with the ALSA framework allows it to interact directly with various audio hardware devices and their channels. Users can specify playback parameters such as the device, sample format, rate, and number of channels, offering granular control over the audio output. It's an essential tool for developers, system administrators, and anyone needing low-level audio playback capabilities in a Linux environment.

CAVEATS

aplay primarily handles uncompressed audio formats like WAV and raw PCM. It does not natively support compressed formats such as MP3, OGG, or FLAC; for these, a separate player or transcoder (like mpg123 or ffplay) is required.

Playback might fail if the specified ALSA device is already in use by another application or if the user lacks sufficient permissions to access the audio hardware. Ensuring correct device selection and proper user group membership (e.g., 'audio' group) is crucial for successful playback.

<B>SUPPORTED FILE TYPES</B>

aplay natively supports WAV (.wav) files and raw PCM data. For raw data, the sample format, rate, and channels must be explicitly specified using options like -f, -r, and -c. Support for other formats is generally not built-in and requires external decoders or pipes for conversion.

<B>DEVICE SELECTION</B>

The -D option is critical for specifying the playback device. Users can list available ALSA devices using 'aplay -L' to identify the correct device string (e.g., 'hw:0,0', 'default', or 'plug:dmix'). Choosing the wrong device can result in no sound or playback errors.

HISTORY

aplay is an integral part of the ALSA (Advanced Linux Sound Architecture) utilities, which emerged as the successor to OSS (Open Sound System) for sound card drivers in Linux. ALSA development began in 1997, aiming to provide a more modular and robust audio framework. aplay, alongside arecord, was developed to provide command-line interfaces for playback and recording within this new architecture. Its continued relevance stems from ALSA's widespread adoption as the default sound system in most modern Linux distributions, making aplay a fundamental tool for direct audio hardware interaction.

SEE ALSO

Copied to clipboard