要关闭和开启麦克风,可以使用 C# 中的 Windows API。以下是示例代码:

关闭麦克风:

using System.Runtime.InteropServices;

...

[DllImport("winmm.dll", EntryPoint = "auxGetNumDevs")]
private static extern int auxGetNumDevs();

[DllImport("winmm.dll", EntryPoint = "auxSetVolume")]
private static extern int auxSetVolume(int uDeviceID, int dwVolume);

...

int numDevices = auxGetNumDevs();
for (int i = 0; i < numDevices; i++)
{
    auxSetVolume(i, 0);
}

开启麦克风:

int numDevices = auxGetNumDevs();
for (int i = 0; i < numDevices; i++)
{
    auxSetVolume(i, 100);
}

注意:这些代码只能静音和取消静音麦克风,不能完全关闭或启用麦克风。要完全关闭或启用麦克风,需要使用更高级的 Windows API。

如何利用C#-关闭和开启-mic

原文地址: https://www.cveoy.top/t/topic/gPc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录