-
Notifications
You must be signed in to change notification settings - Fork 827
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
Wsl2 sound support #5816
Comments
This article may help https://x410.dev/cookbook/wsl/enabling-sound-in-wsl-ubuntu-let-it-sing/ |
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
Test this setup by running: c:\pulse\pulseaudio.exe -F config.pa
play some sound on wsl2 and you will get it working.
Extract it and copy nssm.exe from the win32 folder to c:\pulse.
Fill in the following details on the Application tab: Display name: PulseAudio 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.
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! |
@ameeno Oops. That shouldn't 404! I'll put that back! |
@tomjepp hey Tom. Awesome thanks. I adapted it slightly for wsl use and allowed anonymous sound. Thanks for the guide initially! |
@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! |
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 ? |
@ameeno @tomjepp Thank you both so much for this, works perfectly with Debian Buster + Mopidy on my desktop. Outstanding stuff. |
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. This is an attempt to collate what ended up working, hopefully it will be of some help. |
@eamondo2 Yea, that sounds good. Only I use X410 instead of vcxsrv also my .bashrc vars look like this:
Which seems to work great another guide I have adapted slightly is this one: Changes I have made include:
In your case you would need to start the vcxsrv generated file to start your x server. glad to help. |
I’ve set in etc/pulse/default.pa this:
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
Note: I lookup the WSL2 ip using ip route instead of /etc/resolv.conf as I bypass the WSL2 nameserver due to #5806 |
@ameeno thanks for your guide. I followed it to the letter but unfortunately, on the WSL2 side, I get this: On the windows side, here is what my running instance looks like - should I be concerned about any of the warnings/errors?
|
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. |
@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:
How can it be working through docker via WSL but not from WSL directly? Full details below.
|
@ameeno any thoughts? Grateful for any help, thank you |
definetly a linux config issue not a pulse issue. 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. |
I literally did a fresh install of wsl2 + 20.04 just yesterday and same issue. I have |
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.
test connection (ensuring env var is correct) with
that should print out some information about the pulse server you are connected to. finally, you can test sound via command line using
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. |
@ameeno Thanks for the info. Here's the output of the first few:
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 |
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. |
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
|
Thanks - via
|
@adamcunnington You can check your audio devices like this too:
@ameeno Is there a way to get microphone in? I tried recording sound from the When I run
Update:Changing Docs: https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Modules/ |
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:
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):
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. Edited to add:
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. |
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? |
I try this and when I run pulse audio with the Config.pa file I get this error .. `E: [(null)] pulsecore/module.c: Failed to load module "module-native-protocol-tcp" (argument: "auth-anonymous=1"): initialization failed. C:\pulse>c:\pulse\pulseaudio.exe -F config.pa |
WSL 2 combined with WSLg provide built-in support for sound. No configuration is needed, nor is running pulseaudio any longer necessary on the Windows side. Delete or comment out any commands regarding redirection of audio or video you put in your .bashrc file. Run the following to ensure that you are using the latest stable WSL 2 configuration: wsl --update |
I've tried this now... and get this when running the command C:\Windows\system32>wsl --shutdown C:\Windows\system32> (audacity:965): dbind-WARNING **: 15:03:21.050: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-prKBEQTgsM: Connection refused ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused ALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card |
I get this error when I comment the display redirect in my .zshrc Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb. |
I think the issue is I’m on windows 10 is there a way to do this on windows 10? |
If you want graphics app support, the closed source commercial app MobaXterm includes an X server and works on Windows 10. It's not open source, but there is a free version for download. export DISPLAY="$(ip route|awk '/^default/{print $3}'):0.0" |
For Windows 10, you need Windows 10 Insider build 21364 or later to use WSLg. At least the last time I checked. What's your build number? Also, if you use redirection for sound and graphics and a third party XServer and pulseaudio, you must use the IP address of your host Windows machine. Also, if you are using pulseaudio, if you are trying to use version 5.0 for Windows you must manually organize the directories properly. |
Same problem running stakira/OpenUtau.
It seems that there isn't any sound device that can be recognized by the ALSA. Hope Microsoft will add sound support in later versions. |
WSL2 already has built-in sound support and Wayland server support. I haven't had to use any third-party ports of Pulseaudio 1.0 or 5.0 or XServer software since WSLg and WSL in Windows 10 Pro preview versions or in Windows 11. I'm using Windows 11 Pro now. But if you did use such third-party software, you need to comment out or remove those lines that redirect sound to the host IP address. Otherwise, the built-in sound support won't work. If you still do need the ported third-party sound device software, I have it here (both 1.0 and 5.0, ready to go; extract to C: and pick one version, and just run the executable pulseaudio.exe in the bin folder with the -d option (though you might have to tweak to work with your audio codecs and hardware): But then you will have to redirect the sound in the environment variable to the host IP address. And you also will need third-party XServer software. Oh, and one other thing. OpenUtau is looking for a hardware device. There isn't one in WSL or WSL2. WSL is using an RDP Sink, as you will see from the following screenshot. On the other hand, Audacity works well with an RDP Sink, as will be seen in the following screenshot. So, I think it should just be a matter of somehow telling OpenUtau to use the RDP Sink. Not sure at the moment how to do that right now. But if you manage to make it work before I can manage to get to it, please post what you did here. |
Audacity working means PortAudio works? afair Jack can use PortAudio? |
tried "jack -d portaudio" but it says driver not found. |
That's not too surprising. You need to install the jack and portaudio backends for pulseaudio and for ALSA. But there is another issue. I tried to run jack, and I don't even get that far (I don't recall ever using it in all the time I've used Linux, either). I get a message asking me if I meant to type several other commands. That does not seem to bode well for the package in Ubuntu. There is no jack installation candidate in 20.04. I can install jackd (which is identified as a dummy package) and run the jackd command, though, if I wanted to do so. I also tried to install portaudio but both synaptic and apt say the package is not found. I do have the libportaudio2 package installed, however. And the portaudio19-dev package still is available, but installing it seems pointless if the portaudio package itself isn't available. Why do you need to use jack in WSL2? Do you have software that is dependent upon it? If you still want to use it, you might try enabling the backports repository. But when Ubuntu starts putting stuff in backports, it often means it is going away. And one other thing: There is no audio hardware device in WSL. Not even emulated hardware. Not presently at any rate. All that is available is the RDP Sink device. |
I will look further into your post later, but as someone working with audio there is tons of great free audio plugins in Linux I would like to be able to use via WSL2, like the "Linux Studio Plugins" for example. |
Whatever solution is used, it must address the RDP Sink. There is no audio hardware emulation in WSL. At least, not yet. |
sometimes for connection refused, we should add --exit-idle-time=1 for pulse service on Windows. |
Here is one way to resolve
export HOST_IP="$(ip route |awk '/^default/{print $3}')"
export PULSE_SERVER="tcp:$HOST_IP"
|
I wanted to add my two cents:
(I'm not fully sure what the issue is, but this fixed it for me.) Also, some services like |
Shooting comments into a necro thread because I have nothing better to do. How in the heck can AUDIO SUPPORT be an afterthought? This is not some obscure feature set, this is AUDIO for the applications that run under WSL. You jumped though like 50 hoops to make video acceleration function but "install pulseaudio server on your Windows machine and proxy traffic to it over tcp" is the official solution citing a pile of third party blogs. I am not sure how to emphasize this to you as I thought this was supposed to be your job, but just because some randos found a way to make it work does not mean that you should not be working to support audio out of the box. You are already leeching off of the great work of a mountain of devs that do this stuff day in and day out for free the least you can do here is keep the issue open and put something in your backlog to officially support pipewire and pulseaudio in some fashion in WSL. What I want to hear is "You ain't got no problem TheLamer, we're on it, everyone just chill out, we're sending the dev which should be coming directly" |
@thelamer , as someone who's done my own share of shouting into voids, I sympathize with the comment; however, if you're still digging for WSL2 sound support, note that PulseAudio should work "out of the box" these days - see wslg/README.md. It worked for me, though I had to pay attention to the WSLg Architecture Overview (and run a few experiments) to understand that the sound interface is limited to a PulseAudio "bridge" - therefore interfaces that look for sound hardware, e.g. PortAudio, probably won't work without additional effort. At least that was my take-away; I think it's also roughly the same take as @dcharlespyle's prior comment. For what it's worth, my (limited) experience is that WSL development does an admirable job of keeping pace with customer demands. But I'd also agree that transparency about what's in the works/priorities can feel thin on the ground (case in point, it would've been nice/saved me time if there had been a follow-up pointer in the "closing this issue" comment 3 years ago). |
Can anyone provide insight into why my sound works out of the box using bash in WSL2 but if I open the same binary via zsh no audio device driver is recognized? Is there something I need to add to my zshrc? |
@epdesjardins Type |
Thank you for taking the time to reply. I'll try when I'm back to work.
On Fri, May 24, 2024, at 5:39 PM, onomatopellan wrote:
@epdesjardins <https://github.com/epdesjardins> Type 'env' in bot cases and you will see which environment variable is missing. In later WSL2 versions the `export PULSE_SERVER=unix:/mnt/wslg/PulseServer` is a must.
—
Reply to this email directly, view it on GitHub <#5816 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/BFJX3L2ZZ3SFHGMS5L3QRR3ZD6XQFAVCNFSM4QLNZU3KU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMJTGA2DAMZTGQYA>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
Evan Desjardins
***@***.***
669-609-2884
https://gardensound.ca
|
Thanks, this worked |
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.
The text was updated successfully, but these errors were encountered: