英文:
set default microphone from c#
问题
I am trying to set the default microphone device on windows 10 and 11. I can list all the devices okay, including getting the current default device. But I cannot find a way to set the default device.
NAudio does not have an API for doing that, so I am trying to use the waveInXXX API instead. But I cannot find an API that will switch the default microphone.
I even tried the new MS Bing AI chat (ChatGPT), which gave me the following code, including a Win32 declaration. Unfortunately, I don't think the API exists!
// from Bing AI Chat
// [DllImport("winmm.dll", CharSet = CharSet.Auto)]
// static extern int waveInSetDefault(int uDeviceID);
// waveInSetDefault(i);
My question is how to set the default microphone device. NAudio doesn't have an API (that I can find). The waveXXX methods do not have an API that I can find (despite the MS AI saying that such an API exists). Is there any way to set the default device from C# without using a Powershell library? (which I have not yet tested)
// here is my code (that fails on the waveInSetDefault(i) call)
public static void
WaveInputDeviceDefaultSet(string match, out WAVEINCAPS defaultDevice) {
WaveInputDevicesAllGet(out var waveDevices);
defaultDevice = waveDevices.First();
// set the default device by its index
for (var i = 0; i < waveDevices.Count; i++) {
if (waveDevices[i].szPname.Contains(match)) {
var code = waveInSetDefault(i);
defaultDevice = waveDevices[i];
break;
}
}
}
英文:
I am trying to set the default microphone device on windows 10 and 11. I can list all the devices okay, including getting the current default device. But I cannot find a way to set the default device.
NAudio does not have an API for doing that, so I am trying to use the waveInXXX API instead. But I cannot find an API that will switch the default microphone.
I even tried the new MS Bing AI chat (ChatGPT), which gave me the following code, including a Win32 declaration. Unfortunately, I don't think the API exists!
// from Bing AI Chat
// [DllImport("winmm.dll", CharSet = CharSet.Auto)]
// static extern int waveInSetDefault(int uDeviceID);
// waveInSetDefault(i);
My question is how to set the default microphone device. NAudio doesn't have an API (that I can find). The waveXXX methods do not have an API that I can find (despite the MS AI saying that such an API exists). Is there any way to set the default device from C# without using a Powershell library? (which I have not yet tested)
// here is my code (that fails on the waveInSetDefault(i) call)
public static void
WaveInputDeviceDefaultSet(string match, out WAVEINCAPS defaultDevice) {
WaveInputDevicesAllGet(out var waveDevices);
defaultDevice = waveDevices.First();
// set the default device by its index
for (var i = 0; i < waveDevices.Count; i++) {
if (waveDevices[i].szPname.Contains(match)) {
var code = waveInSetDefault(i);
defaultDevice = waveDevices[i];
break;
}
}
}
答案1
得分: 0
我在评论中提到,这个众所周知但未记录的接口IPolicyConfig用于与端点合作。您可以尝试*IPolicyConfig::SetDefaultEndpoint
*。
英文:
As I said in comments, the well-known undocumented interface IPolicyConfig
is used to cooperate with endpoints. You can try IPolicyConfig::SetDefaultEndpoint
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论