playing music on your Raspberry Pi
2013-Jan-23, Wednesday 10:16 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
This topic requires a post of its own because audio is mildly "broken" in the latest Raspbian image.
Raspbian uses ALSA (Advanced Linux Sound Architecture), and it comes with a standard "aplay" command to play audio files. You can try it yourself with audio files that are already installed. Telnet to your Raspberry Pi and try the following command.
Raspbian uses ALSA (Advanced Linux Sound Architecture), and it comes with a standard "aplay" command to play audio files. You can try it yourself with audio files that are already installed. Telnet to your Raspberry Pi and try the following command.
sudo aplay /usr/share/sounds/alsa/Front_Center.wavIf your speakers are hooked up to your Pi, you probably heard the audio message. That success is encouraging, at least until you try to play some music files of your own. Suddenly, you find playback quite restrictive. Aplay is working only with audio files that are:
- stored with old .WAV or .AU file format,
- stored with integer (not floating point) values, and
- sampled with cd-quality resolution (such as 144,000 Hertz).
sudo apt-get --purge remove pulseaudioNow let's download some audio files in other formats.
cd ~/Desktop wget http://www.soundjay.com/nature/river-4.wav wget http://www.soundjay.com/nature/river-4.mp3If we try the standard Aplay program, we find that we can play other .wav files, but we still can't hear the .mp3 file. You can use Control-C to interrupt playback.
aplay river-4.wav aplay river-4.mp3We'll need to install a different program to play the .mp3 file. We find the opposite issue with this program; it plays .mp3 files but not .wav formats.
sudo apt-get install mpg321 mpg321 river-4.mp3 mpg321 river-4.wavThere's still a slight "pop" sound as the audio engages/disengages. At least we have our playback options covered with these two programs together. We really need to get a single program that covers all the formats, with playlists, and with repeating loops. Until then, audio is less than "friendly" in the current Raspbian distribution. I'm certain that better solutions will appear in future releases.