Play remote audio over an SSH connection with a Mac Client

Image for post
Image for post

I am working on my remote machine with datasets of audio files, and it becomes very uncomfortable to not be able to listen to the audio samples directly from the terminal.

Fortunately, PulseAudio allows us to do that very easily. My current setup is the following:

  • Remote Machine: Linux Server (Ubuntu 18.04)
  • Client: Macbook (OSX Catalina)

Follow these steps on your Client Machine:

1. On the Mac, install PulseAudio with brew :
brew install pulseaudio
2. Configure a listening daemon that will receive the audio from the remote machine. This daemon will not be persistent and will stop after you restart your computer or stop the process.
pulseaudio --load=module-native-protocol-tcp --exit-idle-time=-1 --daemon
3. Usually, PulseAudio will listen on port 4713, but double-check the listening channel with:
lsof -i -P | grep -i "listen"
4. Connect to your server by establishing a Reverse Port Tunnel. This will forward the audio from your remote machine, from the (arbitrarily chosen) port 24713 to our local port 4713.
ssh -R 24713:localhost:4713 server

Now follow these steps in your remote machine (inside your SSH session)

1. Install PulseAudio
apt-get install pulseaudio
2. Make the remote PulseAudio server send to the chosen port 24713:
export PULSE_SERVER="tcp:localhost:24713"
3. You can check that your computer appears as the listening device when you call pactl info:

Server String: tcp:localhost:24713
Library Protocol Version: 32
Server Protocol Version: 33
Is Local: no
Client Index: 12
Tile Size: 65472
User Name: xxxxxxxx
Host Name: xxxxxxxx-MacBook-Pro.local
Server Name: pulseaudio
Server Version: 13.0
Default Sample Specification: s16le 2ch 44100Hz
Default Channel Map: front-left,front-right
Default Sink: Channel_1__Channel_2.2
Default Source: Channel_1__Channel_2
Cookie: xxxx:xxxx

4. You can test that the audio is working either with speaker-test or just play your file with paplay file.

If the Pulse Audio Player is not working, you can also install another player, play the file and you will still be able to hear. I recommend trying SoX.

Originally published at HELLO, I AM CRISTIAN DUGUET.

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store