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

controling " python.exe " controls the global volume of Windows. #83

Open
ftk7810 opened this issue Oct 27, 2023 · 2 comments
Open

controling " python.exe " controls the global volume of Windows. #83

ftk7810 opened this issue Oct 27, 2023 · 2 comments

Comments

@ftk7810
Copy link

ftk7810 commented Oct 27, 2023

I'm on the latest pycaw update, And I'm using windows 10, When I do this:

 for session in sessions:
        if session.Process and session.Process.name() == "python.exe":
            if psutil.pid_exists(session.Process.pid):
                volume_interface.SetMasterVolumeLevelScalar(volume, None)

For some reason it controls the Global volume of the whole output device, Is there a way I can make it so it controls the python script it's running from instead?

@0ekel
Copy link

0ekel commented Feb 28, 2024

Probably already to late but

try looking at this from the examples

def set_volume(self, decibels , process):
sessions = AudioUtilities.GetSessionsFromAllDevices()
for session in sessions:
interface = session.SimpleAudioVolume
if session.Process and session.Process.name() == process:
# only set volume in the range 0.0 to 1.0
self.volume = min(1.0, max(0.0, decibels))
interface.SetMasterVolume(self.volume, None)
#print("Volume set to", self.volume) # debug

@TJ-59
Copy link

TJ-59 commented Sep 23, 2024

Might be because you're supposed to use GetMasterVolume() and SetMasterVolume() on a session's SimpleAudioVolume.
Well, as long as you actually want the ratio to be depending on the ACTUAL device's GetMasterVolumeLevelScalar() and SetMasterVolumeLevelScalar().
If you set your DEVICE at 0.5 (aka 50%), and then set your session, using SetMasterVolume(), to 1.0, then your session is at "100% of 50%"... If you set your session to 0.3, then the volume is "30% of 50%" (aka 15%).
Think of it like the Windows Audio Mixer : the device's volume, on the left side of the panel, casts a bar over the rest of the panel, above the apps' volumes; whenever you try to raise the volume of an app ABOVE that bar, the device's volume is moved UP to accommodate the "extra volume needed", but by doing so, it only ever raises the global volume, as nothing can automatically bring it down.
Using a SetMasterVolumeLevelScalar() on a SESSION is just doing that, hence the global volume going up when you're only touching the app's volume.

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

No branches or pull requests

3 participants