import win32gui, time, winsound from pycaw.py...

6/09/2021  •  184 views
 
import win32gui, time, winsound
from pycaw.pycaw import AudioUtilities, ISimpleAudioVolume

w=win32gui
sessions = AudioUtilities.GetAllSessions()

while True:
for session in sessions:
volume = session._ctl.QueryInterface(ISimpleAudioVolume)
volume.SetMasterVolume(1, None)

winText = w.GetWindowText (w.GetForegroundWindow())

if "code" not in winText.lower():
winsound.Beep(800, 200)

print(winText)
time.sleep(0.5)
https://paste.ac/yogesh