59

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).

6 Answers 6

44

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.

6
  • 15
    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.
    – Jannes
    Apr 20, 2015 at 0:42
  • 1
    Just to clarify: the output of pactl list sources short is better to find the number of the source parameter.
    – wolfmanx
    Nov 12, 2017 at 21:38
  • 8
    using pactl list | grep "Monitor Source" shows more relevant sources for me.
    – markroxor
    Apr 10, 2018 at 7:39
  • 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... Oct 2, 2020 at 15:37
  • 2
    hostname -I is one command to get the IP address of the computer, in case someone needs it. Feb 10, 2021 at 14:58
29

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}'
7
  • 2
    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...
    – naim5am
    Aug 5, 2018 at 18:43
  • @Slabo good point, for some reason i'd wrongly assumed the OP only wanted to stream music. Edited my answer
    – pevinkinel
    Aug 12, 2018 at 7:50
  • 3
    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=http,dst=0.0.0.0:8888/pc.mp3}' Nov 4, 2018 at 17:10
  • 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
    Mar 7, 2019 at 22:37
  • 2
    @КристиянКацаров 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?
    – pevinkinel
    Jun 12, 2020 at 21:10
10
+50

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

4
  • SoundWire lags by 1-2 sec Jul 6, 2016 at 19:29
  • @gauravgupta No lags if you choice smaller buffer size. Also try to use compression. This worked for me very well.
    – raacer
    Sep 18, 2016 at 12:22
  • can you put PC application download link of WiFi Audio here?
    – seyed
    Jan 10, 2017 at 19:01
  • 5
    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. Nov 25, 2017 at 0:15
2

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.

1
0

For those of you using Soundwire and sending out wifi from your laptop or PCs, using ifconfig MAKE SURE YOU USE THE CORRECT IP ADDRESS. This still works to this day but most Linux distros need a second wifi adapter to send out the wifi and you have to use the one that your Android is connected TO. not the one recieving internet. The one sending it OUT.

i.e. -> If you are using "A" wifi adapter to connect to the internet and "B" to send out wifi from "A", then connect SoundWire on Android to "B" NOT "A".

SoundWire will NOT connect or stream if you connect to the adapter not sending out the wifi so input your IP address into your Andoroid app(s) accordingly, using the terminal command ifconfig accordingly.

Yes there is lag but this app, SoundWire, is the most simple "multi-connect to ip and forget" system out there. No crazy menus to go through. And yes, it does accept more than one connect. I used 2 the other day. It appends the number of devices connected to it in the main window on the device sending out the transmission.

Using this personally as a multi-room/short distance wifi-radio system at my place to this day.

Enjoy.

-4

Wow this is old...

Anyway, use VLC. Pretty GUIs all the way.

  • Fire up VLC on your desktop.
  • Hit Stream, select the file (add how ever many files you want), hit stream.
  • 'Next' if it's all correct.
  • For New Destination select "http" (or whatever you want to use). Select Display locally if you want to play it on the machine you're streaming from too. The next few dialogues are all self-explanatory.

Fire up VLC on your Android device. Hit the icon next to the search button (the arrow pointing to the dot). type in http://<IP ADDRESS O OF THE MACHINE RUNNING VLC>:8080/ for me this was http://xxx.ca:8080/

Tested and working. Now, could one do this in the ancient time of Jun 9'13? Maybe, but I'm too lazy to check VLC's commmit logs ;)

1
  • 5
    He's not looking for a music/video streaming solution. Apr 24, 2014 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .