当前位置: 首页>>技术问答>>正文


终端命令设置音量?

, , , ,

问题描述

我有一个外部声卡,大部分工作正常,除了第一次插入时或打开笔记本电脑时,音量设置为100%。也就是整个系统音量,如声音指示器所示。

我正在寻找的是一个终端命令,将该音量设置为50%,这样我就可以在登录时运行它,而不必担心如果我忘记了转动,我播放的第一个音频会在我身上发出声音音量降低。哪些命令允许您更改该音量,即声音指示器中的音量?

我用gsettings和dbus四处探索,但一直无法找到任何可以让我设置系统音量的东西。我知道alsamixer,但这不是我正在寻找的解决方案,因为这不允许我使用声音指示器或笔记本电脑的多媒体键来改变音量。

最佳解决方法

这个答案的一部分来自Setting microphone input volume using the command line?,放在这里为了您的方便。

将音量提高5%

amixer -D pulse sset Master 5%+

减少5%

amixer -D pulse sset Master 5%-

将音量设置为50%

amixer -D pulse sset Master 50%

If you are using ALSA, amixer can be helpful for your script programming.

When dropping the amixer --help command in a terminal you will see something like this:

enter image description here

Depending on your soundcard, levels may be different than mine, but you can use alsamixer in the terminal in order to check which levels and which features in your sound card you can call in a command to set the volume as you wish.

enter image description here

In my example, with my principal sound card (I have 2: the embedded and a PCI audio card), levels are from 0 to 100, this way I can change the volume of a desired input/output in my soundcard by dropping in a terminal the next command:

amixer -c 0 set Front 50DB  amixer -c 0 set Front 64DB  

In the first command, the result will set the Front panel output to 78% level and the second one will set the Front panel output to 100% level.

In order to gather information related to your mixer controls, drop the amixer command with no parameters and you will get a list. Or indicate which audio device you wish to see a list of controls with amixer -c X (where “X” is the number of your audio device).

BTW: Remember that DB values are calculated logarithmically and not linearly.

请记住,该命令允许您控制当前使用的任何声音设备上的参数。

祝你好运!

次佳解决方法

你可以用PulseAudio本身来做(我不会推荐使用ALSA,因为那时你不能使用GUI来增加/减少音量)。

使用pactl:您可以按如下方式设置特定设备的卷:

pactl set-sink-volume 0 +10%

这使得音量增加10%。如果你想把它降低10%

pactl set-sink-volume 0 -10%

如果你需要50%的音量:

pactl set-sink-volume 0 50%

如果你需要摇动整个地方:

pactl set-sink-volume 0 150%

你可以使用百分数或整数,但整数很慢,可能不是你的东西。

pactl /pacmd(与amixer不同)允许将音量增加超过100%:-)。

第三种解决方法

amixer set 'Master' 10%+ – 增加最大声音10%

amixer set 'Master' 10%- – 减少最大声音10%

amixer set 'Master' 10% – 获得最大声音的10%

amixer set 'Master' 80% – 获得80%的最大声音

等等

如果您想将音量设置为’Master’以外,请通过以下方式检查列表:

amixer scontrols


您可能还想查看alsamixerpacmd

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/868.html,未经允许,请勿转载。