Play audio on a Bluetooth speaker with Raspberry Pi

By Russell Barnes. Posted

Make use of the Raspberry Pi's Bluetooth capabilities to play audio and/or music over a wireless speaker, without using a dongle!

Bluetooth is a wireless technology standard, and it has been a feature on the Raspberry Pi since the Raspberry Pi 3 and Pi Zero W. You can use it to connect Bluetooth keyboards, mice, and other accessories: like speakers and headphones.

The new Raspberry Pi 3B+ even moves from Bluetooth 4.1 to 4.2, which brings faster and more reliable over-the-air data transmission.

In this tutorial we’ll take a look at hooking up a Raspberry Pi to a Bluetooth speaker. This enables you to play music wirelessly from your Raspberry Pi, turning it into an effective media centre.

You should be able to follow this Bluetooth audio tutorial with any Bluetooth-enabled Raspberry Pi.

And Bluetooth can easily be added to an older Raspberry Pi using a dongle, like this Nano USB to Bluetooth Dongle V2.0.

Get a free Pi Zero W with a 12-month subscription to The MagPi magazine. Click here for more info.

Play Bluetooth Audio on a Raspberry Pi: get some music

First, you’ll need some music files. You can stream audio online from a source such as YouTube, and many people have MP3 and other audio files. We downloaded Sampler EP Vol. 9 by Vulpiano Records Artists from Free Music Archive for this tutorial. Save the file to your Music folder. Use File Manager to locate the zip file, then right-click it and choose Extract Here.

It is possible to play the music files directly from Terminal using omxplayer. Open a Terminal window and enter omxplayer followed by the path to the music file, like this:

oxmplayer ~/Music/Anton_Rothschild_-_03_-_Its_Not_Vegas.mp3

But it’s not a great visual option. We’d rather double-click MP3 files in the File Manager using the Desktop interface. For this we need a media player, and we’re going to use a popular one called VLC. Enter these commands in Terminal:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y vlc

During the installation you’ll be asked if you want to allow metadata network access. This is used to add cover artwork and track listings to your files. Tick or untick the box and click Continue.

Double-clicking the MP3 files in File Manager will open VLC and play the file.

Connect to Bluetooth

OK, so we’ve got our music and a music player. Now it’s time to connect the Raspberry Pi to a Bluetooth speaker.

To do this you’ll need to put the speaker in pairing mode and pair the Raspberry Pi to the speaker. How you do this depends on the speaker itself. If your speaker has an interface, you’ll probably use the controls to put it into pairing mode. Many smaller speakers or headphones have a button that you hold down to put the device into pairing mode (typically you’ll see a flashing light).

Bluetooth Add Device 500

Connect a Raspberry Pi to Google Home via Bluetooth

  1. We’re using a Google Home speaker for this test. For this you simply say “Hey Google... Connect To Bluetooth” (you can do the same with Alexa).
  2. Now click on the Bluetooth icon in the top-right of the screen and choose Add Device. Look for your speaker in the ‘Add new device’ window. In most cases the speaker will be identified by an easily recognisable name, such as our Google Home.
  3. However, you may need to locate the device using its MAC address (the six octet hexadecimal code). These are often printed on the device itself – or you can cancel pairing mode, then re-enter it and see which device disappears and reappears. Hopefully you won’t have to resort to that. Locate the speaker in Add Devices and click Pair. After a short while, the window will display Pairing Successful. Click OK.
  4. Your Raspberry Pi is now paired with the speaker, but it won’t output audio to it yet. Right-click on the Volume Control applet in the top-right of the screen and choose your speaker from the list (it is below Analog and HDMI).

A pop-up will display ‘Connecting to Bluetooth audio device’. Now double-click on of the music files in Files Manager. The VLC app will open and your music will start playing through the Bluetooth speaker.

When you restart the Raspberry Pi, you will need to reconnect to the Bluetooth speaker (this isn’t the same as pairing – it is still paired). Click on the Bluetooth icon, choose your speaker, and select Connect from the menu.

You can use the Bluetooth menu to disconnect, if you don’t want to use a device for the time-being. Or remove it entirely if you don’t want to use it again.

Subscribe and never miss an issue

 Get a free Pi Zero W with every twelve-month print subscription

Get a a brand new Raspberry Pi Zero W, a case for it, and a selection of adapter cables with a twelve-month print subscription to The MagPi!

From The MagPi store


Subscribe to the newsletter

Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.