如何检测任何应用程序是否使用麦克风

发布于 2025-01-22 23:00:44 字数 294 浏览 2 评论 0 原文

我编写了一个程序,该程序会根据我是否参加会议来改变我的灯光。检测到这一点的最简单方法是检查麦克风是否打开。当前,我检查屏幕上是否出现麦克风图标(OPENCV):

我敢肯定它不是最佳解决方案。 Java有什么方法可以检测到正在使用麦克风的事实?

I wrote a program that changes my light depending on whether I'm in a meeting or not. The easiest way to detect this is to check if the microphone is on. Currently, I check if a microphone icon appears on the screen (OpenCv):
enter image description here

I'm sure it's not the most optimal solution. Is there any way in Java to detect the fact that a microphone is being used?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

在风中等你 2025-01-29 23:00:44

多亏了Eskandar Abedini,我能够做到!以下是整个代码:

public enum RegistryType {

    MICROPHONE("microphone"),
    WEBCAM("webcam");

    private final String pathValue;

    RegistryType(String pathValue) {
        this.pathValue = pathValue;
    }

    public String getNonPackagePath() {
        return "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CapabilityAccessManager\\ConsentStore\\" + pathValue + "\\NonPackaged";
    }

}

public class RegistryManager {

    private static final String LAST_USED_TIME_STOP = "LastUsedTimeStop";
    private static final Long LAST_USED_TIME_STOP_VALUE = 0L;

    private RegistryManager() {
    }

    public static boolean isMicrophoneWorking() {
        return isDeviceWorking(MICROPHONE);
    }

    public static boolean isWebcamWorking() {
        return isDeviceWorking(WEBCAM);
    }
    private static boolean isDeviceWorking(final RegistryType registryType) {
        final String[] folders = Advapi32Util.registryGetKeys(WinReg.HKEY_CURRENT_USER, registryType.getNonPackagePath());
        return Arrays.stream(folders)
                .map(folder -> registryType.getNonPackagePath() + "\\" + folder)
                .map(register -> Advapi32Util.registryGetLongValue(WinReg.HKEY_CURRENT_USER, register, LAST_USED_TIME_STOP))
                .anyMatch(lastUsedTimeStop -> LAST_USED_TIME_STOP_VALUE.compareTo(lastUsedTimeStop) >= 0);
    }

}

我还必须使用: https://github.com/java -native-access/jna

Thanks to Eskandar Abedini I was able to do it! Below is the entire code:

public enum RegistryType {

    MICROPHONE("microphone"),
    WEBCAM("webcam");

    private final String pathValue;

    RegistryType(String pathValue) {
        this.pathValue = pathValue;
    }

    public String getNonPackagePath() {
        return "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CapabilityAccessManager\\ConsentStore\\" + pathValue + "\\NonPackaged";
    }

}

public class RegistryManager {

    private static final String LAST_USED_TIME_STOP = "LastUsedTimeStop";
    private static final Long LAST_USED_TIME_STOP_VALUE = 0L;

    private RegistryManager() {
    }

    public static boolean isMicrophoneWorking() {
        return isDeviceWorking(MICROPHONE);
    }

    public static boolean isWebcamWorking() {
        return isDeviceWorking(WEBCAM);
    }
    private static boolean isDeviceWorking(final RegistryType registryType) {
        final String[] folders = Advapi32Util.registryGetKeys(WinReg.HKEY_CURRENT_USER, registryType.getNonPackagePath());
        return Arrays.stream(folders)
                .map(folder -> registryType.getNonPackagePath() + "\\" + folder)
                .map(register -> Advapi32Util.registryGetLongValue(WinReg.HKEY_CURRENT_USER, register, LAST_USED_TIME_STOP))
                .anyMatch(lastUsedTimeStop -> LAST_USED_TIME_STOP_VALUE.compareTo(lastUsedTimeStop) >= 0);
    }

}

And I also had to use: https://github.com/java-native-access/jna

得不到的就毁灭 2025-01-29 23:00:44

几年前,我正在调查如何通过网络传输音频,并写了简单的丑陋项目。

并检查是否准备好使用麦克风:

javax.sound.sampled.TargetDataLine microphone = AudioSystem.getTargetDataLine(null);
if (!microphone.isOpen()) {
    // ...
}

也许这有点无用的信息,但我希望它可以是有用的方向!

链接到类:

A few years ago I was investigating how to transmit audio through the network, and I wrote simple ugly project.

And to check if a mic is ready to use I used:

javax.sound.sampled.TargetDataLine microphone = AudioSystem.getTargetDataLine(null);
if (!microphone.isOpen()) {
    // ...
}

Maybe it's a bit useless info but I hope it can be useful direction!

Link to class: MicrophoneReader.java

好多鱼好多余 2025-01-29 23:00:44

您可以检查Windows注册表,检查托盘或其他方式麦克风用法

注意:

Microsoft警告说,桌面应用程序可以录制声音,而无需
通知窗口。因为它们不受沙箱的影响
Microsoft商店应用程序的限制,桌面程序可以直接
与您的麦克风硬件接口。这意味着恶意软件
可以在没有窗口的情况下录制,因此不会出现在
在系统托盘中列出或显示麦克风图标。

如何查看哪些应用在Windows 10中使用您的麦克风

You may check Windows registry, checking tray or other means for microphone usage

Detecting if mic/camera is in use?

Note:

Microsoft warns that desktop apps can record sound without ever
notifying Windows. Because they're not subject to the sandbox
restrictions of Microsoft Store apps, a desktop program can directly
interface with your microphone hardware. This means malicious software
could record without Windows being aware, so it won't show up in the
list or display the microphone icon in the system tray.

Detecting if mic/camera is in use?
How to see which apps are using your microphone in Windows 10

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文