Streaming Audio from Windows to PulseAudio Server

2008-09-22 09:01

PulseAudio is a great network audio server for Linux. It allows me to stream audio between machines. However, the biggest problem with PulseAudio is that it doesn’t have a descent client implementation for Windows. There are a couple known workarounds such as using WinESD, but they are all pretty experimental. Also, the Win32 binary build didn’t work for me, perhaps because it’s somewhat outdated and buggy.

My first try was to use LineInCode and Netcat for Windows on the client side and to use module-simple-protocol-tcp on the server side. After adding -L "module-simple-protocol-tcp port=4712 rate=44100 format=s16le channels=2" option to the PulseAudio startup option, I was able to stream audio from Windows to PulseAudio server using the following command:

linco.exe -B 16 -C 2 -R 44100 | nc.exe <host> 4712

However, PulseAudio dies whenever the connection is closed because of a known issue of module-simple-protocol-tcp. I wrote some script that restarts PulseAudio whenever it dies, but I realized there’s a better solution – OpenSSH.

I have installed a Cygwin build of OpenSSH, and replaced Netcat with it:

linco.exe -B 16 -C 2 -R 44100 | ssh.exe <user@host> "cat - | pacat --playback"

This solution works without module-simple-protocol-tcp, and therefore there’s no need to restart the PulseAudio server on disconnection. Better security is another bonus. Instead, it requires a running SSH server. If SSHD is not running in the PulseAudio server, you can give it a little twist:

linco.exe -B 16 -C 2 -R 44100 | ssh.exe <user@otherhost> "cat - | pacat --server <host> --playback"

In case your Windows machine doesn’t have a sound card or it doesn’t allow you to capture the audio stream, you might want to use Virtual Audio Cable. It’s a commercial software, but it worths a purchase.

You might also want to set up a passwordless login so you don’t have to enter the password every time you stream the audio.

---
NOTE: Google Translate is poor at translating Korean. Do NOT guess from its result.

·

Comment

19 Comments

thank you so much %)

rstets · 2008-10-09 22:36 · # · Reply

@rstets: You’re welcome! :)

Trustin Lee · 2008-10-09 22:53 · # · Reply

Hmmm, how did you manage to send anything but microphone to PulseAudio server from Windows? Linco transfer only Audio Input on my machine :(

kotnik · 2009-02-24 01:49 · # · Reply

@kotnik: Virtual Audio Cable just worked for me. Perhaps linco might have an option which allows you to choose a device? I’m not sure anyway because I didn’t try that way. I’d recommend Virtual Audio Cable to save your effort. It doesn’t cost that much. Or.. perhaps there might be some open source alternative somewhere. Please let me know if you found one. :)

Trustin Lee · 2009-02-24 03:29 · # · Reply

Thanks…

I’ll try to find some solution that doesn’t involve proprietary software. If I stumble upon anything, I’ll let you know ;)

kotnik · 2009-02-25 17:43 · # · Reply

I solved this by changing the record source in the windows volume control (on XP) from Microphone to Stereo Mix. If you don’t have the stereo mix option, you might be able to add it in Options->Properties->Recording

monad · 2010-07-05 23:02 · # · Reply

How did you reduce the latency in your setup? I’m using Plink instead of ssh.exe, but other than that, I have the same setup as you.
However, I’m getting latencies of at least 1.5 seconds, which seems a bit ridiculous. Did you do anything to reduce it?

Walter Huf · 2009-03-26 08:29 · # · Reply

@Walter: Actually, I just live with it. I think it’s fine unless you are playing video. I use it only for playing music.

Trustin Lee · 2009-03-26 16:49 · # · Reply

Thanks for this post. I run Ubuntu 8.10 as my host operating system but do development work in Windows (C#) so I run VMware Workstation. Up until this point I was never able to get sound fully working inside a guest Windows operating system – I would always get obnoxious stuttering or the audio would speed-up/cut-out randomly. I’ve tried multiple sound cards and numerous settings tweaks to both PulseAudio & the individual virtual machines.

But now, with Virtual Audio Cable and your setup with LiveIncode & SSH, I’m able to route sound over to my host Ubuntu’s PulseAudio server and have it be pretty much flawless.

Thanks.

Mulchman · 2009-04-04 12:00 · # · Reply

@Mulchman: Great to hear that my tip was helpful. :)

Trustin Lee · 2009-04-04 15:18 · # · Reply

Hi,
I’m trying to mimic your initial setup of having pulseaudio stream to netcat, but when I try to run mplayer or any other program on the server, it returns:
AO: [pulse] Failed to connect to server: Internal error
Could not open/initialize audio device -> no sound.

My server doesn’t have speakers or a sound card, so my default.pa config file is empty except for the module-simple-protocol-tcp module.

Do you have anything additional in your default.pa file beyond that module?

Thanks!

Rohan Relan · 2010-05-05 16:33 · # · Reply

Thanks for this brilliant guide! It helped me work around a broken headphone jack.

monad · 2010-07-05 23:05 · # · Reply

Pulseaudio does NOT exit if you start it with
—exit-idle-time=-1
This is no bug. Its a feature…

sam · 2011-01-09 00:01 · # · Reply

Thanks for excellent guide! All works!

But i have a one little problem – a latency in 0,5 second. Is there any way to reduce it?

NecromS · 2011-03-05 00:12 · # · Reply

AFAIK, no. The situation could get better if someone ports PulseAudio server to Windows.

Trustin Lee · 2011-03-05 02:28 · # · Reply

LineInCode has an excessively large buffer for this job, and Windows likes to use big buffers for TCP. I had much better latency with sox —buffer=1024 and nc -u.

notes on windows network audio

Joe Rayhawk · 2011-07-28 11:09 · # · Reply

I did what follows to “almost” remove latency:
Windows 7 machine – install virtual audio cable – install cygwin with soc, nc etc. – “sox —buffer=1024 -t waveaudio 0 -t raw -r 48k -e signed -b 16 -c 2 – | nc -u 10.0.10.10 4713”

On linux (receiver and using jackd): – setup jackd to real-time – “nc -n -k -l -u -vvv -p 4713 | aplay -r 48001 -f S16_LE —buffer-size=2048 -c 2”

The -k parameter “almost” work. You can restart the server while client still is running. Notice the -r 48001… This is still a experiment. I had trouble over time where the latency continuously build up if my server did a lack e.g. when going to screensaver. I expect this to be a aplay buffer building up and therefore I raised the rate.

Jacob Kusk · 2013-01-29 04:19 · # · Reply

Naaah. The -r 48001 was not an succes…

Jacob Kusk · 2013-01-29 16:41 · # · Reply

Hi,

Thanks for your tutorial :)

I’m looking to use the same thing on Android. To stream sound from Android device to my sound system through this. Any idea ?

Bye
G

Guillaume · 2013-03-23 21:44 · # · Reply

 
  • Preview 버튼 누르고 reCAPTCHA 입력 후 Submit 버튼까지 눌러야 실제로 게시됩니다.
  • Make sure to answer the reCAPTCHA and click the Submit button to get your comment posted. It's not enough to click the Preview button only! -- See why.

·

---