You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何控制Windows系统声音音量(非主音量)及解决自动重置问题

实现Windows系统声音音量锁定与变更通知的小程序

要针对性控制混音器中的「系统声音」音量(而非主音量)并监控其变更,你可以用Python结合Windows Core Audio API快速实现这个工具,以下是具体方案:

依赖安装

首先安装所需的Python库:

pip install pycaw win10toast
  • pycaw:封装了Windows Core Audio API,能精准操作特定音频会话的音量
  • win10toast:用于弹出Windows原生通知提醒

完整代码

from pycaw.pycaw import AudioUtilities, ISimpleAudioVolume
from win10toast import ToastNotifier
import time

def get_system_sounds_session():
    # 遍历所有音频会话,找到系统声音对应的会话
    sessions = AudioUtilities.GetAllSessions()
    for session in sessions:
        if session.Process and session.Process.name() == "SystemSounds.exe":
            volume_ctrl = session._ctl.QueryInterface(ISimpleAudioVolume)
            return volume_ctrl
    return None

def main():
    target_volume = 0.3  # 对应30%音量
    toaster = ToastNotifier()
    system_volume = get_system_sounds_session()
    
    if not system_volume:
        print("错误:无法找到系统声音音频会话")
        return
    
    print("系统声音音量监控已启动,目标音量锁定为30%...")
    toaster.show_toast("音量监控启动", "将持续维持系统声音音量为30%", duration=5)
    
    while True:
        current_volume = system_volume.GetMasterVolume()
        # 检测音量是否偏离目标(允许0.01的误差,避免频繁触发)
        if abs(current_volume - target_volume) > 0.01:
            # 重置音量到目标值
            system_volume.SetMasterVolume(target_volume, None)
            # 弹出通知提醒
            toaster.show_toast("音量被修改!", "系统声音音量已恢复至30%", duration=3)
            # 记录时间戳,方便后续对应排查进程
            print(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] 检测到音量变更,已恢复至30%")
        time.sleep(1)  # 每秒检查一次

if __name__ == "__main__":
    main()

使用说明

  1. 运行脚本后,程序会持续在后台监控系统声音音量
  2. 一旦发现音量被修改为非30%,会自动将其重置,并通过Windows通知提醒你
  3. 控制台会打印变更发生的时间戳,你可以在收到通知后立刻打开任务管理器,查看「详细信息」中近期活动的进程,重点排查:
    • 你使用的复古主题相关后台程序
    • 音效增强、系统优化类软件
    • 近期安装的驱动或系统工具

额外排查建议

  • 暂时禁用复古主题的声音组件,观察是否还会出现音量重置,排除主题本身的问题
  • 检查Windows事件查看器,在「Windows日志>应用程序」中查找与音频、系统声音相关的事件,可能会找到触发重置的进程线索

内容的提问来源于stack exchange,提问作者Reke Unhs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 03:37:45