简体   繁体   English

如何以编程方式更改默认音频输入设备

[英]How to change default audio input device programatically

I am looking for a way to set/change default input device inside my application.我正在寻找一种在我的应用程序中设置/更改默认输入设备的方法。 I have several different recording devices and it is very anoying to go into the control panel and change default recording device.我有几种不同的录音设备,进入控制面板并更改默认录音设备 go 非常烦人。 I was looking around and I did not find anything that could help me with the problem.我环顾四周,没有找到任何可以帮助我解决问题的东西。 Application is written in c# and it is targeted for Windows Vista / Windows 7.应用程序在 c# 中编写,针对 Windows Vista / Windows 7。

This can now (actually for quite some time already) be done very easily using theAudioSwitcher.AudioApi.CoreAudio NuGet package .现在(实际上已经有相当长一段时间了)可以使用AudioSwitcher.AudioApi.CoreAudio NuGet package轻松完成。

Simply create a new CoreAudioController :只需创建一个新的CoreAudioController

var controller = new AudioSwitcher.AudioApi.CoreAudio.CoreAudioController();

Get hold of the desired device using its GUID:使用其 GUID 获取所需设备:

var device = controller.GetDevice(Guid.Parse(...));

And lastly set it as the default playback device:最后将其设置为默认播放设备:

controller.DefaultPlaybackDevice = device;

Note: this answer was also posted under this question .注意:这个答案也发布在这个问题下

There is no public API to do this in Vista/7 AFAIK. 在Vista / 7 AFAIK中没有公共API可以执行此操作。

For a media center launch thing I created, I had to open the control panel and send keys to the dialog, a big ugly hack, but it's the best you can do. 对于我创建的媒体中心启动程序,我必须打开控制面板并将键发送到对话框,这是一个很丑陋的技巧,但这是您能做的最好的事情。 (Or run .net reflector on media center (It is able to change it, using undocumented calls)) (或在媒体中心上运行.net反射器(可以使用未记录的调用对其进行更改))

If you had Windows XP, apparently , you can do this by editing the registry. 如果你有Windows XP中, 很明显 ,您可以通过编辑注册表来做到这一点。 The key HKEY_CURRENT_USER\\Software\\Microsoft\\Multimedia\\Sound Mapper\\Playback contains the name of the current default playback device. HKEY_CURRENT_USER\\Software\\Microsoft\\Multimedia\\Sound Mapper\\Playback包含当前默认播放设备的名称。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM