Alexander Gromnitsky's Blog

Share a PulseAudio sink with an Android phone

Latest update:

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:

  1. Load module-simple-protocol-tcp module into a PulseAudio server.
  2. The module can use any sink you prefer, typically the default one.
  3. Initiate a regular playback using the selected sink (with mpv, vlc, a web browser, whatever).
  4. Connect to the server from an Android phone using Simple Protocol Player.

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:

#!/usr/bin/make -f

# 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

$(answer):
    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)
    rm $<

.DELETE_ON_ERROR:

Run it as

$ android-pa-share start

Beware that module-simple-protocol-tcp module doesn't support authentication, hence protect the port (4713 in the script above) from the WAN.


Tags: ойті
Authors: ag