June 17, 2017

Playing audio on the Raspberry Pi

To play an MP3 file, navigate to the location of the .mp3 file in the terminal using cd and then type the following command:

omxplayer example.mp3

This will play the audio file example.mp3 through either your monitor’s built-in speakers or your headphones, connected via the headphone jack.

If you need an example file you can download one from here using the following command:

wget -O example.mp3 --no-check-certificate

If you cannot hear anything, make sure your headphones or speakers are connected correctly. Note that omxplayer doesn’t use ALSA and so ignores the audio configuration set by raspi-config or amixer.

If omxplayer’s auto-detection of the correct audio output device fails, you can force output over HDMI with:

omxplayer -o hdmi example.mp3

Alternatively, you can force output over the headphone jack with:

omxplayer -o local example.mp3

You can even force output over both the headphone jack and HDMI with:

omxplayer -o both example.mp3


There are two ways of setting the audio output.


The following command, entered in the command line, will switch the audio output to HDMI:

amixer cset numid=3 2

Here the output is being set to 2, which is HDMI. Setting the output to 1switches to analogue (headphone jack). The default setting is 0 which is automatic.


Open up raspi-config by entering the following into the command line:

sudo raspi-config

This will open the configuration screen:

raspi-config screen

Select Option 8 Advanced Options and press Enter, then select Option A6: Audio and press Enter:

Audio configuration screen

Now you are presented with the two modes explained above as an alternative to the default Auto option. Select a mode, press Enter and press the right arrow key to exit the options list, then select Finish to exit the configuration tool.


In some rare cases, it is necessary to edit config.txt to force HDMI mode (as opposed to DVI mode, which does not send sound). You can do this by editing /boot/config.txt and setting hdmi_drive=2, then rebooting for the change to take effect.


Source: Playing audio on the Raspberry Pi – Raspberry Pi Documentation

Leave a Reply

Your email address will not be published. Required fields are marked *