How do I change it?
I'm looking for something like:
SetMasterVolume(0.5)
SetAppVolume('FooBar',0.5)
I tried using ctypes.windll.winmm, but I can't find much documentation on how to use it.
Thanks in advance.
Every call to Sound. mute() will toggle mute on or off.
I'd hope after 5 years this is no longer a problem for you, but I've just had to do the same thing. It's possible using the PyCaw library.
Simple proof of concept, based on PyCaw's examples
from __future__ import print_function
from pycaw.pycaw import AudioUtilities, ISimpleAudioVolume
def main():
sessions = AudioUtilities.GetAllSessions()
for session in sessions:
volume = session._ctl.QueryInterface(ISimpleAudioVolume)
if session.Process and session.Process.name() == "vlc.exe":
print("volume.GetMasterVolume(): %s" % volume.GetMasterVolume())
volume.SetMasterVolume(0.6, None)
if __name__ == "__main__":
main()
this is a very roundabout way to do it but it works.you can simulate the key presses for the computers master volume with pynput. it works but it is quite inacurate.
from pynput.keyboard import Key,Controller
keyboard = Controller()
import time
while True:
for i in range(10):
keyboard.press(Key.media_volume_up)
keyboard.release(Key.media_volume_up)
time.sleep(0.1)
for i in range(10):
keyboard.press(Key.media_volume_down)
keyboard.release(Key.media_volume_down)
time.sleep(0.1)
time.sleep(2)
this is an ok method of doing it. every keypress and release is equal to about 2 volume . hope this is somewhat helpful!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With