简体   繁体   English

如何以编程方式设置系统响度(在OSX和Windows上)

[英]How to set the system loudness programmatically (on OSX and Windows)

I want to manipulate the system loudness (the global volume, or whatever it is called) from within my program. 我想从我的程序中操纵系统响度(全局音量,或任何其他音量)。 This might seem ridiculous, but I need to do some measurements, so I am interested in not only attenuating the sound via an internal loudness, but also amplify it, which is only possible using the system loudness. 这看似荒谬,但我需要进行一些测量,因此我不仅对通过内部响度衰减声音而且还对其进行放大感兴趣,这只有在使用系统响度时才可能实现。 Since I am using Qt, a C++-solution would be greatly appreciated. 由于我使用的是Qt,因此非常感谢C ++解决方案。

Would anyone know how to do this on either Windows or OSX? 有人知道如何在Windows或OSX上执行此操作吗? (Cross-platform development, you see...) (跨平台开发,您看到...)

Thank you in advance! 先感谢您!

Check out this post. 看看这篇文章。 CocoaDev: SoundVolume CocoaDev:SoundVolume

One possibility on OSX is to use a terminal command: OSX上的一种可能性是使用终端命令:

#include <cstdlib>
system("osascript -e \"set Volume 5\"\n");

(Of course, you may change ' 5 ' to whatever you like; The range seems to be between 0 and about 7.5 (?)) (当然,您可以将“ 5 ”更改为任意值;该范围似乎在0到7.5之间(?)。

Admittedly, this is not a pretty solution and I am still interested in a better one, but at least it works, although at a hefty performance cost while executing the command. 诚然,这不是一个很好的解决方案,我仍然对更好的解决方案感兴趣,但是至少它可以工作,尽管执行命令时会付出很高的性能代价。

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

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