aplay is a command-line utility for playing audio files on a Linux system. It is part of the ALSA (Advanced Linux Sound Architecture) utility suite, which provides audio support for Linux systems. aplay can be used to play a variety of audio file formats, including WAV, AIFF, AU, and MP3.
To use aplay, you will need to specify the name of the audio file you want to play as an argument. For example:
# aplay mysong.wav
You can also specify options to control the way aplay plays the audio file. For example, you can use the -D option to specify the name of the audio device to use, or the -c option to specify the number of channels in the audio file.
Here is an example of how to use aplay with some options:
# aplay -D hw:0,0 -c 2 mysong.wav
This will play the audio file mysong.wav using the audio device hw:0,0 and with 2 channels. You can use the man command to view the manual page for aplay and see a full list of options that are available.
# man aplay
If you encounter the below error while running the aplay command:
aplay: command not found
you may try installing the below package as per your choice of distribution:
OS Distribution | Command |
---|---|
Debian | apt-get install alsa-utils |
Ubuntu | apt-get install alsa-utils |
Alpine | apk add alsa-utils |
Arch Linux | pacman -S alsa-utils |
Kali Linux | apt-get install alsa-utils |
CentOS | yum install alsa-utils |
Fedora | dnf install alsa-utils |
Raspbian | apt-get install alsa-utils |
aplay Command Examples
1. Play a specific file (sampling rate, bit depth, etc. will be automatically determined for the file format):
# aplay {{path/to/file}}
2. Play the first 10 seconds of a specific file at 2500 Hz:
# aplay --duration={{10}} --rate={{2500}} {{path/to/file}}
3. Play the raw file as a 22050 Hz, mono, 8-bit, Mu-Law .au file:
# aplay --channels={{1}} --file-type {{raw}} --rate={{22050}} --format={{mu_law}} {{path/to/file}}