
How to stream audio from your phone to your laptop with PulseAudio - manjana
https://bash-prompt.net/guides/pulse-audio-bluetooth-streaming/
======
grawprog
Linux audio can be a pain to get setup, but once you've got it setup you can
do some pretty cool things. I set something up similar the other day with
pulseaudio and a Bluetooth headset. I used it to route the headset channel
output on mixxx to the Bluetooth headset and the master output through the
speaker output. Sadly, the latency was too much to actually mix and beatmatch
properly, but it was a fun exercise and just the fact I could do it was pretty
cool.

~~~
sudosysgen
I wonder if it could work with modern AptX low-latency headsets.

~~~
Fnoord
Yes, but you need a different repo [1] for that. The default one supports only
SBC, this one adds support for AAC, AptX, AptX-HD, and LDAC. There's third
party packages for a myriad of OSes.

[1] [https://github.com/EHfive/pulseaudio-modules-
bt](https://github.com/EHfive/pulseaudio-modules-bt)

~~~
sudosysgen
Huh, I managed to get AptX working using just a small patch for BlueZ, but I
guess that would work too.

------
sirius87
aww man, this is so frickin cool. i just set this up, and its amazing. i
really needed this for audiobooks. thank you! <3

I use an app called "Voice" [1] on Android for audiobooks. I'm so used to it
that any other app or way to consume audiobooks seems below par.

[1]
[https://github.com/PaulWoitaschek/Voice](https://github.com/PaulWoitaschek/Voice)

~~~
bostonvaulter2
That seems interesting. Where do you get your audiobooks from?

~~~
frosted-flakes
Not the same person, but I get my audiobooks from Amazon Audible or my local
public library.

In the case of Audible, the first listen usually occurs in the Audible app,
but eventually I remove the DRM (converting it to mp3) and dump it in my Books
folder, which automatically syncs to my phone with SyncThing. I often re-
listen to audiobooks a year or two later, and subsequent listens happen in the
Voice app. I like having my books stored locally so I can listen to them
whenever, and it's also a safeguard if they ever disappear from Audible.

When I check out audiobooks from my library, I do it through the OverDrive
program on my Windows computer, which lets you download in mp3 format. It's
apparently on the honour system to delete the files once you finish it (which
is shocking), but I have to admit that I usually don't. If I ever do re-listen
to them, I just check it out from the library again, skipping the download
step because I already have the mp3s.

~~~
libraryatnight
I hadn't considered doing this to save my audible purchases. Going to, now!

------
armagon
I really wish there was a standard way of streaming audio over LANs that
worked between devices (like phones, computers, and smart speakers). Bluetooth
is such a pain, IMHO.

~~~
Spivak
If you are willing to accept something obscure PulseAudio actually has the
best thing. Look into the PulseAudio native module which just let’s you put a
speaker on the network as a normal boring sound output that works as if it was
connected to your computer.

\- Install the zeroconf module on both server and clients.

\- Enable the native module on the server and open the port and tell PA to
publish an mDNS record.

\- See the speaker just appear in your sound options. Play!

Actual instructions if you want to set it up
[https://blogs.gnome.org/ignatenko/2015/07/31/how-to-set-
up-n...](https://blogs.gnome.org/ignatenko/2015/07/31/how-to-set-up-network-
audio-server-based-on-pulseaudio-and-auto-discovered-via-avahi/)

~~~
kylegordon
I tried that and whilst it works for individual outputs, having it playing
synchronised with other speakers was not ideal given the timing discrepancies
that appeared.

~~~
Spivak
That should be fixable in the same way speaker groups in Google Home work.

Try using module-loopback to add some latency to the sinks and get them in
sync.

------
ofou
Is it possible to stream my phone mic to my laptop with Pulseaudio?

------
ajflores1604
Could probably roll something yourself using Spotify API. Has tempo available
as a query [https://developer.spotify.com/documentation/web-
api/referenc...](https://developer.spotify.com/documentation/web-
api/reference/tracks/get-audio-analysis/)

~~~
drewg123
This exists. I use it daily & it is awesome. Its called spotifyd:
[https://github.com/Spotifyd/spotifyd](https://github.com/Spotifyd/spotifyd)

~~~
mixmastamyk
I don't really understand how this fits in.

------
ourcat
Very neat. I assume this would work work on a cheap Raspberry Pi3 or 4 too,
via their Bluetooth and out via its audio jack.

Now I think of it, I seem to remember seeing a project like this to make use
of old wooden-box speakers (with a small amp inside too.)

------
krick
I still don't really understand Linux audio layers and how all this stuff
works together, how do I configure it, and so on. Is there some good
manual/blogpost/etc that would explain that?

~~~
josteink
> I still don't really understand Linux audio layers and how all this stuff
> works together

My simple understanding is that in the Linux audio stack you have the
following layers:

\- kernel-driver for local sound devices (provides exclusive access, no
mixing/multiplexing).

\- application-level audio-frameworks/APIs which are device-agnostic (pulse,
ALSA, jack), can support, mix and multiplex multiple concurrent
streams/applications.

\- these different application-level frameworks can have several different
back ends (for real HW, BT, virtual devices, network targets, etc, _other_
Linux application-level audio-frameworks. )

(Someone correct me if I’m wrong)

Applications target a framework, but not all target the same, so the
frameworks needs to be able to “plug together” so the speak.

This leaves the possibility if the following scenario:

App written for ALSA -> ALSA -> ALSA’s Pulseaudio backend -> PulseAudio ->
Real hardware

PulseAudio in particular is very featured, modular and pluggable which is why
most desktops Linux distros uses this by default these days.

It supports things like transparent network streaming between various kinds of
targets and lets you compose “audio graphs” if need to.

And that’s probably why it was chosen for the experiment in this blog post.

~~~
marcan_42
ALSA is (confusingly) two things: a userspace library and API, complete with
plug-ins and configurability and even mixing, and also the kernel API that
underlies it to talk to the physical hardware.

So a typical chain ends up being legacy app -> ALSA -> PulseAudio -> ALSA ->
kernel, because ALSA both frontends PA for legacy ALSA-only apps to use it,
and also backends PA to talk to the real hardware.

But ALSA isn't the only backend for PA. For example, Bluetooth audio output
will go via BlueZ and into kernel socket APIs instead, since Bluetooth audio
is a network protocol, not something handled in the kernel. And then there's
FFADO, a userspace driver for FireWire audio devices. And you can put JACK on
top of that. And then you can put PulseAudio on top of JACK. Or you can out
JACK on top of PulseAudio, but that'd be silly. And PA can go over the
network, both from app to a remote PA daemon, and also from PA daemon to PA
daemon. And there's also netJACK if you want to put that on a network.

And now PipeWire is replacing JACK and PulseAudio and impersonates their APIs
and also ALSA and lets everything talk to everything else.

Basically it's complicated, but also very flexible. In the end though, there
is usually one "default" setup that you get if you don't do anything on a
typical distro, and that's, these days, apps -> [ALSA ->] PulseAudio -> {ALSA
-> kernel, BlueZ -> kernel} for most typical use cases (native PA apps and
ALSA apps, local audio and bluetooth backends).

~~~
tomn
> Or you can out JACK on top of PulseAudio, but that'd be silly

It doesn't give you low latency, but if you don't care about that this is a
nice way of using JACK applications without interrupting other applications
that might be using PulseAudio; for development it's pretty handy.

------
miki123211
There's also Bluetooth Audio receiver, available in the Windows store for
Windows 10 2004 and up, for those who lean that way.

------
zerop
A friend want to do real time speech to text of phone calls for a call center
client. They want to capture the customer side of audio which is listened by
customer care agent. How to build the part to extract stream of audio from
this call conversation. Once extracted it would be passed to speech to text
streaming API to do inference.

~~~
dfg0987098x7
You'd process the audio streams in the call center telephony stack (kamilio,
asterisk etc)

~~~
zerop
Thanks. Isn't there any other options than touching telephony stack

~~~
Nextgrid
In their SIP client instead? But I agree with the parent, doing it at the PBX
level makes more sense.

------
neolog
Does anybody know, Is it possible to get high-quality two-way audio (e.g.
Zoom, Skype) over Bluetooth on Linux?

~~~
DenseComet
I believe this is an issue with the Bluetooth codecs. The higher quality
codecs use bandwidth dedicated to the mic to also transmit audio signals, and
cannot be used for two-way communication. If you actually look at the active
codec while just listening to audio, compared to the codec used when also
transmitting mic audio back, you will see that they are completely different.

~~~
boomboomsubban
I think you just need to tell Pulse to use a different profile.

[https://wiki.archlinux.org/index.php/Bluetooth_headset#Switc...](https://wiki.archlinux.org/index.php/Bluetooth_headset#Switch_between_HSP/HFP_and_A2DP_setting)

~~~
the_pwner224
Pulse already automatically switches the profiles. The issue is that the good
codecs are available in the A2DP profile which is sound output only. Pulse
will automatically switch back and forth from the HSP profile when an
application starts/stops using input from the headset mics, but in HFP you
don't have access to the high quality codecs.

Exact same thing happens on Windows and Android and on Apple devices.

The only case where your linked command would be necessary is when depending
on your Bluetooth devices & adapters the headset connects and then for some
reason registers as HSP instead of A2DP - so you manually switch it back to
A2DP to get HQ audio.

~~~
boomboomsubban
I was confused as like you said Bluetooth voice quality is fairly universal.

There is a patch to enable faststream in pulseaudio, but it sounds like very
few adapters support it

------
Beldin
I've done the reverse (connecting to bluetooth speaker) out of the box on
Ubuntu. So I'm surprised you'd need to install an extra PulseAudio module.

Perhaps the BT module was already installed? Or do you only need the BT module
to handle input, but output works via the kernel's BT stack?

~~~
danielheath
On my ubuntu machine the Bluetooth modules for pulse are installed by default.

------
rektide
Another one of the Linux projects that the cranky contakerous pissy segment of
the FOSS world just loves to spit on & hate, PulseAudio.

The FUD keeps coming from within the FOSS world itself. But I keep seeing
stuff like this, & thinking, this is such a flexible powerful tokit,
pulseaudio- why are so few haters willing or capable of acknowledging that
pulse does have serious upsides & vast intermixable capabilities? Maybe it's
just me but I feel le Pulse Audio is another one of those epic works that is
ceaselessly pointlessly shat upon while no one has anything remotely
comparable.

Also though still eager as heck to replace it all & this use case (a frigging
awesome ubicomp style use case) with PipeWire. Zeeeerrrooop ccoopppyyyy (to
the tune of leroy jenkins).

~~~
marcan_42
PulseAudio sucked when it first came out, then gradually grew enough features
and stability to make it worthwhile. The people still hating on it are just
too boneheaded to appreciate things like your speakers muting themselves when
you plug in headphones.

That said, it's still glitchy at times and can't do low latency properly, and
JACK1 is inefficient, and JACK2 has a messy threading model, and none of them
can do any-to-any latency compensation, so let's hope it all gets replaced by
PipeWire and we solve this mess once and for all.

~~~
nieve
I've had huge problems with PulseAudio over the last 14 years, but now there
are only two left: it randomly hard-hangs a few times a day and it sometimes
stops sending audio to a bluetooth speaker (or occasionally to headphones)
while acting as if everything is fine. The latter shows up with speakers from
two different manufacturers. Everything else I used to hate about Pulse has
gotten better: weird audio distortion, clicking & crackling, skipping, messing
up the soundcard enough to require reloading modules, getting stuck on mute,
jumping to max volume when things were connected - thankfully all gone.

I've had the hang & audio interruption on Mint, openSUSE, an Ubuntu so I'm
inclined to think it's something inside Pulse and I've got some hope that
those last bits will get fixed. (I am aware that actually playing sound is the
first responsibility of a sound system, but I'm being optimistic here.)

~~~
db48x
Nobody is going to be able to fix that hang unless they know the steps to
reproduce. Can you record pulseaudio with rr and capture it happening? Then
debugging it should be pretty easy.

------
AdmiralAsshat
Won't the quality of the audio over Bluetooth be incredibly compressed,
though?

~~~
esaym
Short answer is no. I'm not really sure why so many try to hate on bluetooth
audio. But don't take my word for it, hear for yourself. You can first read up
some on it[0] Then get the needed tools to encode audio into the exact same
format that your headphones would see [1]

Hopefully, you have an uncompressed wav file to test with. Unfortunately, the
sbcenc command wants the wav in the uncommon big-endian format. Not worries,
just do: "ffmpeg -i test.wav test.au" and it will convert it for you. Now feed
that .au file into sbcenc:

"sbcenc -B 16 -s 8 -j -b 51 test.au >test.sbc"

That is the default scheme for "bluetooth high quality". Personally I have not
found a difference in the sound. Of course note that the audio encoding is
adaptive, so if you put on your bluetooth headphones and walk 50 ft away, yea
it might sound bad...

[0]:
[https://en.wikipedia.org/wiki/SBC_(codec)](https://en.wikipedia.org/wiki/SBC_\(codec\))

[1]: [https://packages.debian.org/buster/sbc-
tools](https://packages.debian.org/buster/sbc-tools)

~~~
Renaud
My real problem with BT is how unreliable it is. I'd like to find someone who
never had an issue pairing some earphones or headphones and had it working
flawlessly every time.

There are many variants of BT audio and they don't all work the way you would
expect. It's still not rare to end up with lag if your combination of
hardware, software and receivers don't have compatible technologies like aptX.

For me the unreliable and lengthy pairing process is the major pain. Takes out
the earbuds, wait at least 10-20s to get them connected, then wait another 10s
for the phone to realize it needs to output to the earbuds. More often than
I'd like, I have to put back the buds in their case and take them out again to
force a reconnection because the phone or one of the buds said it was
connected but isn't getting any sound...

And I'm not talking about a cheap Chinese Android phone with a pair of crap
$20 earbuds. I'm talking about iPhone 11 Pro with Sony 1000XM3. It's not the
equipment, had similar issues with an iPhone 8 and Bose headsets, and with
various dongles and computers.

A friend recently thought his new Sony WH-1000XM4 headphones were not working
and asked me to have a look. Took me 15 minutes to hook them to Windows
properly. Turns out there are multiple devices that appear (but not at the
same time) during the pairing process and if you connect to the BLE stack, you
don't get the headphone functionality... (what functionality you get is a
mystery) and of course, no mention of that in the documentation.

Wireless audio is important enough that we shouldn't have to settle for these
subpar experiences. Although BT has made progress on the audio front by
providing protocols with lighter overhead and latency, it's still not
particularly suited for audio (no high quality transmission, mono/stereo only,
no multicast, lengthy connection, ...)

It is what is is, but it's not what it should be.

~~~
Jugurtha
> _My real problem with BT is how unreliable it is. I 'd like to find someone
> who never had an issue pairing some earphones or headphones and had it
> working flawlessly every time._

The first project I worked on was for elderly care[0], with a fitness tracker
we would connect with over Bluetooth Low Energy (BLE). The first things I had
done was to request the manufacturer's communication protocol for that device
and then abstract that away in a nice library so we could control the tracker
with Python functions `tracker.start_ecg()`, etc.

The second part was dealing with all the weird connectivity problems,
troubleshoot, and add helpful exception messages for others. Here's an
example:

    
    
      message = """
          We were unable to connect to the device {}{}{}...
          Bluetooth devices are tricky and even when you do everything
          right, you can still get this exception. Here are a few things
          to consider:
    
            - Simply retry to connect.
    
            - Check `rfkill list`: it will tell you whether your device
              is blocked or not. If it is indeed blocked, you can run:
              `\x1b[33mrfkill unblock bluetooth\x1b[0m` to unblock it.
    
            - Check `hciconfig`: it will tell you whether your device is
              down or up. If it is down, you can raise your device:
              `\x1b[33msudo hciconfig [hci0|hci1] up\x1b[0m`.
    
            - You can also restart the bluetooth service:
              `\x1b[33msudo service bluetooth restart\x1b[0m`.
    
            - Calling Bluetooth.connect with the wrong hci_device param
              can result in this exception, too. Check which device is
              active and call the method with that one.
    
            - Take a deep breath, you'll probably get this often.
      """
    
    

[0]:
[https://twitter.com/jugurthahadjar/status/130349692330808525...](https://twitter.com/jugurthahadjar/status/1303496923308085256)

~~~
maxerickson
What's the target market for a product that exposes the whole Linux device
stack to an end user?

~~~
Jugurtha
I don't understand your comment. Are you referring to the error message? If
yes, that is targeted to the developers using the library that controls the
device. i.e: us. The library helps us talk to a device by abstracting away low
level details.

------
yeswecatan
I've been playing around with mopdiy and it's excellent

------
cowmix
This is all well and good but I still can't get mono output going out of
Ubuntu 202004. The audio stack under most distros is still a weird mess.

------
grupthink
I'd like to see someone stream my pulse to my headphones and synthesize that
as music. The more amped I am, the more amped the music should be.

~~~
WD-42
Positive reinforcement loop until your heart explodes? Be careful.

------
animex
I'm confused... I have all my streaming available on my PC via web-browser.
Was this created primarily for Linux users?

~~~
diffeomorphism
This article is not about the "streaming" you are thinking about. It is about
using your PC as wireless speakers, i.e. streaming your phone audio to your
PC.

~~~
animex
But again... why would I ever do that? I have access to all my services on my
PC directly. I'm not aware of any phone-only streaming services?

~~~
diffeomorphism
What does this have to do with streaming? Obvious use case would be: I am
sitting on the couch and want some music played on my speakers.

Option 1: Get up from the couch, go to PC, put the music on, get back to
couch. Listen a bit, change my mind, get up again, change track on pc, get
back to couch.

Option 2: Have some kind of remote controls for the PC media player on my
phone (e.g. mpd). Requires some setup and only for one specific app, but very
similar.

Option 3: Use phone as normal and as output select the speakers. People
commonly do this with bluetooth speakers (which have their own issues) or you
instead use wifi as described in the fine article.

Your whole question is basically "why would anyone want wireless speakers?".

------
aasasd
Anything for the other way around, specifically from Mac to Android? Sort of
poor man's wireless headphones.

~~~
smegma2
Yes! There are a few answers here:
[https://superuser.com/questions/605445/how-to-stream-my-
gnu-...](https://superuser.com/questions/605445/how-to-stream-my-gnu-linux-
audio-output-to-android-devices-over-wi-fi) I'm using the top one and it works
well for me.

------
avodonosov
Sadly, there is no good way to stream sound over wifi from my android phone to
the rock64 connected to amplifier

~~~
sirius87
You could probably set the device as a DLNA receiver? [https://www.raspberry-
pi-geek.com/Archive/2014/08/Using-the-...](https://www.raspberry-pi-
geek.com/Archive/2014/08/Using-the-Raspberry-Pi-as-a-DLNA-receiver-for-a-
stereo-system)

Edit: [https://www.pimusicbox.com/](https://www.pimusicbox.com/)

~~~
avodonosov
I have dlna on the rock64 (volumio), the problem is on android side - there
are no tools to capture the sound and stream it to dlna.

Custom apps like BubbleUPnP are not satisfying, I want to stream any app sound
- chrome, youtube, any

------
fignews
Have shairplay installed on my Linux desktop to accomplish something similar
in the iOS playground.

------
brunoqc
Anyway to do it without bluetooth?

~~~
cheeze
Sure, run a 3.5mm from the phone to the mic port of any motherboard

~~~
stallmanite
I rue the day they remove audio jacks from desktop motherboards. Presumably to
improve water resistance.

------
WesolyKubeczek
I’m using shairport-sync for that.

