kdschlosser / pyWinCoreAudio

Python Windows Core Audio API
GNU General Public License v2.0
34 stars 9 forks source link

Switch process to another device #5

Open KillerBOSS2019 opened 2 years ago

KillerBOSS2019 commented 2 years ago

Hi, Thanks for the awesome library. I am curious if there any way to route process to another device? In Win10 under mixer you can see that your able to change app's output/input device.

kdschlosser commented 2 years ago

I am not sure what you mean.

kdschlosser commented 2 years ago

I also have a newer version of the library that runs on python 3. I also reworked the API so it's much easier to use. I also fixed some memory leaks as well.

It's in the develop branch

KillerBOSS2019 commented 2 years ago

image You see discord have audio output

KillerBOSS2019 commented 2 years ago

I want to be able to switch Output device per application

kdschlosser commented 2 years ago

you want to be able to control the volume of another application?

I haven't tried doing that. if you register to get a callback for a stream being created/destroyed you might be able to change the volume of the stream. I would have to mess about with it to see if it can be done.

KillerBOSS2019 commented 2 years ago

you want to be able to control the volume of another application?

I haven't tried doing that. if you register to get a callback for a stream being created/destroyed you might be able to change the volume of the stream. I would have to mess about with it to see if it can be done.

Well change the output device of each application

kdschlosser commented 2 years ago

The only way you can alter the output device is if you set the application to use the default audio endpoint and then using this library you would change the default audio endpoint to whatever it is you want the audio to be output from.

Unfortunately there is no API to redirect another programs audio output to a different endpoint. Now I am not saying there is a way as I am sure there is, I believe you can do what you are looking to do by using the loopback sound device and looping the audio back and then send it back out to the endpoint you want. Problem is Python is simply too slow to be able to do this.

KillerBOSS2019 commented 2 years ago

The only way you can alter the output device is if you set the application to use the default audio endpoint and then using this library you would change the default audio endpoint to whatever it is you want the audio to be output from.

Unfortunately there is no API to redirect another programs audio output to a different endpoint. Now I am not saying there is a way as I am sure there is, I believe you can do what you are looking to do by using the loopback sound device and looping the audio back and then send it back out to the endpoint you want. Problem is Python is simply too slow to be able to do this.

I found this It seems like there is a way using policyconfig https://github.com/Belphemur/SoundSwitch/blob/4ae9d0c6a8dc7cb2f7cf62d8ab8d8ca11d50830c/SoundSwitch.Audio.Manager/AudioSwitcher.cs#L109

kdschlosser commented 2 years ago

OK that is only going to work on Windows 10 version 1803 or newer.

I am looking into it because I am not able to locate the class ids in my registry nor can I locate the the .NET class "Windows.Media.Internal.AudioPolicyConfig".

I have added code to see if I can get it to work. we will see what happens.

KillerBOSS2019 commented 2 years ago

Any luck on this?