Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for help for audio output. #2658

Closed
ultrasound1372 opened this issue Nov 12, 2017 · 44 comments
Closed

Request for help for audio output. #2658

ultrasound1372 opened this issue Nov 12, 2017 · 44 comments
Labels

Comments

@ultrasound1372
Copy link

this is a sort of support question but I don't know where else to post. Direct me if needed
Hello there.
So, I'm playing with wsl. I am a blind computer user, and so my interest in wsl is mainly the speech systems offered in it. ESpeak, festival etc. I am trying to figure out how I would go about bringing audio from the system, either using pulse audio or alsa. I do not currently have alsa, so PA is prefered.
Previous research and tests have lead me to realize that wsl currently does not implement audio of any kind, since linux doesn't have a specific implementation for audio. It's left up to the user, but the underlying framework needed for audio devices doesn't exist. I saw that I should be sending audio from pulse on linux to a pulse server on windows. Have tried this, it doesn't seem to work.
I have the pulse server on windows running, listening for incoming audio with no authentication. I then go over to linux and execute paplay to play a file. It says connection refused. This is reasonable, so I try explicitly specifying connection options instead.
paplay -s 127.0.0.1 -n linux audio.wav
This doesn't produce any errors, but no audio is heard. It sits there for a bit and then returns back to my shell. I can only assume this is an issue with finding the server or something.
If someone could guide me or give me a solid direction to follow to get audio from linux to windows I would appreciate it. I sort of assume it also has something to do with the way the networking is managed, maybe 127.0.0.1 isn't the address for the windows server? If this is the case, correct me.
P.S. Audio should just work! It works in a vm...

@onomatopellan
Copy link

Pulseaudio 8 works great on Fall Creators Update. You need the patched libpulse0 in order to make it work (from #486 thanks to @therealkenc). I just tested it yesterday and mplayer works with these steps:

sudo apt update && sudo apt upgrade

sudo apt install pulseaudio

wget https://launchpad.net/~therealkenc/+archive/ubuntu/wsl-pulseaudio/+build/13050551/+files/libpulse0_8.0-0ubuntu3.3ppa1_amd64.deb

sudo dpkg -i libpulse0_8.0-0ubuntu3.3ppa1_amd64.deb

export PULSE_SERVER=tcp:localhost

mplayer test.flac

@therealkenc
Copy link
Collaborator

Hi @ultrasound1372. Yours is the "except one" use case I was alluding to in #1006 (message), and curiously overlooked in the August 09, 2016 WP Dev response "but what developer scenario" over in the User Voice ticket. Surprised it took this long to come up, and it seemed like cheating to do it myself. Now that it has, I would not be surprised if priority for the feature improves markedly (if I know my big companies right).

The details are in #486, but it sounds like you've found and followed the info over there about right. Per onomatopellan above it does work; though I haven't run it personally in ages despite being therealkenc in that PPA. There isn't much concrete I can offer as to why it is not working for you. Try Ono's steps above and if it still doesn't work it will boil down to debugging why you are getting connection refused errors. Which is more of a "networking thing" rather than an "audio thing". First step would be to use netstat on the Windows side and see if there is in fact anything listening on port 4713, and we can take it from there.

@therealkenc
Copy link
Collaborator

Ono's link works here (note it is split on two lines), but I just made a tiny url which might be easier.

wget https://goo.gl/fPK6Tq -O pulse.deb

@ultrasound1372
Copy link
Author

ultrasound1372 commented Nov 13, 2017

Begin edit:
Yes, his link did work. There was just an extra space and wget picked that up. Installed the deb.
End edit.

I ran netstat, it never seems to complete, just loops, and because I cannot see I cannot check for that. Tried redirecting to a text file, became 4KB before I terminated it, ctrl f, 4713, nothing found. So I guess it isn't listening. Executing paplay on the windows side returns connection refused... Maybe it has something to do with this line at the very bottom of the pulseaudio output?
E: [(null)] daemon/main.c: Failed to load directory

@therealkenc
Copy link
Collaborator

E: [(null)] daemon/main.c: Failed to load directory

That error is on the Windows (ie server) side? Yeah that sounds like a problem. The netstat command you are looking for, FWIW, is:

netstat -n | find "4713"

Which is almost certainly going to come up empty.

@ultrasound1372
Copy link
Author

ultrasound1372 commented Nov 13, 2017

errp... Looked up that error and immediately got to wsl and pulseaudio bridging, fall creator's update has broken it completely they say and no fix has been provided for that error. Although he wqas getting all kinds of errors with waveout so... Let me try their workaround.
edit: didn't work, still that error. Also let it be known that if I add "--start" it flashes output in the terminal, says this program requested to terminate the runtime in an unusual way, and then a werfault dialog about pulseaudio.exe has stopped working pops up. Oops!
Current launch code is in a batch file and is as follows
pulseaudio.exe -p "C:\Users\Colton\Documents\utilities\pulseaudio\lib\pulse\modules" -nF "C:\Users\Colton\Documents\utilities\pulseaudio\etc\pulse\default.pa"
and the tcp listen thing being loaded inside default.pa
load-module module-native-protocol-tcp listen=0.0.0.0 auth-anonymous=1

@onomatopellan
Copy link

onomatopellan commented Nov 13, 2017

E: [(null)] daemon/main.c: Failed to load directory.

That is normal, I also see that line on Windows and it works.

On the Windows side, in default.pa I modified these lines

load-module module-waveout sink_name=output source_name=input record=0
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1

also added this to daemon.conf
exit-idle-time = -1

With this you only need to double click on the pulseaudio.exe in the bin folder and it will wait for connections.

@ultrasound1372
Copy link
Author

okay this just really doesn't wanna work. I changed my config. It runs. Sits there, awaiting stuff. Paplay still says connection refused on windows side.
netstat -n | find "4713"
returns a blank line... Guess it's still not listening!

@therealkenc
Copy link
Collaborator

Yes, nothing is listening if that command returns blank.

It is possible you are running into something like #1561, #1350 or #416. I hope not, because that is a bear under the best of circumstances. I understand entirely that you want audio, not to go down a networking debug rabbit hole. But I'd be remiss if I didn't point it out as a possibility. Or, as likely, it could be a just a silly step missing, which I can't guess at the moment. Anyway, happy to see you trying, and don't want you discouraged. The most constructive thing you can do at this time is find a local computer club and get hands on help. Or I am happy to pursue the problem to the gates of hell here in this list; though I am not sure I'd wish that on anyone, or whether you'd find the result satisfactory. Patience (I prefer the term laziness) is another viable option. Audio devices aren't supported by WSL right now (that's just a hard fact), but I hope your post will help change that. It sounds like you have Linux up in a VM, and for all practical purposes that's the route I'd go if it were me.

Going to ping @sunilmut at random just to make sure the guys are aware of your use case.

@onomatopellan
Copy link

onomatopellan commented Nov 14, 2017

Don't worry about netstat because output is empty for me too. Ok let's start again from the beginning.
Reboot your PC because there could be a pulseaudio.exe hanged or something.

For the Windows side download and extract Pulseaudio 6 from here https://github.com/kitor/wsl/raw/master/pulse6.zip
Since is preconfigured (and sound hardcoded to two speakers and disabled input devices) you only need to double click pulseaudio.exe and let that window open.

For the WSL side forget about paplay and use mplayer instead.
sudo apt install mplayer (you will problably need first to sudo apt-get -f install )
mplayer testfile.flac
What the output says?

@therealkenc
Copy link
Collaborator

Output says connection refused. What port is it listening on? I just googled and 4713 popped up; I didn't actually try. I guess I should get the thing up again so I can play along for reals.

@onomatopellan
Copy link

onomatopellan commented Nov 14, 2017

Ok when I double click pulseaudio.exe for fist time Windows Firewall asked me for permission. Maybe that's the problem here.
Running netstat from admin cmd while playing testfile.flac it shows 127.0.0.1:4713

@therealkenc
Copy link
Collaborator

Command is netstat -a -n | find "4713". I forgot the -a to get the listening ports. My bad there. You shouldn't have to be admin.

@onomatopellan
Copy link

On WSL is empty.
On cmd it shows

  TCP    0.0.0.0:4713           0.0.0.0:0              LISTENING
  TCP    127.0.0.1:4713         127.0.0.1:60796        ESTABLISHED
  TCP    127.0.0.1:60796        127.0.0.1:4713         ESTABLISHED
  TCP    [::]:4713              [::]:0                 LISTENING

@therealkenc
Copy link
Collaborator

netstat doesn't work on WSL, which is why it's empty there.

@ultrasound1372 that first TCP 0.0.0.0:4713 0.0.0.0:0 LISTENING line is what you are looking for. But even if it is listening it could be blocked by the firewall, possibly, like Ono hypothesises.

@ultrasound1372
Copy link
Author

I'm using paplay for a reason. Because I don't wanna use wsl as a media player. I wanna use it to pipe output from synths and minimodem.

@ultrasound1372
Copy link
Author

ultrasound1372 commented Nov 15, 2017

okay, so it's listening now. I'm using paplay on the windows side to test. Allowed it strictly through firewall, it didn't ask me at first so I forced it. Netstat found it. Now, paplay on the windows side, executed as follows
paplay C:\Windows\media\ding.wav
produces
Connection failure: Connection refused
pa_context_connect() failed: Connection refused
Roar! Do I have to specify some extra arguments? Surely I don't have to allow paplay through the firewall...

@onomatopellan
Copy link

onomatopellan commented Nov 15, 2017

If you think you already have pulseaudio.exe listening on windows then test paplay like this:
on windows side paplay -s 127.0.0.1 C:\Windows\media\ding.wav
on WSL side paplay /mnt/c/Windows/media/ding.wav

@ultrasound1372
Copy link
Author

woot woot! Windows paplay finally works. Now how would I configure wsl to always use that gateway? Does it require me to explicitly specify things or will it connect to localhost and find my thing?

@onomatopellan
Copy link

onomatopellan commented Nov 15, 2017

On WSL edit or create /etc/pulse/client.conf
and add this line
default-server = 127.0.0.1

and then test paplay on WSL with paplay /mnt/c/Windows/media/ding.wav

@therealkenc
Copy link
Collaborator

Or just:

export PULSE_SERVER=tcp:localhost

@ultrasound1372
Copy link
Author

ultrasound1372 commented Nov 15, 2017

alright! It works! For a bit it didn't, then I checked and the windows demon was doing the 20 second timeout. Set that to -1 and hopefully it'll stay. So, since I've configured pulse itself to do this, any application that uses pulse will now automatically stream to the windows side?

@onomatopellan
Copy link

onomatopellan commented Nov 15, 2017

Yes, the exit-idle-time = -1 makes it always listening.
paplay is too simple and works. That's why you need to test with something like mplayer. If it outputs sound then you shouldn't have problem with others programs.

@ultrasound1372
Copy link
Author

minimodem works, so I guess everything else should too. i'm off to install synth toolkits. Thanks for your help.
P.S. Another thing that doesn't work is beep. Windows has a pc speaker, that should work too. Without audio, shell scripts have no feedback form other than beep.

@ultrasound1372
Copy link
Author

Well, it did... Until I install anything that needs pulse. Then it throws something about a mutex?

@onomatopellan
Copy link

onomatopellan commented Nov 15, 2017

That's the #486 bug. Every time you see that you need to install the patched pulse0 with
sudo dpkg -i libpulse0_8.0-0ubuntu3.3ppa1_amd64.deb

@ultrasound1372
Copy link
Author

ultrasound1372 commented Nov 15, 2017

Ehh. That sounds like a massive throwback for developers, possibly beyond pulse audio. I have no flipping idea what a mutex is. But anyways, I kept the download in /temp and created a shell script on root called fixpulse.sh so when I install something, and it breaks, I can unbreak it. Hopefully espeak will install without doing this again, when I tried that it said unmet dependencies, apt -f install upgraded the deb.
edit: nope, it won't work. I cannot install espeak with this patched deb, because it does a version check. Okay, how about festival?
edit2: Not that either! Is there any way I can fake the version number of the patched deb?

@onomatopellan
Copy link

onomatopellan commented Nov 15, 2017

Yep, it's a PITA. I think @benhillis said support for syscalls like FUTEX_CMP_REQUEUE_PI_PRIVATE it's on the backlog though.

@ultrasound1372
Copy link
Author

in the meantime, can I either fake the version number of this patch or install the pulse version that used it? Because I cannot use apt anything unless it matches what it wants.

@onomatopellan
Copy link

onomatopellan commented Nov 15, 2017

You can hold a package with
sudo apt-mark hold libpulse0

But I don't know too much about packet managers so maybe that will get more problems in the future.

@ultrasound1372
Copy link
Author

doesn't work, still haults the process and says this.
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
libpulsedsp : Depends: libpulse0 (= 1:8.0-0ubuntu3.4) but 1:8.0-0ubuntu3.3
ppa1 is to be installed
pulseaudio : Depends: libpulse0 (= 1:8.0-0ubuntu3.4) but 1:8.0-0ubuntu3.3p
pa1 is to be installed
pulseaudio-module-x11 : Depends: libpulse0 (= 1:8.0-0ubuntu3.4) but 1:8.0-
0ubuntu3.3ppa1 is to be installed
pulseaudio-utils : Depends: libpulse0 (= 1:8.0-0ubuntu3.4) but 1:8.0-0ubun
tu3.3ppa1 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specif
y a solution)

@onomatopellan
Copy link

onomatopellan commented Nov 15, 2017

Nah, forget it. It uninstalled all the dependencies. You can unhold it with sudo apt-mark unhold libpulse0

@ultrasound1372
Copy link
Author

nope, then it continues to error and yelling about that I held broken packages. I just need to fake the version number. How can I do that. When I try apt -f install after holding just libpulse0, it removes all of pulse!

@onomatopellan
Copy link

yes that happened too. I'm now trying updating the entire pulseaudio with the patched version.

@ultrasound1372
Copy link
Author

ultrasound1372 commented Nov 15, 2017

this is way too fucking complicated just to get audio and apps to use it! And beep will never work...
cannot access /dev/tty0 or /dev/vc/0. No such file or directory.
edit: if you are truely rebuilding all of pulse just to work with this patched version, you should get it uploaded somewhere where apt can access it, identifying it as pulseaudio-wsl or something.

@onomatopellan
Copy link

onomatopellan commented Nov 15, 2017

WSL is right now just for commandline development scenarios and clearly not ready for audio support.
For now I recommend you to install everything you need and patch libpulse0 as latest step.

About the beep sound see #1355

@onomatopellan
Copy link

onomatopellan commented Nov 16, 2017

Ok I found a way to patch libpulse0 without screwing the package dependencies. You only need to replace libpulsecommon shared library.

First make sure you have latest libpulse0 with sudo apt -f install
Then extract the .so file from the patched deb and replace the original

sudo dpkg -x libpulse0_8.0-0ubuntu3.3ppa1_amd64.deb .
sudo cp ./usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-8.0.so /usr/lib/x86_64-linux-gnu/pulseaudio/

That's it. You only need to do this once and it should work at least until Ubuntu updates pulseaudio again.

@therealkenc
Copy link
Collaborator

Thanks Ono. I was going to suggest that but wanted to let your help play out. Good suggestion. At base the problem here is Canonical updated from 3.3 to 3.4 and the PPA needs updating. "Effort"

@therealkenc
Copy link
Collaborator

I've put up a new PPA for PulseAudio 8. Here's the libpulse0_8.0-0ubuntu3.4ppa1_amd64.deb that matters. Or do the usual:

sudo add-apt-repository ppa:therealkenc/wsl-pulseaudio
sudo apt-get update && sudo apt-get upgrade

@adikhanna
Copy link

adikhanna commented Jul 18, 2018

Hi,

I got this to work with great thanks to everyone in this thread.

I am now able to use paplay while being ssh-d into a remote machine (CentOS 7) and hear sounds on my local machine (Windows 7). However, I wanted to use padsp and that does not seem to work. I am running my application like so while being ssh-d to my remote machine:

/usr/bin/padsp-32 application_name

And I don't hear any sounds on my local machine. Could this be because the pulseaudio for Windows does not have padsp? I know that padsp forwards sound to the PulseServer which I know to be working fine because of paplay. But, does it attempt to use something like a "padsp.exe" on the local machine and doesn't find it? Or do I need to do something else? Like load a particular module into my pulse audio on the Windows side?

@mailinglists35
Copy link

@therealkenc could you update the ppa for bionic? it's impossible to install on bionic :(

@therealkenc
Copy link
Collaborator

The PPA is obsolete as of Windows 1809 aka build 17763 aka October 2018 Update (and Insider 17627 since March). Ref #486 (message).

@ultrasound1372
Copy link
Author

Ah so they fixed the mutex error that was preventing it from running? Cool, I can close this now I guess.

@mcandre
Copy link

mcandre commented Aug 14, 2020

@msftgits

$ sudo add-apt-repository ppa:therealkenc/wsl-pulseaudio; echo "$?"
 A one-liner change to  src/pulsecore/mutex-posix.c adding #undef HAVE_PTHREAD_PRIO_INHERIT to work around missing futex() surface in WSL.
 More info: https://launchpad.net/~therealkenc/+archive/ubuntu/wsl-pulseaudio
Press [ENTER] to continue or Ctrl-c to cancel adding it.

Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:3 http://ppa.launchpad.net/openjdk-r/ppa/ubuntu focal InRelease
Hit:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Ign:6 http://ppa.launchpad.net/therealkenc/wsl-pulseaudio/ubuntu focal InRelease
Err:7 http://ppa.launchpad.net/therealkenc/wsl-pulseaudio/ubuntu focal Release
  404  Not Found [IP: 2001:67c:1560:8008::15 80]
Reading package lists... Done
E: The repository 'http://ppa.launchpad.net/therealkenc/wsl-pulseaudio/ubuntu focal Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants