Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login
Using a Raspberry Pi as a Bluetooth Speaker with PipeWire (www.collabora.com) similar stories update story
198 points by mfilion | karma 3025 | avg karma 6.65 2022-09-02 09:58:02 | hide | past | favorite | 65 comments



view as:

This is a neat way to use the PI, if you want to avoid BT all together and have access to a web browser on the PI you could also login to Spotify.com and use your phone / watch to manage what is playing but have the output set to the web browser on the PI. This assumes you use Spotify of course =)

I have a similar setup in my workshop and it has been solid for years.


Better yet would be to use spotifyd[0] for this. I tried to set this up with my RPi a while ago but was defeated by Linux audio. Instead I just bought a Sonos. Oh, well.

[0]: https://github.com/Spotifyd/spotifyd


You don't even need a graphical user interface, a web browser or the official Spotify app to accomplish this either - you can use open source projects that use the official Spotify API to create an extra Spotify speaker you can control from Spotify on another phone or PC.

There are loads of these projects, often in docker containers you can launch with a single command:

> https://hub.docker.com/r/flaviostutz/rpi-spotify

> https://github.com/qSharpy/raspotify-docker-compose

> https://github.com/Spotifyd/spotifyd

etc etc.

I've several speakers integrated with various Spotify API based solutions around my home running on various RPi hardware. Some of these projects do even more, like add Airplay streaming too.


Interesting! Combine this with the product(s) from hifi berry and you can relatively cheaply turn any high quality speaker into a standalone. Who needs Sonos.

I'm actually using HifiBerry! They provide a great OS built in partnership with B&O that supports Spotify/Airplay with their devices out of the box:

https://www.hifiberry.com/hifiberryos/


Check out HiFiBerryOS with their DSP hat and a calibration mic.

Pi + DSP Hat + AIYIMA A07 + decent speakers + Roon (or other) = A fantastic and inexpensive sound system. You could spend 50x as much and not get as good sounding system.


DSP hat + calibration mic is exactly the approach I went with, agreed it is an incredible setup for the money.

> https://www.hifiberry.com/shop/boards/hifiberry-dac-dsp/


All of those use reverse engineered APIs, particularly for playback. Spotify's APIs only support playback through a Web browser (that supports their DRM).

If the goal is to play music from your phone, then buy a phone with a headphone jack. Problem solved!

.


It's nice to be able to use my phone normally (put it in my pocket etc) while playing audio from it on nicer speakers

Actually I kept wanting to use my phone (which has a headphone jack) as a bluetooth receiver for audio from the PC, and remember attempting to spelunk into the bluez stack (for use with lineageos) and getting frustrated quickly.

There's some niche usecases (e.g. lengthy video editing on a PC while wanting to move around listening to music on your phone - airfoil (wifi) technically works but at the time was a bit laggy).


Your phone has XLR outputs? Or how do you want to connect the speakers? And you want to do this plugging every time you come home and listen to music?

I mean, you do you, but that sounds like a very inconvenient "solution".


Pi's can also be used as servers and receivers for the open-source Logitech Media Server software. I've been successfully using it for synchronized multi-room audio. It has support for both local music and streaming services.

Please say more about this! I've wanted to do this for ages.

I am using this. LMS is running on the network. UI is material-ui (works great on mobile as well). Spotty as Spotify plugin.

I can play music directly from my mobile Spotify (so supports Spotify Connect). I can see all my Squeezebox players there, combines synced players flawlessly.

Also plays local files. And also directly from youtube.

I have about 9 players on different rooms and could not be more happy with the setup.

If you would like to know any specific details, just ask. Happy to elaborate.


What are your players? What kind of device?

Currently I have multiple different Squeezebox players (Boom, Radio, Receiver, Touch), then on mobile Squeezeplay app (Android) for mobile usage (sometimes quite handy, when somewhere else than home, nice way to have own music library with me via VPN with same UI as home). Also Chrome speakers are players from LMS point of view.

Squeezeboxes are rather durable, probably will use those for many more years. Have been also collecting little replacement player stock :)

Wanted to evaluate esp32 -based player mainly for hacking purposes, but havent found yet time to work on those.


If you like it simple max2play is an image for that. https://www.max2play.com/en/

Wow, I'd not thought about that in ages. I still have the original slimp3 around here somewhere....

And I have a Squeezebox 3/Classic I've been meaning to drop off at electronic recycling... but it's such a nice object!

I have 4 of them. Need any more?

somewhat unrelated but I recently looked for a pi and it was sold out or the price tag was 10x the regular price everywhere, mostly because of the chip shortage. Am I looking in the wrong places?

They are in short supply, however you can still pay normal retail price. Check https://rpilocator.com/ .

From the parent link you can find the pilocator Twitter account, and your can set that to notify your phone whenever there is new inventory. In the U.S., Adafruit has been doing big drops the last few Wednesdays and Thursdays, but you need your account and 2FA set up ahead of time.

2x is current normal due to shortages, 10x is definitely wrong places.

You can snipe at 1x from the usual rpi vendors when they come back in stock, if you make the effort.


Please only buy from certified vendors and do not under any circumstances pay anyone over normal retail price.

Part of me wants to buy a $200 pi on Amazon, wait 29 days, and then return it. I enjoy the thought of a scalper having his inventory unavailable until price normality returns.

Also, some retailers have just the pi out of stock, but have it in stock if you get a bundle with a case, etc. That's how I got an 8GB one a few weeks ago.

I've had good luck with the Le Potato boards for RPi style applications. They are in stock and ~$55USD. Generally compatible with RPi4 cases and accessories.

The shortage is insane, and seems as if someone is trying to cripple supply for small autonomous computers that could be used for UAVs and guided munitions - isn't that a possibility, actually?

Seems it's more due to a number of scalpers who use(d) automated scripts to make bulk purchases from online vendors in order to sell at a markup on sites like amazon.

That's why the legit vendors like Adafruit now set a quantity limit and also require registration (with phone number IIRC) to buy them.


I’m all for hacking with the Pi, god knows I’ve a tendency of buying them for every automation idea I may have, even if only an embarrassingly small percentage is actually ever implemented.

However, for this use case, I’d recommend one of those Bluetooth “pen drives” with a P2 conector. I’ve used one powered by a phone charger connected to a stereo for over a decade. It’s cheep and works as well as Bluetooth possibly can (pairing sucks, range too, etc)


> However, for this use case,

As a bluetooth speaker, perhaps yeah. To me, the title described a capability clearly. I might already have, for example, a KodiTV media rpi. Now I know I can add more features to this system easily.

General purpose computing is great. We can keep exploring & expanding what we do; being limited only by imagination is excellent. We could add public announcement capabilities, could have the rpi connected to webconference software, could set up music-playing daemons or internet radio (somewhat covered by KodiTV). This article was a clear way to state what capability is possible. And it's mostly all built-in to the latest greatest free desktop technology, requiring only a little glue to make the bluetooth connection seamless:

> It provides Bluetooth® A2DP support with optional codecs (SBC-XQ, LDAC, aptX, aptX HD, aptX-LL, FastStream) out of the box. At the same time, WirePlumber automatically creates the connection between the A2DP source and the audio chipset when a remote device, like a phone or a laptop, connects. This makes the configuration very easy, as PipeWire will work out of the box. We will only need to set up BlueZ to make the system headless.


Any recommendations? I got one from AliExpress for my car and when it plays the navigation instructions it seems to mess up the order of the received data packets, so it says "100 in meters..." instead of "In 100 meters..."

Not anyone in particular. Any of this should do:

https://www.amazon.com/s?k=bluetooth+p2+adapter


I’ve had decent luck with shairport-sync (I think the name was) for Airplay audio. Only relevant for mac/ios, which I happen to use. Video playback and streaming airplay audio syncs up though, totally unlike windows with bluetooth audio, which I discovered in the past. I use a USB sound card with an older «dumb speaker» of good but analog quality.

I do the same with a Pimoroni DAC SHIM (a little PCB you can slot between the Pi and another connected device)

I do the same, and think it’s a great setup. I have a few around the house attached to older (nice) dumb speakers.

But really, the extra USB audio adapter is a must here. The internal Pi audio hardware, I found to be very noisy. The USB DACs I bought were also super cheap (<$10). You can scale this up in cost as much as you’d like.


Agree, the built-in DAC is so noisy it’s more or less unusable. A USB DAC is not too expensive and can be plugged into some random laptop, too.

I had set up ,rtmp server with ffplay as player ,with nobuffer flag ,works fine with video and audio cast

Is it possible to set this up so that multiple devices can be paired and stream audio to the same speakers simultaneously?

Using my old 2015 Macbook Pro for this; OCLP allows enabling airplay receiver for unsupported macs.

I use shairport-sync on my old macs for this, installs with brew and has a launchd service and everything

I'd recommend Volumio - gets you Spotify connect for your raspberry pi, and if you have a NAS, it can index that too

Volumio is pretty good. I used the free version. I've moved to Roon and it is on another level. Check it out if you would like to rediscover your music collection.

Is Spotify connect still working [will it keep on working]? I thought they'd have [were about to] drop the old API implemented by librespot (et al.) in favor of a pure web API?

I don't know exactly what volumio are doing. But librespot itself does currently still work. Who knows for how long (I doubt Spotify themselves know what they are doing). Librespot is transitioning to the new API, that API has already been implemented by other ports e.g. Librespot-java (and psst). It's not a pure Web API. It's a messy mix.

Volumio is ok, but I much prefer moodeaudio.org. It is also open source.

I use my Linux machine as a Bluetooth speaker with nice big speakers plugged in. Literally required 0 extra software. Just pair and then in my iPhone, hit the little (i) button and selected "speaker."

In times past, was it not easier to share audio output devices on Linux computers with normal networking or Bluetooth?

I never much cared for audio applications but I can distinctly remember it being trivial to use my Ubuntu PC as an audio device for pretty much anything else. Dread to think of the Bluetooth delay though.


A few years ago I already experimented with this[1]. However I'm still wondering why the bluez api does not let you set the playback position[2]... it is pretty awesome to not only use raspberry as bluetooth receiver but also use GPIO-Buttons or IR remote to send commands to the connected bluetooth devices (play, pause, next, etc.), but without the ability of setting a playback position that feels kind of incomplete - I would have loved to implement the "rewind 30s" button :-)

[1]: https://github.com/sandreas/raspberry-bluetooth-receiver

[2]: https://stackoverflow.com/questions/50190477/bluez-and-dbus-...


It's worth opening a bug against bluez to ask for this if one doesn't exist already.

That's quite... overpowered for what it does, considering that the majority of BT speakers are usually based around a dedicated SoC with a few hundred MHz of CPU and at most several MB of RAM.

given the shortage of Pi's available on the market right now, and the fact that you can get Bluetooth adapters for speakers on Amazon for a few bucks, it's probably not applicable anymore for real world usage.

But, it's a cool writeup and a nice learning process that is documented well.


It was never applicable directly, BT receivers are ancient tech that costs very little.

But what if you wanted to do something more fancy like build a jukebox that also had BT in addition to a web based control front end?


right.

even if you wanted to stay over-powered but try to remain budget friendly a ~3-5usd esp32 would handle this.



Or a hifi-berry amp. I don’t use Hifi-berry’s distro anymore though. I use diet-pi. Also Roon. But you don’t need Roon for airplay or casting.

The sound output through the 3.5mm jack is notoriously low quality.

Use a sound card.


Is there a book that explains all this dbus, glib, gstreamer mumbo-jumbo? Despite knowing a lot about classic Unix stuff and Python, I don't think I could write something like this by cobbling advice from a bunch of random webpages.

I'm not sure there is. They're all separate projects, that just happen to be the standard linux tech stack everyone(Except the people who don't) agree on.

It would be cool to write a guide to Linux programming that went over all the stuff you should know to do it the modern way.

dbus is a message bus that lets apps communicate. But it's object oriented and corba-ish and really complicated. It's wonderful if you don't have to think about it and are just copying and pasting. If you have to actually think about it , it becomes just OK. I'm still a big fan though.

Also, it's not really a pure message bus, it also does stuff like RPC calls. It's not just an MQTT type thing.

Gstreamer is a node based audio framework. It is the second best way to handle media as far as I'm concerned, the best being to not do so at all and use existing stuff because media always seems to be a nightmare in new ways every time.

You mostly never touch any actual media. You just set up nodes with code.

glib is a utility library that has to to with the GTK and gnome people , like gstreamer. It tries to give C the things that other languages I'd rather be using have. I'd still rather be using them instead.

There's also gobj. They have this object thing for C and they can auto generate bindings for python with introspection. This is how gstreamer works in python.

Unfortunately it is totally possible to make resources leaks and such using those bindings, autocomplete won't work, you may get unhelpful error messages, or just annoying unpythonic things, and you will probably need GDB to debug any segfaults, should you want to do anything very complicated.


Thanks for your help.

I tried running the script (audio receiver) on two desktop Linux laptops running PipeWire and bluez, but my other computers (acting as an audio source) would not pick up the receiver advertising A2DP (0000110d-0000-1000-8000-00805f9b34fb), and the receiver's terminal prints neither "AuthorizeService" nor "Service rejected" (indicating that Agent isn't taking effect). What did I do wrong?

Would only suggest using the Pi's HDMI output to an "HDMI audio extractor", feeding out toslink/spdif to something else, and avoid having the Pi DAC involved with it's 3.5mm output. Keep the signal digital across the cheap components until it gets to a high quality DAC that feeds the speakers.

Legal | privacy