L
L
leviathan2020-10-11 15:15:59
Python
leviathan, 2020-10-11 15:15:59

How to get the current sound level and its status?

You need to somehow get the current sound level and its state (on / off). How can this be implemented? Windows, Python3.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-10-11
@The_Lars

Try the pycaw library . Here is an example of its use:
pip install pycaw

from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(
    IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
volume.GetMute()
volume.GetMasterVolumeLevel()
volume.GetVolumeRange()
volume.SetMasterVolumeLevel(-20.0, None)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question