How to stream my GNU/Linux audio output to Android devices over WI-FI?

72,755

Solution 1

There is a very simple solution because PulseAudio already has all the necessary tools.

  1. Get your source device name with command pactl list | grep Name
  2. Create the following script named pashare:

    #!/bin/sh
    case "$1" in
      start)
        $0 stop 
        pactl load-module module-simple-protocol-tcp rate=48000 format=s16le channels=2 source=<source_name_here> record=true port=8000
        ;;
      stop)
        pactl unload-module `pactl list | grep tcp -B1 | grep M | sed 's/[^0-9]//g'`
        ;;
      *)
        echo "Usage: $0 start|stop" >&2
        ;;
    esac
    
  3. Make some checks and preparations (to allow script execution and check if the port successfully opened):

    chmod 755 pashare
    ./pashare start
    netstat -nlt | grep 8000 
    telnet 127.0.0.1 8000
    
  4. Download and install PulseDroid.apk

  5. Launch app on your phone; set the IP address to your computer and the port to 8000.

P.S. You can also check this Wiki page for general information on Pulseaudio network streaming, and this Wiki page about RTP streaming. Don't expect too much from streaming raw audio over WiFi; it takes enormous gobs of bandwidth. Even with a high-end wireless router/AP with a powerful signal I haven't been able to get more than stuttering audio out of it. Your best bet is probably to setup a proper media server (like Rygel, which works well with Pulseaudio) to transcode the raw audio to something like MP3 and stream that instead.

Solution 2

You can use VLC to serve a MP3 stream of pulseaudio's output via HTTP.
The main advantage is that you don't need to install any special software on your remote device, a web browser (or music player) is all you need to play the stream. The downside is that it's audio only, a few seconds lag make it useless for videos

  1. Find pulseaudio's output name with:

    pactl list | grep "Monitor Source" 
    
  2. Start the VLC http server, replacing XXXX by your output name:

    cvlc -vvv pulse://XXXX --sout '#transcode{acodec=mp3,ab=128,channels=2}:standard{access=http,dst=0.0.0.0:8888/pc.mp3}'
    
  3. If needed, find your local IP address with ifconfig

  4. On your remote device, point the browser (or audio streaming app) to:

    http://your.local.ip.address:8888/pc.mp3
    

Note: The stream isn't affected by the volume set on the server, unless you totally mute it. If needed, you can keep the level just a tiny bit above 0 to only hear the remote device.


The first two steps combined into one by polynomial_donut:

cvlc -vvv pulse://$(pactl list | grep "Monitor Source" | awk '{print $3}') --sout '#transcode{acodec=mp3,ab=128,channels=2}:standard{access=http,dst=0.0.0.0:8888/pc.mp3}'

Solution 3

To stream audio output over wifi to your android phone you need to install server software, that sends audio, on PC and client software on Android device. Available options are

WiFi Audio Wireless Speaker

Run WiFi Audio Android App and Press start, you will see IP address of mobile device in the bottom after that run Windows/Linux application and put mobile device's IP address in the IP address field and then press start on PC application. Now all audio coming out from PC will be send to mobile device and you will hear audio on mobile device.
Download

SoundWire

Wirelessly transmit any music or audio from your PC to your Android phone, tablet, or other PCs
Home page Also see

Other useful links
XBMC android SE

Solution 4

I've published a native PulseAudio server for Android (also includes X11 server):

https://play.google.com/store/apps/details?id=x.org.server

To use it, set environment variable PULSE_SERVER for your Linux application that you want to redirect the audio from:

export PULSE_SERVER=tcp:10.0.0.100:4713
vlc

where 10.0.0.100 is the IP address of your Android device.

The downside is that you will need to launch each application from the terminal, the upside is that it should be less laggy than module-simple-protocol-tcp. You can put PULSE_SERVER to /etc/profile to set it as a system-wide env variable, then you won't need to use terminal, but you'll need to edit it and reboot your PC each time your Android device gets different IP address.

Share:
72,755

Related videos on Youtube

semente
Author by

semente

Updated on September 18, 2022

Comments

  • semente
    semente over 1 year

    I want to stream my audio output over the network (Wi-Fi) to my Android devices. I'm not looking for a music/video streaming solution, but I would stream any audio output of my GNU/Linux desktop to my Android work like a bluetooth headphone.

    My GNU/Linux desktop is Debian Wheezy and the sound is provided by pulseaudio.

    I've tried Pulseaudio's raop module (and enabled it on paprefs) + Android's AirBuddle app, but the audio is not streamed (pulseaudio seens connect to AirBuddle, but the sound is not reproduced, there is a connection failure in some softwares, in some other softwares the sound is stucked).

  • Jannes
    Jannes about 9 years
    This also works perfectly with this Android App: Simple Protocol Player play.google.com/store/apps/… Note that this defaults to rate=44100 however, so you might want to use that.
  • Gaurav Gupta
    Gaurav Gupta almost 8 years
    SoundWire lags by 1-2 sec
  • Jonathan Aurry
    Jonathan Aurry over 7 years
    @gauravgupta No lags if you choice smaller buffer size. Also try to use compression. This worked for me very well.
  • seyed
    seyed over 7 years
    can you put PC application download link of WiFi Audio here?
  • wolfmanx
    wolfmanx over 6 years
    Just to clarify: the output of pactl list sources short is better to find the number of the source parameter.
  • Saren Tasciyan
    Saren Tasciyan over 6 years
    WiFi Audio Wireless Speaker was removed from github and the compiled version in the forums is reported by the users to be a malware. Be careful! Soundwire also looks fishy, from the way it is distributed.
  • markroxor
    markroxor about 6 years
    using pactl list | grep "Monitor Source" shows more relevant sources for me.
  • naim5am
    naim5am almost 6 years
    awesome! There's a 3 second lag but I'm happy with this little hack till I find that damn cable. I'll probably have to buy another one...
  • wilks
    wilks almost 6 years
    @Slabo good point, for some reason i'd wrongly assumed the OP only wanted to stream music. Edited my answer
  • polynomial_donut
    polynomial_donut over 5 years
    A one-liner instead of the first two lines: cvlc -vvv pulse://$(pactl list | grep "Monitor Source" | awk '{print $3}') --sout '#transcode{acodec=mp3,ab=128,channels=2}:standard{access=ht‌​tp,dst=0.0.0.0:8888/‌​pc.mp3}'
  • Rolf
    Rolf about 5 years
    The stream IS directly affected by the volume setting for me. I just plug in my earphones to stop the sound from coming from the laptop.
  • Rolf
    Rolf about 5 years
    By the way, how do I stop the lag from lasting like 1/2 hour?
  • Кристиян Кацаров
    Кристиян Кацаров almost 4 years
    Yeah, big lag, how can we improve it?
  • wilks
    wilks almost 4 years
    @КристиянКацаров This solution is a lot more like streaming an internet radio than connecting a bluetooth device. The lag comes from these steps: encoding the mp3 stream on the server, serving it over http, the quality of the connection (both server and client) and decoding the stream on the client. Any more than 3 or 4 seconds lag means that one of this steps is taking longer than it should. I don't know how you would go about making it less, maybe with a different codec and stream quality?
  • Sebastián Grignoli
    Sebastián Grignoli over 3 years
    For me the best way to find the device name was: pactl list sources short that returned 0 alsa_output.pci-0000_00_1f.3.analog-stereo.monitor module-alsa-card.c s16le 2ch 48000Hz SUSPENDED And the name I was needing was the one starting with alsa_output.pci-00...
  • Arch Stanton
    Arch Stanton over 3 years
    hostname -I is one command to get the IP address of the computer, in case someone needs it.
  • RJVB
    RJVB about 3 years
    In your script, why don't you just do pactl unload-module module-simple-protocol-tcp to stop the sharing?
  • Alexander Kellett
    Alexander Kellett about 2 years
    Thank you. This solution just works.