How to test audio on Raspberry Pi

Despite its small size, the Raspberry Pi is perfectly capable of putting out audio via HDMI, Bluetooth, or analog audio with the 3.5mm onboard headphone jack. If you have just set up your Raspberry Pi and need to perform some testing to get the audio working correctly, or verify that your setup is working, then there are easy ways to test the audio on Raspberry Pi. In this tutorial, you will see how to test audio functionality on a Raspberry Pi.

In this tutorial you will learn:

  • How to test audio via speaker-test command
  • How to adjust volume level on Raspberry Pi GUI
  • How to play audio file via VLC on Raspberry Pi GUI
  • How to play MP3 or other audio file from command line
How to test audio on Raspberry Pi
How to test audio on Raspberry Pi
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Raspberry Pi
Software speaker-test, VLC, omxplayer
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to test audio on Raspberry Pi




We have various ways to test out the audio on a Raspberry Pi. This includes via the command line and GUI, and by either playing an audio file or generating a speaker test. Check out the different methods below and choose whichever one is most convenient for you.

First thing is first, though. If you are using the GUI on Raspberry Pi, ensure that your volume is loud enough (and that it is not muted). This can be done by clicking on the speaker icon in the upper right corner.

Adjusting the volume on Raspberry Pi
Adjusting the volume on Raspberry Pi

Next, make sure that you have the correct device selected for audio output. This can be done by right clicking on the speaker icon and then selecting which device you want the Raspberry Pi to output audio to. Of course, you will only see one option (the audio jack) if you do not have an extra devices such as a USB speaker or Bluetooth speaker connected to your Raspberry Pi.

Selecting the device that the Raspberry Pi should output audio to
Selecting the device that the Raspberry Pi should output audio to

With that out of the way, let’s see some ways to test our audio on Raspberry Pi…

  1. One of the best ways to test out audio, which will work for both command line only systems and GUI, is by using the speaker-test command. The following syntax will do the job:


    $ speaker-test -c2 -twav -l3
    

    The -c option lets us specify the number of speakers we have, and the -l option allows us to specify how many tests to perform (each one lasts a second or two). Usually, -c will be set to 2, for a left and right speaker. But if you have more speakers, feel free to put a larger number:

    $ speaker-test -c4 -twav -l3
    
    Testing the audio on a Raspberry Pi by using the speaker-test command
    Testing the audio on a Raspberry Pi by using the speaker-test command

    A sound will play on each speaker, helping you identify which speakers are working and which ones are not.

  2. If you would like to play an audio file from command line for testing purposes, then omxplayer is the perfect tool for the job. The sytnax is very simple and requires no further options:
    $ omxplayer audio.mp3
    
  3. As for playing audio via GUI, Raspberry Pi OS includes VLC player by default, which is capable of playing almost any kind of audio format. If you do not have VLC already, it can be installed with this command:
    $ sudo apt install vlc
    

    There are a variety of other audio players that can be installed on the Raspberry Pi as well – MPV, Audacious, and OSMC to name a few. VLC should be accessible from the system application launcher:

    Accessing VLC Media Player from Raspberry Pi menus
    Accessing VLC Media Player from Raspberry Pi menus

Closing Thoughts




In this tutorial, we saw how to test the audio on a Raspberry Pi system. This included using the speaker-test command, which is a viable method for both command line and GUI systems, and allows users to pinpoint which speaker is not working, in the case of a multi speaker setup. In addition, we learned how to play an audio file from command line with omxplayer and how to use VLC player via GUI. A big but simple fix also involves adjusting our volume off of mute and selecting the appropriate audio device for output.



Comments and Discussions
Linux Forum