简体   繁体   English

查看应用程序是否正在使用 Windows 10 上的麦克风

[英]See if an app is using the Microphone on Windows 10

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.对于网络摄像头,我已经设法在 Python 中写了一些东西,但是到目前为止,我还没有找到对麦克风做同样事情的好方法。

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):在 Windows 中,您在 SysTray 中有一个专用设置,当您的麦克风被应用程序实际使用时会显示该设置(甚至显示哪个应用程序):
麦克风设置
使用麦克风的应用

So obviously Windows knows whether it's used at the moment (that's all I would need) and even which application is using it.所以很明显 Windows 知道它现在是否被使用(这就是我所需要的),甚至知道哪个应用程序正在使用它。 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?是否有可能以某种方式从 Windows 本身获取数据? At this point, I don't even mind which language would be used for it, Python, C#, PowerShell or whatever.在这一点上,我什至不介意使用哪种语言,Python、C#、PowerShell 或其他任何语言。

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. PS:我知道可能有一些方法可以访问麦克风,但它不会显示在 SysTray 中,但这种情况与我想要实现的目标无关。

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.我现在用以下方法管理它 - 我只是截取桌面的屏幕截图并检查我希望出现在 SysTray 中的图标,以防某些应用程序正在使用麦克风。

For this I used the package imagesearch that can be installed via pip:为此,我使用了可以通过pip安装的 package 图像搜索:
pip3 install python-imageseach-drov0 pip3 安装 python-imageseach-drov0

Then I take a screenshot via that package and check whether the item is visible on the screen:然后我通过 package 截取屏幕截图并检查该项目是否在屏幕上可见:

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: imagePath中定义的图像如下所示:
麦克风图标

I found infos for the package on following page: https://brokencode.io/how-to-easily-image-search-with-python/我在下一页找到了 package 的信息: 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.如果有一些可用的 API 可以询问,那仍然会更好,但总比没有好,解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Python、Windows 10 更改麦克风音量 - Changing microphone volume using Python, Windows 10 如何使用python查看是否有一个麦克风处于活动状态? - How to see if there is one microphone active using python? 为什么我在使用 pip (Windows 10) 安装插件后看不到 spyder-terminal? - Why can't I see spyder-terminal after installing plugin using pip (Windows 10)? 使用魔法时看不到在 Jupyter 笔记本中创建的 plot:%matplotlib 笔记本。 Windows 10 和铬 - Not possible to see the plot created in Jupyter notebooks when using magic: %matplotlib notebook. Windows 10 and Chrome 如何在 ZAEA23489CE3AA9B6406EBB28E0CDA430ozer 上为 ios 编译 python kivy 应用程序 - how to compile python kivy app for ios on Windows 10 using buildozer? 无法在 Windows-10 中使用 Docker 运行 Flask 应用程序 - Unable to run Flask App using Docker in Windows-10 在Windows 7和10上使用python - Using python on windows 7 and 10 我的程序有没有办法检测我的麦克风是否被任何程序使用? (视窗 10) - Is there a way my program can detect if my microphone is being used by any programs? (Windows 10) 在 venv 中使用 pip (Windows 10) - Using pip in venv (WIndows 10) Windows:获取默认麦克风名称 - Windows: get default microphone name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM