从终端设置音量

Tri*_*ian 102 command-line audio linux-mint

是否可以使用终端而不是单击顶部栏中的扬声器图标来设置音量?

我想这样做的原因是我的键盘没有音量增大/减小按钮,而且我觉得伸手去拿鼠标很烦人。

Ren*_*nan 112

对于交互式使用,您可以使用alsamixer. 对于脚本(例如绑定到组合键),请查看amixer.

alsamixer 在大多数系统中默认包含。


要设置主音量,请使用:

# Gets a list of simple mixer controls
$ amixer scontrols 
Run Code Online (Sandbox Code Playgroud)

然后将其设置为所需的音量,例如

$ amixer sset 'Master' 50%
Run Code Online (Sandbox Code Playgroud)

  • “sset”和“set”有什么区别?(我都试过了,都有效) (3认同)
  • 将以下内容添加到我的 `.bashrc` 以简化此命令: `volume() { amixer sset 'Master' $1%; }` (2认同)

enz*_*tib 53

在 Openbox 的配置文件中找到rc.xml

# increase by 3%
amixer -q sset Master 3%+

# decrease by 3%
amixer -q sset Master 3%-

# mute/unmute
amixer -q sset Master toggle
Run Code Online (Sandbox Code Playgroud)

amixer 手册页可以提供更多详细信息。


don*_*sti 30

如果您的系统正在使用,pulseaudio您可以使用pactl

pactl set-sink-volume 0 +15%
Run Code Online (Sandbox Code Playgroud)

或者

pactl set-sink-volume 0 -5dB
Run Code Online (Sandbox Code Playgroud)

虽然您也可以指定整数或线性因子:

set-sink-volume SINK VOLUME [VOLUME ...]
          Set the volume of the specified sink (identified by its symbolic name or numerical index). VOLUME can be speci?
          fied as an integer (e.g. 2000, 16384), a linear factor (e.g. 0.4, 1.100), a percentage (e.g. 10%, 100%) or a
          decibel value (e.g. 0dB, 20dB). If the volume specification start with a + or - the volume  adjustment  will  be
          relative to the current sink volume. A single volume value affects all channels; if multiple volume values are
          given their number has to match the sink's number of channels.
Run Code Online (Sandbox Code Playgroud)

  • 来自 [arch linux wiki](https://wiki.archlinux.org/index.php/PulseAudio/Troubleshooting) 的注意事项:采用负百分比参数的 `pactl` 命令将因“无效选项”错误而失败。使用标准 shell `--` 伪参数在否定参数之前禁用参数解析。例如`pactl set-sink-volume 1 -- -5%` (2认同)
  • @JamieCockburn - 我不确定那是什么时候写的,但_我使用 archlinux_ 并且绝对不需要额外的`--` 负值(百分比、db、整数......它们都可以正常工作)。事实上,**恰恰相反**:如果我按照维基使用`--`,例如`pactl set-sink-volume 1 -- -3%`,我会得到`Invalid volume specification`。 (2认同)
  • @JamieCockburn - 我不认为 shell 是相关的(为了记录,它对我来说对 `bash` 和 `zsh` 都很好)。可能早期版本的 `pactl` 有这个问题,上游很可能修复了它(我使用的是 6.0 版)。 (2认同)

小智 12

我知道这是一个旧的。由于 Alsa 和 pulseaudio 如此紧密相连,askubuntu 的这个答案帮助我管理了主声音和 HDMI 的音量:

增加音量

amixer -q -D pulse sset Master 10%+
Run Code Online (Sandbox Code Playgroud)

减少音量

amixer -q -D pulse sset Master 10%-
Run Code Online (Sandbox Code Playgroud)

切换静音

amixer -q -D pulse sset Master toggle
Run Code Online (Sandbox Code Playgroud)

其他 amixer sset 命令也可以工作。


小智 7

这些“对人耳更自然”。

要在 alsamixer 单元中获取主设备,请使用:

amixer -M get Master
Run Code Online (Sandbox Code Playgroud)

要将 alsamixer 装置的音量提高 5%,例如:

amixer -M set Master 5%+
Run Code Online (Sandbox Code Playgroud)

https://bbs.archlinux.org/viewtopic.php?id=135348


fra*_*eve 6

你也可以尝试pamixer,一个最近的项目,完全符合你的要求。它位于同名的 ArchLinux AUR 存储库中。


1''*_*1'' 6

在 OS X 中使用以下命令:

# highest
osascript -e "set Volume 7"
# lowest
osascript -e "set Volume 1"
# middle
osascript -e "set Volume 3.5"  
Run Code Online (Sandbox Code Playgroud)

您甚至可以将音量设置为其他分数级别:

# 25%
osascript -e "set Volume 1.75"
Run Code Online (Sandbox Code Playgroud)