HOWTO: Redirect sound output from computer to mobile
Let's suppose You want to watch movie streamed to Linux.
But You need headphones for any reason.
Then You have choice to either buy headphones for computer
or You can just stream directly the audio to Your Android
Phone and use Your favorite headphones attaches to phone.
On source computer:
1] modprobe snd-aloop index=1 pcm_substreams=1
2] Add to ~/.asoundrc:
pcm.loop {
type plug
slave.pcm "hw:Loopback,1,0"
}
3] On Termux on Android Phone:
ssh -C user@hostname sox -q -t alsa loop -t wav -b 16 -r 48k - | play -q -
Then You have to set default audio output device on source
computer to loopback:
$ pactl list short sinks
You'll see the exact name for the loopback sink.
Set defaults:
$ pactl set-default-sink alsa_output.platform-snd_aloop.0.analog-stereo
There is a small addendum to this:
The above works fine quite alright on wi-fi. But in some cases
You'd want to redirect audio output to the mobile phone while
You're on different (mobile) network. In this case it's reasonable
to cut down the bandwidth and throughput requirements.
Currently I achieved like 3kB / sec (the mp3 transfers each second second)
$ cat audr
#!/bin/bash
pulseaudio -k
pulseaudio --check
pulseaudio --start
ssh -C user@hostname sox -c 1 -q -t alsa loop -t mp3 -r 10k - | mpg123 -
..
This get's the audio transfer to something like 8 GB / month
in case it would play 24/7.
On the source computer (e.g. Debian) the sox has to have mp3 support:
libsox-fmt-mp3 - SoX MP2 and MP3 format library
And in the target Termux there has to be mpg123
BTW: There is no need for the sound card with ALSA...
the snd-dummy module can be used together with snd-aloop.
# modprobe snd-dummy
# modprobe snd-aloop
And the pactl should give something like:
# pactl list short sinks
0 alsa_output.platform-snd_aloop.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNING
1 alsa_output.platform-snd_dummy.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
The rest is the same and cheap vps can be used as a sound player or streamer to the mobile device.
Thank You for listening...