I'm trying to write a script that let's me check whether the Webcam and Microphone are in use. For the webcam I already managed to write something in Python, however so far I haven't found a good way to do the same for the microphone.
In Windows you have a dedicated setting in the SysTray that is showing up when your microphone is actually used by an app (and even showing which one):
So obviously Windows knows whether it's used at the moment (that's all I would need) and even which application is using it. However I did not find any way to read that information out in any way yet.
Is it possible to somehow get the data from Windows itself? At this point, I don't even mind which language would be used for it, Python, C#, PowerShell or whatever.
PS: I know there might be ways to access the microphone wihtout it being shown in the SysTray, but this case is not relevant for what I'm trying to achieve.
I managed it now with the following approach - I'm just taking a screenshot of the desktop and check for the icon I expect to appear in the SysTray in case some app is using the microphone.
For this I used the package imagesearch that can be installed via pip:
pip3 install python-imageseach-drov0
Then I take a screenshot via that package and check whether the item is visible on the screen:
from python_imagesearch.imagesearch import imagesearch
pos = imagesearch(imagePath)
microphone_on = pos[0] != -1
if microphone_on:
print("Microphone is in use")
else:
print("Microphone is not in use")
The image defined in imagePath looks like this:
I found infos for the package on following page: https://brokencode.io/how-to-easily-image-search-with-python/
The recognition works very well and fast, but of course this might not be the best solution and works for simple cases where you just want to know whether anything is using the mic or not. It still would be better if there is some API available that could be asked, but it's better than nothing and solves my problem.