Share a PulseAudio sink with an Android phone
While attempting to find a pair of semi-decent USB-only speakers, I
became so frustrated that contemplated creating a mock simulator with
"greater dynamic range", "improved bass", & even "lower distortion" to
reliably replicate the advertised "quality" of these fake USB
speakers. (Why fake? Because they all (?) use USB-A for power &
require a 3.5mm jack input for sound.) Most speakers in the $0-$100
range often sound as if someone placed a phone in a metal bucket &
started playing Quake 2 theme music using the phone's mighty speaker.
Here's a high precision simulator:
module-simple-protocol-tcp module into a PulseAudio server.
- The module can use any sink you prefer, typically the default one.
- Initiate a regular playback using the selected sink (with mpv, vlc,
a web browser, whatever).
- Connect to the server from an Android phone using Simple Protocol
For an additional milieu, put the phone in a bucket. $100 saved,
"greater dynamic range" achieved.
The scheme is compatible with PipeWire too.
Coincidentally this can be used as a rustic spying technique: you can
listen to everything a machine with a running
module-simple-protocol-tcp module plays.
A script (requires dialog(1) and jq(1)) that draws
a menu with available sinks and starts listening on a socket:
# the standard pulseaudio tcp port
port := 4713
answer := $(shell mktemp -u)
status:; pactl list | grep tcp -B1
stop:; -pactl unload-module module-simple-protocol-tcp
pactl -f json list sinks \
| jq -r '. | @sh "\(.index) \(.description)"' \
| xargs dialog --keep-tite --menu "Local sink" 0 0 0 2>$(answer)
start: $(answer) stop
pactl load-module module-simple-protocol-tcp rate=44100 format=s16le channels=2 source=`cat $<` record=true port=$(port)
Run it as
$ android-pa-share start
module-simple-protocol-tcp module doesn't support
authentication, hence protect the port (4713 in the script above) from