“set default microphone from C#” 的中文翻译是 “设置默认麦克风从 C#”。

huangapple go评论79阅读模式
英文:

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(&quot;winmm.dll&quot;, 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 &lt; 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.

huangapple
  • 本文由 发表于 2023年5月22日 11:19:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76302848.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定