设置声音输出/输入

发布于 2024-11-03 05:05:00 字数 73 浏览 0 评论 0原文

我一直在网上寻找,但我不知道是否可能:Cocoa Mac OS X 应用程序可以更改声音输入/输出设备吗?如果是这样,怎么会这样呢?

I've been looking all over the web, but I don't know if it is possible: can a Cocoa Mac OS X app change the sound input/output device? If so, how come?

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

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

发布评论

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

评论(2

情徒 2024-11-10 05:05:00

Cocoa Mac OS X 应用程序可以更改声音输入/输出设备吗?

是的,通过 设置 相关音频系统对象属性

如果是这样,怎么会这样?

可能是因为用户可能想要从应用程序内更改默认输入或输出设备,而不是必须在前后跳转到声音预窗格或使用额外的声音菜单。

can a Cocoa Mac OS X app change the sound input/output device?

Yes, by setting the relevant Audio System Object property.

If so, how come?

Probably because the user might want to change the default input or output device from within an application, rather than having to jump over to the Sound prefpane before and after or use the Sound menu extra.

止于盛夏 2024-11-10 05:05:00

我知道这是一篇旧文章,但这些天我一直在努力寻找一种使用代码更改声音输入/输出设备的方法,我终于找到了如何做到这一点。如果其他人遇到同样的问题,这就是答案!

有一个名为 SwitchAudio-OSX 的命令行实用程序 (https://code.google.com/p/ switchaudio-osx/),允许您从终端切换音频源。它是开源的,您可以在这里找到最新版本:https://github.com/deweller/switchaudio -osx

无论如何,您可以使用这些行来更改声音输入/输出设备:

UInt32 propertySize = sizeof(UInt32);
AudioHardwareSetProperty(kAudioHardwarePropertyDefaultInputDevice, propertySize, &newDeviceID); // To change the input device
AudioHardwareSetProperty(kAudioHardwarePropertyDefaultOutputDevice, propertySize, &newDeviceID); // To change the output device
AudioHardwareSetProperty(kAudioHardwarePropertyDefaultSystemOutputDevice, propertySize, &newDeviceID); // To change the system output device

其中 newDeviceIDAudioDeviceID 的实例,代表您要选择的设备的 ID。此外,可以使用以下代码获取所有可用设备的列表:

AudioDeviceID dev_array[64];
AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &propertySize, dev_array);
int numberOfDevices = (propertySize / sizeof(AudioDeviceID));

I know this is an old post but I've been struggling these days trying to find a way of changing the sound input/output device using code and I finally found how to do it. In case someone else runs into the same problem, here's the answer!

There's a command line utility called SwitchAudio-OSX (https://code.google.com/p/switchaudio-osx/) that allows you to switch the audio source from the terminal. It is open-source and you can find the latest version here: https://github.com/deweller/switchaudio-osx.

Anyway, you can use these lines to change the sound input/output device:

UInt32 propertySize = sizeof(UInt32);
AudioHardwareSetProperty(kAudioHardwarePropertyDefaultInputDevice, propertySize, &newDeviceID); // To change the input device
AudioHardwareSetProperty(kAudioHardwarePropertyDefaultOutputDevice, propertySize, &newDeviceID); // To change the output device
AudioHardwareSetProperty(kAudioHardwarePropertyDefaultSystemOutputDevice, propertySize, &newDeviceID); // To change the system output device

Where newDeviceID is an instance of AudioDeviceID and represents the id of the device you want to select. Also, a list of all available devices can be obtained using this code:

AudioDeviceID dev_array[64];
AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &propertySize, dev_array);
int numberOfDevices = (propertySize / sizeof(AudioDeviceID));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文