microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.31k stars 814 forks source link

Wsl2 sound support #5816

Closed w5wa closed 3 years ago

w5wa commented 4 years ago

Is your feature request related to a problem? Please describe. The Pulseaudio doesn't natively supported by WSL2 and it difficult to link it to Windows speakers.

Describe the solution you'd like Add driver support of sound as update

Describe alternatives you've considered Codes for Pulseaudio to link Windows speaker or export sound of linux to local host ip address.

Biswa96 commented 4 years ago

This article may help https://x410.dev/cookbook/wsl/enabling-sound-in-wsl-ubuntu-let-it-sing/

therealkenc commented 4 years ago

Spiritually dupe #237 which is the three-digit landing zone for sound, with ref #486 and #4205. WSL2 can have its own LZ for reasons.

ameeno commented 4 years ago

I found a way that is better than the x410 guide and works with the latest version of pulse on windows 10. installs pulse as a service, and is seamless.

this is the guide.

originally available from https://tomjepp.uk/2015/05/31/streaming-audio-from-linux-to-windows.html but now down:

I found a much newer set of binaries from the X2Go project: http://code.x2go.org/releases/binary-win32/3rd-party/pulse/.

To set up PulseAudio 5.0 on Windows, do the following:

Download pulseaudio-5.0-rev18.zip from http://code.x2go.org/releases/binary-win32/3rd-party/pulse/pulseaudio-5.0-rev18.zip Extract it and copy the pulse folder to C:\pulse Create a config.pa file in that folder with these contents:

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

Test this setup by running: c:\pulse\pulseaudio.exe -F config.pa On the wsl2 side you must run:

export PULSE_SERVER=tcp:$(grep nameserver /etc/resolv.conf | awk '{print $2}');

play some sound on wsl2 and you will get it working. You should now be able to get Linux sound playing on your Windows PC. For a permanent setup, we need to create a Windows service rather than running PulseAudio in a command prompt. I use NSSM to run arbitrary programs as services. Download the latest version of NSSM.

https://nssm.cc/download

Extract it and copy nssm.exe from the win32 folder to c:\pulse. Run:

 c:\pulse\nssm.exe install PulseAudio

Fill in the following details on the Application tab: Path: c:\pulse\pulseaudio.exe Start-up directory: c:\pulse Arguments: -F c:\pulse\config.pa On the Details tab, fill in:

Display name: PulseAudio Now click Install service.

Finally, start the newly installed service - either through Services in Administrative Tools, or by running net start PulseAudio

now you will have a permanent pulseaudio service on windows which is very low ram usage. for permanent settings on the WSL side, you could put the following in your .bashrc file:

export PULSE_SERVER=tcp:$(grep nameserver /etc/resolv.conf | awk '{print $2}');

That way, all pulseaudio sound will be passed to windows, seamlessly.

btw, my config above allows anonymous connections. you can restrict it to IP of the wsl2 vm if you want but it changes regularly. so there isnt really a way as far as I can tell, to have the IP restrictions in place and secured properly.

I have seen people use methods such as: sed and regex to update /modify the config.pa file to the correct IP address on WSL2 start-up, (that lives on /mnt/c/pulse/config.pa) but you must then stop and start the pulse audio NSSM service in windows. - I do not think that is so easy.

Allowing anonymous connections works fine for so far, and has the added benefit, that any WSL/Hyper-V -VM can just put sound out of my laptop over tcp.

Hope that helps!

ghost commented 4 years ago

@ameeno Oops. That shouldn't 404! I'll put that back!

ameeno commented 4 years ago

@tomjepp hey Tom. Awesome thanks. your guide was more pulse on windows for network based sound redirection. But is the best way I have found for having a more modern pulse server permanently on windows.

I adapted it slightly for wsl use and allowed anonymous sound. Perhaps you could incorporate wsl1/2 usage into your guide? Pulse as a service + x410 on start-up makes Linux GUI apps almost seamless.

Thanks for the guide initially!

ghost commented 4 years ago

@ameeno I'm afraid I don't use WSL myself so I can't really do this. Feel free to use this guide as a base, however!

cerebrate commented 4 years ago

Seems like the first relevant question here is what, if any, sound support is coming along with the GUI app support we already know is on the roadmap? @craigloewen-msft ?

Panchie commented 4 years ago

@ameeno @tomjepp Thank you both so much for this, works perfectly with Debian Buster + Mopidy on my desktop. Outstanding stuff.

eamondo2 commented 3 years ago

So I had attempted to get some of the suggestions from this thread, as well as from others I'd found while doing research and wasn't able to get them working reliably.

This is mostly based on the guide from @ameeno above, but with a few extra bits to get X11 working as well.

Git Page

This is an attempt to collate what ended up working, hopefully it will be of some help.

ameeno commented 3 years ago

@eamondo2 Yea, that sounds good.

Only I use X410 instead of vcxsrv

also my .bashrc vars look like this:

### WSL2 Stuff

export WSL2IP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}')
export DISPLAY="$WSL2IP":0.0
export PULSE_SERVER=tcp:"$WSL2IP"

Which seems to work great

another guide I have adapted slightly is this one: https://x410.dev/cookbook/wsl/opening-linux-terminal-directly-from-file-explorer/

Changes I have made include: 1) ubuntu1804.exe becomes ubuntu.exe (for normal ubuntu d/l from ms store) 2) All my Exports/functions/vars for wsl2 and .bashrc is actually inside a file called .exports in my home folder. my .bashrc file sources /home//.exports My Terminal here script sources /home//.exports

3) also I use d:\wsl\ for the vbs script files.

In your case you would need to start the vcxsrv generated file to start your x server. its really handy to have a true linux terminal wherever you want it!!!! :)

glad to help.

timriker commented 3 years ago

I’ve set in etc/pulse/default.pa this:

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;172.16.0.0/12

This will authorize all local connections for WSL1 and the RFC-1918 block 172.16.0.0/12 which is the default space for WSL2.

I would not recommend auth-anonymous=1 as this would allow any remote machine to connect. I use this inside my .bashrc:

if grep -qE "(Microsoft|WSL)" /proc/version &>/dev/null; then
  #WSL1
  export DISPLAY="${DISPLAY:-localhost:0.0}"
  export PULSE_SERVER="${PULSE_SERVER:-tcp:127.0.0.1}"
elif grep -q "microsoft" /proc/version &>/dev/null; then
  # WSL2
  export DISPLAY="$(ip route|awk '/^default/{print $3}'):0.0"
  export PULSE_SERVER="${PULSE_SERVER:-tcp:$(ip route|awk '/^default/{print $3}')}"
fi

Note: I lookup the WSL2 ip using ip route instead of /etc/resolv.conf as I bypass the WSL2 nameserver due to #5806

adamcunnington commented 3 years ago

@ameeno thanks for your guide. I followed it to the letter but unfortunately, on the WSL2 side, I get this: Connection failure: Connection refused

On the windows side, here is what my running instance looks like - should I be concerned about any of the warnings/errors?


W: [(null)] pulsecore/core-util.c: Secure directory creation not supported on Win32.
W: [(null)] pulsecore/core-util.c: Secure directory creation not supported on Win32.
W: [(null)] pulsecore/core-util.c: Secure directory creation not supported on Win32.
W: [(null)] pulsecore/core.c: failed to allocate shared memory pool. Falling back to a normal memory pool.
W: [(null)] pulsecore/authkey.c: Failed to open cookie file 'C:\Users\adam.cunnington\.config/pulse/cookie': No such file or directory
W: [(null)] pulsecore/authkey.c: Failed to load authorization key 'C:\Users\adam.cunnington\.config/pulse/cookie': No error
W: [(null)] pulsecore/core-util.c: Secure directory creation not supported on Win32.```
ameeno commented 3 years ago

Your pulse server is not accepting connections. Can you try to put pulse In c:\pulse\ directory and run pulse as administrator in CMD?

I expect if the pulse server does not come up on the windows side, then connection refused on the wsl2 side is quite normal.

Make sure you run your CMD as administrator to launch pulse first time.

Also I noticed you have a mix of back slashes and forward slashes in your logs.

adamcunnington commented 3 years ago

@ameeno I don't think it's that because here's a strange thing... sound works when I run a docker container within wsl2.

In my dockerfile, i do 2 things:

ENV PULSE_SERVER=tcp:host.docker.internal:4713

RUN apt-get install -y pulseaudio vlc

How can it be working through docker via WSL but not from WSL directly?

Full details below. make run-local runs locally whereas make run runs a docker container. How strange that the latter works and the former doesn't - what am I missing?


ac@L153W10LT:~/Projects/Home/Bible$ make run-local
. .venv/bin/activate && \
        python -ic "import bible"
>>> bible.esv["gen"][1][1].audio()
[0000000001ad3a50] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[000000000212a1b0] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
>>> ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
[000000000212a1b0] alsa audio output error: cannot open ALSA device "default": No such file or directory
[000000000212a1b0] main audio output error: Audio output failed
[000000000212a1b0] main audio output error: The audio device "default" could not be used:
No such file or directory.
[000000000212a1b0] main audio output error: module not functional
[00007f02d804df50] main decoder error: failed to create audio output

----

ac@L153W10LT:~/Projects/Home/Bible$ make run
docker run -it --rm --env-file .env -e ESV_API_TOKEN bible:latest
. .venv/bin/activate && \
        python -ic "import bible"
>>> bible.esv["gen"][1][1].audio()
>>>
adamcunnington commented 3 years ago

@ameeno any thoughts? Grateful for any help, thank you

ameeno commented 3 years ago

definetly a linux config issue not a pulse issue. if the pulse works on windows the pulse works on windows.

perhaps you have installed some other sound server or dummy sound configs in your wsl2 escapades? how about starting a new wsl2 install as a side project and seeing if you can get it working there following the guide?

otherwise there is too many possible variables to debug.

adamcunnington commented 3 years ago

I literally did a fresh install of wsl2 + 20.04 just yesterday and same issue. I have apt remove --purge pulseaudio alsa-base and reinstalled and same problem. But I agree with you - it's something in my ubuntu config that is causing problems when it's trying to connect to my windows pulse server.

ameeno commented 3 years ago

Yes. My guess is (and i ran into this initially when I was debugging the first time) - the default sound device in pulse is a) either DUMMY OUTPUT or B) Muted.

now to get around this you need to use a command-line mixer app to unmute the sound and select the correct sound device as default.

i think this might work.

sudo rm /etc/pulse/client.conf #or just make sure every line is commented by cat /etc/pulse/client.conf

rm -rf ~/.config/pulse/*
pax11publish -e -r

test connection (ensuring env var is correct) with

echo $PULSE_SERVER
pactl info

that should print out some information about the pulse server you are connected to.

finally, you can test sound via command line using

paplay /usr/share/sounds/freedesktop/stereo/bell.oga

and you should hear a bell assuming your pactl info command earlier yielded correct results.

all of this requires having pulseaudio-utils installed in ubuntu.

if the above does not work exit your wsl session after running the commenting/rm commands above. set the shutdown wsl2, restart, add the env var. check the env var mace sure you can get pactl info connecting to the pulse server.

if you cannot, maybe you need to debug the firewall settings etc or the pulse windows config for access list?

hope my pointers are helpful.

adamcunnington commented 3 years ago

@ameeno Thanks for the info. Here's the output of the first few:

ac@L153W10LT:~/Projects/Home/Bible$ sudo rm /etc/pulse/client.conf
[sudo] password for ac:
ac@L153W10LT:~/Projects/Home/Bible$ rm -rf ~/.config/pulse/*
ac@L153W10LT:~/Projects/Home/Bible$ pax11publish -e -r
xcb_connection_has_error() returned true
ac@L153W10LT:~/Projects/Home/Bible$ echo $PULSE_SERVER
tcp:172.31.240.1
ac@L153W10LT:~/Projects/Home/Bible$ pactl info
Connection failure: Connection refused

Presumably, it can't be a firewall issue if my docker container is able to connect via host.docker.internal? Maybe I am misunderstanding but when my docker container runs, is it connecting DIRECTLY to my windows pulse server or via my WSL ubuntu kernel?

Is there somewhere where I can see logs generated by pactl info?

adamcunnington commented 3 years ago

Or perhaps that's a foolish question - maybe the only thing my WSL kernel is doing when I run docker is routing ip connectivity - but fundamentally, it's the pulseaudio client within my docker container that is connecting to my windows pulseaudio server I guess. So, in other words, the problem is my wsl pulseaudio client config.

ameeno commented 3 years ago

quick google tells me you should try

basically salsa is selecting the wrong sound card.

if you install pulseaudio-alsa you should be able to use alsamixer to select the correct soundcard (your system is defaulting to a non-existent soundcard.

ps yes you are right, your docker is presumably connecting to the pulse audio server via IP routing.

your issue lies with your wsl install selecting the wrong soundcard.

you should also try


sudo apt install alsa-base pulseaudio pulseaudio-utils```

there is nothing wrong with having pulseaudio and alsa installed on your wsl, initially it will try to connect to a local soundcard inside the VM which does not exist, which is why we are overriding it with the environmental variable.

after you have done these installs, set the pulse server env var, and then launch alsamixer to select the right sound card.
adamcunnington commented 3 years ago

Thanks - via alsamixer or amixer, i can change the sound card but the question is, to what?

ac@L153W10LT:~/Projects/Home/Bible$ sudo aplay -l
aplay: device_list:274: no soundcards found...
reteps commented 3 years ago

@adamcunnington You can check your audio devices like this too:

$ python3 -m pip install sounddevice && python3 -m sounddevice

  0 pulse, ALSA (32 in, 32 out)
* 1 default, ALSA (32 in, 32 out)

@ameeno Is there a way to get microphone in? I tried recording sound from the pulse sounddevice but it did not work. I can play sounds just fine however.

When I run pactl info it says:

Default Sink: output
Default Source: output.monitor

Update:

Changing record=1 enables the microphone.

Docs: https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Modules/

dcharlespyle commented 3 years ago

Pulseaudio 5.0 also allows the microphone to work between WSL 2 and Windows, and audio can be sampled on my machine at a rate as high as 192,000 Hz. But in WSL 2, the examples above no longer function. This is what I put in my ~/.bashrc file to get it to work right:

# Get the IP Address of the Windows 10 Host and use it in Environment.
HOST_IP=$(host YOURHOSTNAME | grep 192. | tail -1 | awk '{ print $NF }' | tr -d '\r')
export LIBGL_ALWAYS_INDIRECT=1
export DISPLAY=$HOST_IP:0.0
export NO_AT_BRIDGE=1
export PULSE_SERVER=tcp:$HOST_IP
export GTK2_RC_FILES=/usr/share/themes/Yaru-dark/gtk-2.0/gtkrc

Just substitute YOURHOSTNAME with your actual hostname, and the numbers with the first numbers in your range of IP addresses on your local network.

One can use the above as a basis for making shortcuts to Linux programs that can be run in Windows, too.

Here is an example that allows sound and X11 forwarding in the Files program (which will allow one to run videos and audio files directly out of the Files app and be able to see and hear them):

C:\Windows\System32\wsl.exe LIBGL_ALWAYS_INDIRECT=Yes IP=$(host YOURHOSTNAME | grep 192. | tail -1 | awk '{ print $NF }' | tr -d '\r') DISPLAY=$IP:0.0 PULSE_SERVER=tcp:$IP dbus-launch --exit-with-session nautilus

Some apps don't need all that. Most CLI apps can be run without X11 forwarding. Links2 requires it but Lynx does not (unless you want to run sound and watch videos from it as a novelty). This shortcut does not hide the console but that is useful for troubleshooting Linux apps. I just set them to run the console windows minimized, and if I need to see them just click them to restore them to read the output. The above command line examples work no matter what the IP addresses of WSL 2 and Windows host may be. But another oddity with pulseaudio 5.0 from x2go was that I had to organize the files according to Linux file system organization on the host machine, just to get it to work right. But it works great for stereo and for recording. Haven't figured out how to get it to work with 5.1 Windows coreaudio sound yet, but I hope that I eventually can.

image

Edited to add: If you use your computer in a facility and your IP Address changes depending on where you are, you will want to use something that is hostname and IP address agnostic. I now use the following in place of the above:

# Get the IP Address of the Windows 10 Host and use it in Environment.
HOST_IP=$(host `hostname` | grep -oP '(\s)\d+(\.\d+){3}' | tail -1 | awk '{ print $NF }' | tr -d '\r')
export LIBGL_ALWAYS_INDIRECT=1
export DISPLAY=$HOST_IP:0.0
export NO_AT_BRIDGE=1
export PULSE_SERVER=tcp:$HOST_IP
export GTK2_RC_FILES=/usr/share/themes/Yaru-dark/gtk-2.0/gtkrc

The above will get your host's hostname and IP address, no matter what either of them might be. You don't have to know what they are using the revised scripting. It will add a second or two of time to get the information and export it, however. If you always know your hostname and first two or three numbers of your IP address, the prior scripting to the revision is faster.

tamer1an commented 3 years ago

Hi, dear @dcharlespyle.

Could I ask why is only version five and not from an official source?

Is later version above 5 is not compatible? like version 14 for the instance? https://freedesktop.org/software/pulseaudio/releases/

dcharlespyle commented 3 years ago

Hi, dear @dcharlespyle.

Could I ask why is only version five and not from an official source?

Is later version above 5 is not compatible? like version 14 for the instance? https://freedesktop.org/software/pulseaudio/releases/

Have to have a build specifically for Windows available to test, first. I'd be willing to give it a roll, if someone did the build. It has been a couple years or so since I have done any software builds myself. It is just that version 5.0 is the latest version I and others have tested, that didn't fail to build, and that I know works in Windows 10. Previous version used for sound on the Windows side was version 1.1. But version 5.0 had an annoying issue in that it was not organized as was 1.1. All the build files were in the same folder. I had to create new folders modeled after the Linux directory layout, and then move the correct files to their proper locations in those folders, just to get 5.0 to work on Windows 10. Otherwise the program pulseaudio.exe failed even to run. I did not have to do that with 1.1. Version 1.1 ran "out of the box," so to speak. But now there is full microphone support with version 5.0 running on Windows 10. It didn't seem to work in 1.1. But even in Ubuntu 20.04 the version of Pulse at the time I type this is 13.99.1.

One last thing. I have been finding version 5.0 to be less stable on Windows 10 than pulseaudio-1.1. It will randomly stop and you cannot find the running program in Task Manager to kill it. The command pulseaudio -k does not work in Windows. So, I find I have to sign out and sign back in again, when that happens, because pulseaudio.exe will not run after that. With 1.1 I could kill the process and then run pulseaudio.exe using a shortcut. This now fails in version 5.0 and the shortcut won't work to launch the program when it fails. I never had problems like these with version 1.1, and may be rolling back to 1.1 accordingly.

fcoulloudon commented 3 years ago

Good afternoon all,

Thank you for this issue chat.

I’m using Ubuntu 20.04 running & WSL 2. I managed to get through most of the hassle to make it work but I get an error.

paplay xxx.wav return me this error: Connection failure: Access denied

I installed Pulse audio on windows from here: Link Pulseaudio Windows

Deamon.conf looks like this:

; daemonize = no
; fail = yes
; allow-module-loading = yes
; allow-exit = yes
; use-pid-file = yes
; system-instance = no
; enable-shm = yes
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB
; lock-memory = no
; cpu-limit = no

; high-priority = yes
; nice-level = -11

; realtime-scheduling = yes
; realtime-priority = 5

exit-idle-time = -1
; scache-idle-time = 20

; dl-search-path = (depends on architecture)

; load-default-script-file = yes
; default-script-file = /usr/i686-w64-mingw32/sys-root/mingw/etc/pulse/default.pa

; log-target = auto
; log-level = notice
; log-meta = no
; log-time = no
; log-backtrace = 0

; resample-method = speex-float-3
; enable-remixing = yes
; enable-lfe-remixing = no

; flat-volumes = yes

; default-sample-format = s16le
; default-sample-rate = 44100
; default-sample-channels = 2
; default-channel-map = front-left,front-right

; default-fragments = 4
; default-fragment-size-msec = 25

; enable-deferred-volume = yes
; deferred-volume-safety-margin-usec = 8000
; deferred-volume-extra-delay-usec = 0

default.pa looks like this:

.nofail

### Load something into the sample cache
load-sample x11-bell %WINDIR%\Media\ding.wav
load-sample-dir-lazy %WINDIR%\Media\*.wav

.fail

### Automatically restore the volume of streams and devices
load-module module-device-restore
load-module module-stream-restore
load-module module-card-restore

### Automatically augment property information from .desktop files
### stored in /usr/share/application
load-module module-augment-properties

### Load audio drivers statically
### (it's probably better to not load these drivers manually, but instead
### use module-udev-detect -- see below -- for doing this automatically)
load-module module-waveout sink_name=output source_name=input record=0
#load-module module-null-sink

### Automatically load driver modules depending on the hardware available
.ifexists module-detect.so
### Use the static hardware detection module (for systems that lack udev/hal support)
load-module module-detect
.endif

### Automatically connect sink and source if JACK server is present
.ifexists module-jackdbus-detect.so
load-module module-jackdbus-detect
.endif

### Network access (may be configured with paprefs, so leave this commented
### here if you plan to use paprefs)
load-module module-esound-protocol-tcp listen=0.0.0.0 auth-anonymous=1 
load-module module-native-protocol-tcp listen=0.0.0.0 auth-anonymous=1 
load-module module-waveout sink_name=output source_name=input record=0

### Make some devices default
#set-default-sink output
#set-default-source input

I did install these packages in Ubuntu

sudo apt install pulseaudio-utils
sudo apt install libasound2-plugins
sudo apt-get install pulseaudio

Windows Firewall is not blocking anything.

I also ran this: export PULSE_SERVER=tcp:$(grep nameserver /etc/resolv.conf | awk '{print $2}'); and when I executed this line nc -vz $(grep nameserver /etc/resolv.conf | awk '{print $2}') 4713 I get this message: Connection to xxx.30.xxx.1 4713 port [tcp/*] succeeded! (I replaced numbers by xxx)

now when I try paplay or aplay, I get errors messages. image

I also check file rights with CHOWN.

Pulse audio version: pulseaudio 13.99.1 Alsa version: aplay: version 1.2.2 by Jaroslav Kysela perex@perex.cz

What am I missing? How can I better understand the error? This is pretty new for me. Thank you!

dcharlespyle commented 3 years ago

Looks like you may have gotten bitten by the same bug that I did. I found that trying to use nc didn't work as expected. I find I cannot use localhost, either, even though it is supposed to work in WSL 2. Part of the problem likely is that your pulseserver environment variable isn't using the address of your Windows host. Its been that way since I moved to WSL 2, but I worked around the issue. Type echo $PULSE_SERVER and see if the IP address you get matches the one used by your Windows host. If it doesn't match, you can put the following at the end of your ~/.bashrc file.

# Get the IP Address of the Windows 10 Host and use it in Environment.
HOST_IP=$(host `hostname` | grep -oP '(\s)\d+(\.\d+){3}' | tail -1 | awk '{ print $NF }' | tr -d '\r')
export DISPLAY=$HOST_IP:0.0
export PULSE_SERVER=tcp:$HOST_IP

The above will grab the IP address of the Windows host, no matter what it is, and set the environment variable that should allow you to play sounds. You also can make direct shortcuts to GUI programs, but you will have to put similar lines in the command line of the shortcut for it to work the same way.

Unfortunately, the above will add a second or two delay in launch times for programs. If you have a static IP address you can shorten the execution time by just putting the IP address in the environment variables. It should work after that.

fcoulloudon commented 3 years ago

@dcharlespyle Indeed it works, IP address is totally different. Amazing! Thank you again. It's also possible to get this address using netstat (one of the two "local" address) in windows and "hardcode" it. image

This is frustrating! Will do a tutorial when I have some time.

dcharlespyle commented 3 years ago

You're welcome! Glad it worked for you. I'm hoping that they can get localhost to work as it did in WSL 1, and as it does in Hyper-V. But at least this way we still can get functionality without having to run extra processes that may or may not work as things change. With the above, apps can be launched and run from the command line at nearly native speed. Shortcuts have a slight delay but not too bad if the static IP address is put in the command line environment variables. Some degree of tweaking sometimes is required, depending upon the program. One program (running under perl) would not run unless I included the word export with every variable, and separate each variable and command with a semi-colon. Some require launching using dbus-launch --exit-with-session {command} to run properly. Others don't require any of that.

gitthangbaby commented 3 years ago

thanks @dcharlespyle, i also had "connection refused" after reading any guide in the world. Until i ran host $(hostname) in Windows and realized how many IPs computer has. With any HOST_IP= command above it was not working:) With 2 NICs, it will gleefully select the wrong one. "grep 192" again selected wrong ip e.g. 172.1.192.1 and not the correct one starting with 192 :) With ping, nslookup, host, getent, resolveip, dig, php, python.. no luck. Only Windows itself shows it right. Finally i asked ask the authority (router) and that works: HOST_IP=$(dig +short COMPUTER @ROUTER)

dcharlespyle commented 3 years ago

I guess I didn't take into consideration that somebody would have the "192." in the middle of the number. That's another reason to use the latter one I did instead of the former. This is what I have been using since:

HOST_IP=$(host `hostname` | grep -oP '(\s)\d+(\.\d+){3}' | tail -1 | awk '{ print $NF }' | tr -d '\r')

But I'll have to try the one you suggest. Thanks for sharing it.

bradleybennett13 commented 3 years ago

After running the windows service it says that it can't find the file specified is this an issue with installing the service?

dcharlespyle commented 3 years ago

I see that error from time to time but it always eventually runs for me. I don't think it has to do with the service itself. I have a script that runs on every sign-in. This is what I have in said script:

@echo off

REM - Allow XServer time to start.
timeout /t 10 /nobreak >NUL

:TRY

REM - Start WSL System-wide DBus service.
C:\Windows\System32\wsl.exe -e sudo /etc/init.d/dbus start

REM - Allow Sys-wide DBus Service time to start.
timeout /t 10 /nobreak >NUL

REM - Check and show result.
wsl pgrep -a 'dbus-daemon'
IF %ERRORLEVEL% NEQ 0 (GOTO TRY)

:NEXT

REM - Start CUPS Printing Service.
C:\Windows\System32\wsl.exe -e sudo /etc/init.d/cups start

REM - Allow CUPS Service time to start.
timeout /t 10 /nobreak >NUL

REM - Check and show result.
wsl pgrep -a 'cupsd'
IF %ERRORLEVEL% NEQ 0 (GOTO NEXT)

:SPEEDUP

REM - Start Preload (speeds application loading).
C:\Windows\System32\wsl.exe -e sudo /etc/init.d/preload start

REM - Allow Preload time to start.
timeout /t 10 /nobreak >NUL

REM - Check and show result.
wsl pgrep -a 'preload'
IF %ERRORLEVEL% NEQ 0 (GOTO SPEEDUP)

REM - Allow time to show result.
timeout /t 5 /nobreak >NUL

REM - Prestart and terminate LibreOffice for faster loading.
wsl libreoffice --terminate_after_init
timeout /t 5 /nobreak >NUL
wsl libreoffice --terminate_after_init

REM - Uncomment below line for troubleshooting.
REM - pause

exit 0

Do you see that error about the missing file in a BASH prompt or when you start the service itself?

Zingam commented 3 years ago

PipeWire - It looks like Wayland based distros will be adopting PipeWire by default. Wouldn't it make sense to prioritize its support. (Microsft is investing in PulseAudio currently?)

dotnetCarpenter commented 3 years ago

@Zingam Microsoft investing in PulseAudio sounds huge. The PulseAudio team say themselves that they are only 3 volunteers, so getting major backing could change everything for them, I guess,

Do you got a link to where is says that "Microsft is investing in PulseAudio currently"?

Zingam commented 3 years ago

@dotnetCarpenter Well, wasn't that mentioned in one of their presentations along with GPU support that they'll support audio in WSL via PulseAudio? I watched it a while ago, so I hope I don't misremember what was said. (Maybe "invest" was a too strong word.)

znmeb commented 3 years ago

I've had some experience with the GPU support. It's only available right now in the Windows Insider developer preview "fast track". Yes, it's "supported" in the sense that bleeding edge folks like myself can fire it up and give feedback to Microsoft and NVIDIA. It does run the demos I've tried. But it's not a production-ready environment yet.

QAston commented 3 years ago

you can install the pulseaudio server coming with cygwin:

  1. install pulseaudio cygwin package
  2. edit configuration in cygwin
    # in /etc/pulse/default.pa find load-module module-native-protocol-tcp and replace with:
    load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;172.16.0.0/12
    # in /etc/pulse/daemon.conf set
    daemonize = yes
    use-pid-file = no
    exit-idle-time = -1 
  3. add a script to start pulseaudio daemon:
    @echo off
    setlocal enableextensions
    set TERM=
    cd /d "C:\cygwin\bin" && .\bash --login -c "pulseaudio"
daniele777 commented 3 years ago

Hy guys in wsl2 Kali Linux kex i have output but mic hardware not recognized how to fix ?

dcharlespyle commented 3 years ago

You have to give pulseaudio on the Windows side permission to use your microphone. That is the first thing to check. You should see the microphone icon in the notifications on your taskbar.

image

image

If you previously denied permission, you will need to grant permission when it asks. If you are using pulseaudio 1.1, there sometimes are issues with getting the microphone working on some systems. It was hit or miss for me, so I switched to a Windows build of pulseaudio 5.0. Works almost flawlessly for me now.

The second thing to check is your pulseaudio settings. In your default.pa you also need to have immediately after "source_name=input" on the same line the setting "record=1" in the file.

daniele777 commented 3 years ago

I'm not install pulse audio in Windows i'll do It ? I check permission on mic on Windows no ask before

dcharlespyle commented 3 years ago

Installing pulseaudio 1.1 is easy. Just extract the archive into a folder, and then you have to manually edit a couple files. Instructions are available on the Internet, along with the files. The first time you run pulseaudio, Windows 10 always asks for permission the first time. If you denied it, you likely won't get asked again. You also have to allow it through the firewall. On the Linux side, you also have to point to your Windows host IP address. On the Windows side, you also must allow permission through your firewall.

Installing pulseaudio 5.0 is non-trivial. You have to place the files into the correct directories or folders manually. This is how I have it arranged so that I can switch between versions if I find the need:

image

You should start with pulseaudio 1.1 until you familiarize yourself with what files go where.

daniele777 commented 3 years ago

I can't find a right download link for pulse audio Windows ....do you have One ? A d/l link ???

dcharlespyle commented 3 years ago

Most of the information you need can be found here: https://discourse.ubuntu.com/t/getting-sound-to-work-on-wsl2/11869

If you still cannot get it to work, my comment at the bottom of the discussion provides configuration information that will work if the others don't.

daniele777 commented 3 years ago

Screenshot_20210418-232258 I can't download from zipfile contain...etc..

dcharlespyle commented 3 years ago

You have to download it on your computer. Link works fine on a computer.

image

daniele777 commented 3 years ago

ok..download setting up now..i can't connect to pulse...from mixer... i did autorizathion at firewall was pulseaudio.exe started...

Suggestion^^^ ???

pulse audio1 pulse audio2
dcharlespyle commented 3 years ago

You need to configure your daemon.conf and default.pa files with the information stated in the webpage. Following is what I have in my configuration files (you must adjust them for your own system).

default.pa:

#!/usr/i686-w64-mingw32/sys-root/mingw/bin/pulseaudio.exe -nF
#
# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with PulseAudio; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

# This startup script is used only if PulseAudio is started per-user
# (i.e. not in system mode)

.nofail

### Load something into the sample cache
load-sample x11-bell %WINDIR%\Media\ding.wav
load-sample-dir-lazy %WINDIR%\Media\*.wav

.fail

### Automatically restore the volume of streams and devices
load-module module-device-restore
load-module module-stream-restore
load-module module-card-restore

### Automatically augment property information from .desktop files
### stored in /usr/share/application
load-module module-augment-properties

### Load audio drivers statically
### (it's probably better to not load these drivers manually, but instead
### use module-udev-detect -- see below -- for doing this automatically)
load-module module-waveout sink_name=output source_name=input record=1
#load-module module-null-sink

### Automatically load driver modules depending on the hardware available
.ifexists module-detect.so
### Use the static hardware detection module (for systems that lack udev/hal support)
load-module module-detect
.endif

### Automatically connect sink and source if JACK server is present
.ifexists module-jackdbus-detect.so
load-module module-jackdbus-detect
.endif

### Network access (may be configured with paprefs, so leave this commented
### here if you plan to use paprefs)
#load-module module-esound-protocol-tcp
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1

### Make some devices default
#set-default-sink output
#set-default-source input

daemon.conf:

# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with PulseAudio; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.

## Configuration file for the PulseAudio daemon. See pulse-daemon.conf(5) for
## more information. Default values are commented out.  Use either ; or # for
## commenting.

; daemonize = no
; fail = yes
; allow-module-loading = yes
; allow-exit = yes
; use-pid-file = yes
; system-instance = no
; enable-shm = yes
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB
; lock-memory = no
; cpu-limit = no

; high-priority = yes
; nice-level = -11

realtime-scheduling = yes
realtime-priority = 5

exit-idle-time = -1
; scache-idle-time = 20

; dl-search-path = (depends on architecture)

; load-default-script-file = yes
; default-script-file = /usr/i686-w64-mingw32/sys-root/mingw/etc/pulse/default.pa

; log-target = auto
; log-level = notice
; log-meta = no
; log-time = no
; log-backtrace = 0

; resample-method = speex-float-3
; enable-remixing = yes
; enable-lfe-remixing = no

; flat-volumes = yes

; default-sample-format = s16le
; default-sample-rate = 44100
; default-sample-channels = 2
; default-channel-map = front-left,front-right
default-sample-rate = 48000

; default-fragments = 4
; default-fragment-size-msec = 25

; enable-deferred-volume = yes
; deferred-volume-safety-margin-usec = 8000
; deferred-volume-extra-delay-usec = 0

You then need to put the proper environment variables in your ~/.bashrc file. Following are the ones I use:

# Get the IP Address of the Windows 10 Host and use it in Environment.
HOST_IP=$(host `hostname` | grep -oP '(\s)\d+(\.\d+){3}' | tail -1 | awk '{ print $NF }' | tr -d '\r')
export LIBGL_ALWAYS_INDIRECT=1
export DISPLAY=$HOST_IP:0.0
export NO_AT_BRIDGE=1
export PULSE_SERVER=tcp:$HOST_IP

Create a shortcut in your startup folder that contains the following target information (adjust for the path on your system):

C:\WSLAudio\pulseaudio-1.1\bin\pulseaudio.exe -D

Then, sign off and sign in again. This will start pulseaudio each time you sign in.

daniele777 commented 3 years ago

Sorry need explain Need to open some file in linux with sudo nano? HOST_IP=$(host hostname | grep -oP '(\s)\d+(.\d+){3}' | tail -1 | awk '{ print $NF }' | tr -d '\r') section 'hostname' with result of .. ipconfig /all of address of IPV4 ?