User avatar
Douglas6
Posts: 4778
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

[Guide] Stream audio to the Raspberry Pi over Bluetooth

Mon Aug 05, 2019 1:24 pm

Here's a quick guide to streaming audio to a Raspberry Pi over Bluetooth. PulseAudio is not required or desired. If you want your Pi to act as an audio sink, that is, to act as a Bluetooth speaker, follow the steps.

1. Unpair your Pi. Use bluetoothctl to remove any pairings it may have. On your phone, or other source, forget any pairings.
2. On the Pi, edit the bluealsa service unit

Code: Select all

sudo nano /lib/systemd/system/bluealsa.service
EdIt the ExecStart line to add to the end of the line '--profile=a2dp-sink'. The line should look like

Code: Select all

ExecStart=/usr/bin/bluealsa --profile=a2dp-sink
Save the file.
3. Now, you're also going to want to start bluealsa-aplay. Systemd works good for that.

Code: Select all

sudo nano /etc/systemd/system/aplay.service
Insert into this file the following:

Code: Select all

[Unit]
Description=BlueALSA aplay service
After=bluetooth.service
Requires=bluetooth.service
 
[Service]
ExecStart=/usr/bin/bluealsa-aplay 00:00:00:00:00:00
 
[Install]
WantedBy=multi-user.target
Yes, use '00's for the <bdaddr>. Save the file. Enable the service with

Code: Select all

sudo systemctl enable aplay
Now, reboot.

Now you can pair and trust your phone (etc.) with the Pi, connect, and the phone's audio will play over the audio jack of the Pi.

[Most of this information comes from https://scribles.net/, which has many excellent guides for Bluetooth and BLE on the Pi]

User avatar
Pulsar33
Posts: 105
Joined: Sun Aug 25, 2019 4:06 pm
Location: Bordeaux France

Re: [Guide] Stream audio to the Raspberry Pi over Bluetooth

Sun Sep 22, 2019 5:53 pm

Hello

I was happy to find this guide because my first attempt when discovering the Pi4 was to install pulseaudio (as I used to do on my desktop). Unfortunately, it doesn't seem to be a good idea because many things don't work and the worst is that all sounds are set to mono instead stereo, which is unacceptable. However, I installed A2DP Sink with pulseaudio and it worked easily (but without stereo). So my Phone and my Pi4 can do the job.

So I tried your solution with ALSA on a fresh installed SD card. All is clear and easy to do, and seems to go well, except that there's no sound :(
At the same time, I can play audio with VLC for example, so the sound works on the Pi4. My Phone sees the Pi4, connects to it and displays "bluetooth audio" confirmation, with the corresponding ajusted audio level. The Pi4 sees my phone and register it as connected. All seems to be ok, but there's no sound.

I can see that :
$ systemctl list-units | grep ALSA
aplay.service loaded active running BlueALSA aplay service
bluealsa.service loaded active running BluezALSA proxy

Please, does someone have an idea of the problem ?
Best regards.
Pulsar33
Pi 4 with 4Gb memory, DVB TV pHAT ------------------- Desktop : Core i5 Linux MINT 19.2

User avatar
Douglas6
Posts: 4778
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: [Guide] Stream audio to the Raspberry Pi over Bluetooth

Sun Sep 22, 2019 8:33 pm

Is your phone Android or iOS?

User avatar
Pulsar33
Posts: 105
Joined: Sun Aug 25, 2019 4:06 pm
Location: Bordeaux France

Re: [Guide] Stream audio to the Raspberry Pi over Bluetooth

Sun Sep 22, 2019 9:49 pm

None of these, but Ubuntu touch.
As said above, my phone works with A2DP Sink on Pi4 board if I install pulseaudio, but in mono and pulseaudio has other drawbacks.
BR. Pulsar33
Pi 4 with 4Gb memory, DVB TV pHAT ------------------- Desktop : Core i5 Linux MINT 19.2

Radiofreak1041
Posts: 3
Joined: Sun Sep 29, 2019 9:53 pm

Re: [Guide] Stream audio to the Raspberry Pi over Bluetooth

Mon Sep 30, 2019 5:20 pm

I got audio streaming to the Pi3B+ to work via Bluetooth (A2DP) using Bluealsa, but in mono. Is there anyone who got this to work with stereo audio? And is it possible to route this audio to another program like Stereo Tool that can modify and output it to the audio jack?

User avatar
Pulsar33
Posts: 105
Joined: Sun Aug 25, 2019 4:06 pm
Location: Bordeaux France

Re: [Guide] Stream audio to the Raspberry Pi over Bluetooth

Mon Sep 30, 2019 6:14 pm

Hello,

Would be happy to know how to make this work.
Someone has an idea ?

Best regards
Pulsar33
Pi 4 with 4Gb memory, DVB TV pHAT ------------------- Desktop : Core i5 Linux MINT 19.2

User avatar
Douglas6
Posts: 4778
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: [Guide] Stream audio to the Raspberry Pi over Bluetooth

Mon Sep 30, 2019 6:25 pm

My Pi4 A2DP sink is working in stereo. No additional steps than the ones posted above.

Radiofreak1041
Posts: 3
Joined: Sun Sep 29, 2019 9:53 pm

Re: [Guide] Stream audio to the Raspberry Pi over Bluetooth

Wed Oct 02, 2019 6:19 pm

It's very nice to hear that it works for someone! Can you maybe provide some information about your setup? Do you use ALSA as well, or PulseAudio? And have you specified an audio playback device somewhere in a config file? What RPi and phone OS's are you using?
Sorry for all these questions, I'm just excited to hear it IS possible :D

User avatar
Douglas6
Posts: 4778
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: [Guide] Stream audio to the Raspberry Pi over Bluetooth

Wed Oct 02, 2019 6:52 pm

More detail. I took a fresh Raspbian Buster image from the Raspberry website, updated and upgraded it on my Pi4 (this was 2 months ago). I then performed the steps listed in the first post of this thread. Exactly nothing more; exactly nothing less.

After reading your post, I found a stereo test audio file on the Web. With my Android 9 phone, I played the mp3 sample to my Pi with M-Audio AV40 speakers plugged into the audio jack. I clearly heard the words "front center" centered between the speakers, "side left" coming from (only) the left speaker, and "side right" coming from (only) the right speaker. The test file I used was the first link on this page: http://www.aoakley.com/articles/2018-08 ... o-test.php.

I think that's everything.

impersson
Posts: 1
Joined: Sun Oct 06, 2019 1:29 pm

Re: [Guide] Stream audio to the Raspberry Pi over Bluetooth

Sun Oct 06, 2019 1:32 pm

Douglas6 wrote:
Wed Oct 02, 2019 6:52 pm
More detail. I took a fresh Raspbian Buster image from the Raspberry website, updated and upgraded it on my Pi4 (this was 2 months ago). I then performed the steps listed in the first post of this thread. Exactly nothing more; exactly nothing less.

After reading your post, I found a stereo test audio file on the Web. With my Android 9 phone, I played the mp3 sample to my Pi with M-Audio AV40 speakers plugged into the audio jack. I clearly heard the words "front center" centered between the speakers, "side left" coming from (only) the left speaker, and "side right" coming from (only) the right speaker. The test file I used was the first link on this page: http://www.aoakley.com/articles/2018-08 ... o-test.php.

I think that's everything.
Hey I have the raspberry pi 4 and get the error

"Failed to enable unit: File aplay.service: Bad message"

when entering

"sudo systemctl enable aplay"

I tried some other guide before that didn't work so maybe I messed up my installation? Im running raspbian.

User avatar
Douglas6
Posts: 4778
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: [Guide] Stream audio to the Raspberry Pi over Bluetooth

Mon Oct 07, 2019 11:26 am

Double check the the contents of aplay.service. You have mis-typed something.

Return to “Graphics, sound and multimedia”