import time
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
def adjust_volume():
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(
IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
while True:
try:
current_volume = volume.GetMasterVolumeLevelScalar() * 100
if current_volume > 40:
print(f"声音过大 ({current_volume}%),将其调整为 10%")
volume.SetMasterVolumeLevelScalar(0.10, None)
time.sleep(1) # 避免频繁检测
except KeyboardInterrupt:
break
if __name__ == "__main__":
print("声音监测脚本已启动")
adjust_volume()
防耳聋脚本
最新推荐文章于 2024-11-15 23:33:54 发布