Thursday, January 1, 2015

Audio Streaming to Bluetooth Speaker Using Raspberry Pi B+

Edit 2016Jan3: This guide was based on old Raspbian Wheezy distro, some packages were no longer included in latest Raspbian Jessie distro. I'll have a look on how to make the old setting works on Raspbian Jessie.

Edit 2017May14: Finally found a way to make it work on Raspbian Jessie distro. Please refer to this link for instructions to setup bluetooth speaker.

Hi~ Here is a small project for my new RPi B+. So i got some bluetooth peripherals lying around the house, so i thought i can make a small music box using RPi. Did some research and got it working!

So here are what you need for the hardware:
  1. RPi Model B+ with Raspbian Installed (Should work with model B or A)
  2. Bluetooth Speaker
  3. USB Bluetooth dongle
  4. USB Wifi dongle / LAN cable for internet connection
  5. 5V 1A/2A Power Supply
Figure6: Hardware Setup
 If you have everything ready for the hardware. You need to install some packages to your RPi before you can connect to your bluetooth speaker. Boot up your RPi, but do not plug in your bluetooth dongle yet. Open up terminal and enter commands below for installation of the required packages.
  1. "sudo apt-get update && sudo apt-get upgrade" - upgrade your Raspbian packages list to latest version. Wait for program to finish upgrade before next command.
  2. "sudo apt-get install bluetooth bluez bluez-utils bluez-alsa blueman" - install five packages for bluetooth dongle and bluetooth audio. Wait for installation to complete before next command.
  3. "sudo usermod -a -G lp pi" - this command will add "lp" group under account "pi". You account need to have access to this group for this to work. If you are using other account, just replace the "pi" in command with your account name.
  4. "sudo nano /etc/bluetooth/audio.conf" - you need to add some command in the audio.conf file. This command will open nano text editor and allow you to edit the file. You need to add in two line in the file. "Enable=Source,Sink,Socket" and "Disable=Media". Refer to Figure1 and Figure2 below. After edit file, press Ctrl+O and Enter to save the file.
    Figure1: Editing audio.conf file
    Figure2: Add in highlighted two lines in audio.conf file
  5. Once save the file, enter command "sudo shutdown -h -P now" to safe shutdown the Pi. Once you see green light blip for 10 times. You can turn off the power supply.
  6. Now plug-in your bluetooth dongle to the USB and start up your RPi.
  7. Wait for boot complete, go to terminal and enter command "lsusb". You should see your bluetooth dongle available as shown in Figure3. You can refer HERE for list of working bluetooth adapter for RPi in case your bluetooth dongle is not detectable.
    Figure3: Bluetooth Dongle Detected in USB list
  8. If you able to find your bluetooth dongle in USB list, you should see a Bluetooth icon at your RPi tray. If you did not boot up your Pi in GUI and you are in command line interface, enter "startx" to start your GUI session. Refer to Figure4 below to setup your bluetooth connection with your bluetooth speaker with 3 simple steps.
    Figure4: Setup Bluetooth Connection with Your Bluetooth Speaker
  9. Follow up on step 8. You can also click "Trusted" on the device as shown in Figure4 if you want to let the speaker auto connect to RPi in the future. Mine is showing "Untrust" because i've already "Trusted" this device.
  10. Open up terminal again to edit one last file. Enter "sudo nano ~/.asoundrc" and enter the script as shown in Figure5. For line start with "device 00:", that the place where you put your bluetooth speaker's MAC address. You can find you MAC address in Figure4. Copy and paste in to the script. Once done save the file and you are done setting up the bluetooth portion for RPi.
    Figure5: Script to Connect Bluetooth to Alsa
  11. If you completed the steps up to 10, you are almost ready. You just need to install one more package so that you RPi can play music. In this case i recommend Mplayer because it is a terminal player that can support wide range of audio format including m4a. Go to terminal and enter "sudo apt-get install mplayer" and wait for installation complete.
  12. Once you complete installation of mplayer. Navigate to your music folder using terminal and then enter command "mplayer -volume 10 -ao alsa:device=bluetooth youmusic.mp3" to play music.
  13. You should be able to listen to your music from bluetooth speaker from now. 
  14. Here is the video showing the working bluetooth speaker using RPi.

Hope you like this tutorial. Thanks for your time!



  1. do you know how to stream audio to wifi speakers (jongo s3) on the rpi? haven't been able to find much on the subject. it must be doable because i was able stream wifi (limited to a few apps) with my android.
    thanks John

    1. Hi John, unfortunately i haven't try this yet because i don't own a wifi speaker myself. You can start searching for packages available in Linux that can enable access to your wifi speaker. Good Luck. =)

  2. Hi, nice tutorial!
    Is it possible to stream online radio instead of mp3? If yes, can you tell me how?

  3. Look great...
    I will try to make this working for my Home Automation.. [ stream music to a Bt speaker... ]
    Is there a option to have acces from a Http comand/.
    Or acces from a lua/bash script...
    My Home automation can work with this scripts an can set the player then on or off...

    Like to hear [ i orderd my first pi] so i must wait ]

  4. Actually there is a github project (pulseaudio-dlna) that streams wifi to dlna renderer speakers (such as I have). It works on Ubuntu, Linux Mint and LMDE 2 and I would imagine any linux box that runs some form of debian jessie. But it requires jessie which at the moment the RPI doesn't support (I haven't had any luck upgrading from wheezy to jessie on the pi yet). I did try running it on my goflex that runs debian jessie (armel) but it kept crashing pulseaudio. I couldn't figure out how to get pulseaudio to stay up and work correctly while pulseaudio-dlna was running.

  5. Thanks for showing how to make bluetooth speaker work with RPi! Curious what wifi and bluetooth adapters did you use?

    1. I bought the wifi module from element14, from adafruit industries. Link below:

      For the bluetooth dongle I'm using the one comes with my Samsung hands free module. I believe it is the normal Cambridge Silicon bluetooth 2.0 dongle.

  6. Just about any bluetooth dongle that supports a2dp should work. I would suggest ver 4.0 and up either Broadcom or Cambridge Silicon Radio as Linux supports both. You should be able to purchase it on ebay for $5 and up. The following bluetooth dongle should work.

    For WiFi once more any wifi dongle that supports N should work. However the dongles don't have a whole lot of range as the antenna is very short. If range and signal strength is a concern I would suggest something such as Edimax EW-7811UAC 11AC (Amazon) or similar that has a high-gain external antenna will work much better. They are a little pricey though.
    CAUTION: no matter what you do be careful to always use the extension cradle with it as the connections on the dongle itself are reversed and will blow-it-out if you plug it directly into the usb port without the cradle.

    The other problem with the Edimax is that you will have to build a driver for it. It wasn't easy so if you're not familiar with compiling you will probably have problems with getting it to compile without errors. Check out MrEngman's post at
    on how to build it. He may be willing to help you with it.

    Good luck

  7. Thanks for the info and the time u took to share this project.
    My pi b+ runs only osmc (kodi) as a media player. Do you know if I can use a bluetooth dongle on the pi to play the audio from movies and series to a set of bluetooth headphones?

  8. Thanks for this tutorial I got a RPi 2 connected to a bluetooth speaker. I followed all steps except that after step 7, I cannot see the Bluetooth icon within the GUI. Searching google lead me to an important step that appears to be missed on this guide:

    sudo apt-get install blueman

    After I installed blueman, everything else was good.

    1. Thanks for the feedback! Yes somehow i miss out blueman (bluetooth manager) in my post. Edited my post.

  9. Really good tutorial. Is it possible to play ALL audio through the bluetooth speakers? Thanks

  10. Thanks for the tutorial. I'm not able to install the Bluez apps though. It tells me "E: Package 'bluez-utils' has no installation candidate" and "Package bluez-utils is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    However the following packages replace it:

    I tried the Bluez package but it didn't work. Any suggestions?

    1. May i know which repo you use for your Pi? I was using wheezy Raspbian when i write this post. Not sure it will work for jessie Raspbian or not.

    2. This comment has been removed by the author.

    3. "sudo apt-get install bluez" is the command if you are using jessie version

    4. Here is the full post on how to make it works on raspbian jessie.

  11. Hi can you tell me which blotooth dongle are you using?

    1. Its a random bluetooth dongle lying around my room. If i remember correctly it was a bluetooth dongle for my Samsung handsfree module. Based on the driver, the name is Cambridge Silicon bluetooth 2.0 dongle.

  12. I have question does all formats can play in bluetooth speakers. Some dont have it. - where i bought a bluetooth speaker which has more options in speaker

    1. It should be able to play all audio supported by mplayer.

  13. Have you been able to make it work under Jessie ? If so, how ?

    1. Hi Andre, It seems like the old methods are not working. I switched to PulseAudio to make it work under Jessie however, it require GUI to work. I'm still figuring out how to make it work under command line.

    2. Here is the full post on how to make it work under Jessie.

  14. I do not run like you that music. You can help me

  15. This comment has been removed by the author.

    1. This comment has been removed by the author.

  16. hi! really thorough tutorial, much appreciated.
    so i have managed to follow it through, but the song does not play,
    step 12 results in a bunch of code, where these were the points that i could find:
    BILITIES failed: invalid argument
    failed to initialise alsa:device=bluetooth
    could not open/initialise audio device-> no sound
    exiting... (end of file)

    Would really really appreciate any insights

    1. May i know which distro you are using? If you are using jessie, please follow instruction in post below to make it work.

  17. Hi,

    Bluetooth audio streaming is no more supported by ALSA, you have to do it with PulseAudio, find a tutorial here:

    1. Great post. I was just about to create another post using PulseAudio and Bluez5. Will publish once complete =)

    2. Here you go.