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

39

31

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

semente

Posted 2013-06-09T01:20:35.490

Reputation: 390

Answers

27

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.

AlexAndersan

Posted 2013-06-09T01:20:35.490

Reputation: 491

7

This also works perfectly with this Android App: Simple Protocol Player https://play.google.com/store/apps/details?id=com.kaytat.simpleprotocolplayer Note that this defaults to rate=44100 however, so you might want to use that.

– Jannes – 2015-04-20T00:42:20.303

1Just to clarify: the output of pactl list sources short is better to find the number of the source parameter. – wolfmanx – 2017-11-12T21:38:00.390

4using pactl list | grep "Monitor Source" shows more relevant sources for me. – markroxor – 2018-04-10T07:39:54.573

18

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}'

wilks

Posted 2013-06-09T01:20:35.490

Reputation: 301

1awesome! 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... – Slabo – 2018-08-05T18:43:29.917

@Slabo good point, for some reason i'd wrongly assumed the OP only wanted to stream music. Edited my answer – wilks – 2018-08-12T07:50:16.120

2A 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}' – polynomial_donut – 2018-11-04T17:10:04.297

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 – 2019-03-07T22:37:37.020

By the way, how do I stop the lag from lasting like 1/2 hour? – Rolf – 2019-03-07T22:46:52.827

9

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

totti

Posted 2013-06-09T01:20:35.490

Reputation: 832

SoundWire lags by 1-2 sec – Gaurav Gupta – 2016-07-06T19:29:22.137

@gauravgupta No lags if you choice smaller buffer size. Also try to use compression. This worked for me very well. – raacer – 2016-09-18T12:22:13.333

can you put PC application download link of WiFi Audio here? – seyed – 2017-01-10T19:01:48.477

1WiFi 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. – Genom – 2017-11-25T00:15:23.103

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.

Roiikka

Posted 2013-06-09T01:20:35.490

Reputation: 11

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

Zeroedout

Posted 2013-06-09T01:20:35.490

Reputation: 56

3He's not looking for a music/video streaming solution. – Cristian Ciupitu – 2014-04-24T18:43:58.087