On Linux how to share Bluetooth sound output via SSH?
Feb 25, 2:46pm

Sharing Bluetooth audio output over SSH on Linux is not straightforward because SSH is primarily designed for terminal access and does not natively support audio streaming. However, you can achieve this by combining several tools and techniques. Here’s a step-by-step approach:


1. Forward Audio Over SSH Using PulseAudio

PulseAudio is the most common sound server on Linux and can be configured to stream audio over a network.

On the Remote Machine (where Bluetooth audio is playing):

  • Ensure PulseAudio is installed:
    bash
    sudo apt install pulseaudio pulseaudio-utils
  • Edit the PulseAudio config to allow network access:
    bash
    sudo nano /etc/pulse/default.pa
    Add these lines:
    load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;YOUR_LOCAL_IP load-module module-zeroconf-publish
  • Restart PulseAudio:
    bash
    pulseaudio -k && pulseaudio --start

On the Local Machine (where you want to hear the audio):

  • Forward the PulseAudio port over SSH:
    bash
    ssh -R 4713:localhost:4713 user@remote-machine
  • Set up PulseAudio to use the remote server:
    bash
    export PULSE_SERVER=tcp:localhost:4713
  • Play audio on the remote machine, and it should stream to your local machine.

2. Use parec and paplay for Direct Streaming

If you want to stream audio directly from the Bluetooth device:

  • On the remote machine, capture audio from the Bluetooth device:
    bash
    parec --device=BLUETOOTH_DEVICE_NAME --format=s16le --rate=44100 --channels=2 | ssh user@local-machine "paplay --format=s16le --rate=44100 --channels=2"
    Replace BLUETOOTH_DEVICE_NAME with the actual name of your Bluetooth audio device.

3. Alternative: Use ffmpeg and ssh

If PulseAudio is not an option, you can use ffmpeg to capture and stream audio:

  • On the remote machine:
    bash
    ffmpeg -f pulse -i BLUETOOTH_DEVICE_NAME -acodec libmp3lame -f rtp rtp://local-machine-ip:1234
  • On the local machine, receive the stream:
    bash
    ffplay -f rtp rtp://localhost:1234

4. Use a Virtual Audio Cable (Advanced)

If you need more control, set up a virtual audio cable (e.g., snd-aloop) on the remote machine and route Bluetooth audio through it, then stream the virtual device over SSH.


Notes:

  • Latency: Audio streaming over SSH will introduce latency, so this is not ideal for real-time applications like gaming or video calls.
  • Bluetooth Device: Ensure the Bluetooth device is properly connected and recognized by PulseAudio on the remote machine.
  • Firewall: Ensure the necessary ports (e.g., 4713 for PulseAudio) are open on both machines.

Feb 25, 2:46pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.