我可以使用这些命令(从命令行)更改主音量,它会影响所有应用程序,但如何仅更改一个应用程序的音量(XMMS
例如)?
amixer -q set Master toggle # or pactl set-sink-mute 0 toggle
amixer -q sset Master 5%+ unmute # or pactl set-sink-volume 0 -- -5%
amixer -q sset Master 5%- unmute # or pactl set-sink-volume 0 -- +5%
pacmd dump #
很有趣,并且有 GUI 应用程序可以执行此操作:gnome-control-center sound
,pavucontrol
答案1
您可以使用 pactl 命令获取接收器输入的数量。
$ pactl list sink-inputs
...
Sink Input #7119
Driver: protocol-native.c
Owner Module: 12
Client: 6298
Sink: 0
...
Properties:
application.icon_name = "google-chrome"
media.name = "Playback"
application.name = "Chromium"
...
使用这个数字(#7119),您可以指定接收器输入。
$ pactl set-sink-input-mute 7119 toggle
它将用application.icon_name
属性来标识应用程序。以下是指定Chromium的情况。
#!/bin/sh
LANGUAGE="en_US"
app_name="Chromium"
current_sink_num=''
sink_num_check=''
app_name_check=''
pactl list sink-inputs |while read line; do \
sink_num_check=$(echo "$line" |sed -rn 's/^Sink Input #(.*)/\1/p')
if [ "$sink_num_check" != "" ]; then
current_sink_num="$sink_num_check"
else
app_name_check=$(echo "$line" \
|sed -rn 's/application.name = "([^"]*)"/\1/p')
if [ "$app_name_check" = "$app_name" ]; then
echo "$current_sink_num" "$app_name_check"
pactl set-sink-input-mute "$current_sink_num" toggle
fi
fi
done
答案2
Roland Haas 为 PulseAudio 编写了一个工具。
我必须安装libpulse-dev
linux-libc-dev
libc6-dev
zlib1g-dev
libpcre3-dev
libglib2.0-0
libglib2.0-dev
.您可能还需要一个编译器 (gcc) 来make
.
答案3
我的播放音量控制片段可将音量更改 5% 并切换静音。
#!/bin/bash
inc() {
playback_input=$(pactl list sink-inputs short | awk '{print $1}' | head -1)
pactl set-sink-input-volume "$playback_input" +5%
}
dec() {
playback_input=$(pactl list sink-inputs short | awk '{print $1}' | head -1)
pactl set-sink-input-volume "$playback_input" -5%
}
mute() {
playback_input=$(pactl list sink-inputs short | awk '{print $1}' | head -1)
pactl set-sink-input-mute "$playback_input" toggle
}
答案4
使用PulseAudio时,此功能可以轻松设置任何应用程序的音量。
function pacmd-set-app-volume() {
local player="$1"
local volume="$2"
playerSinkIndex="$(pacmd list-sink-inputs | awk '/index:|application.name |application.process.binary / {print $0};' | grep -iC 1 "$player" | awk '/index:/ {print $2}')" # get specific app sink
[[ $playerSinkIndex ]] && pacmd set-sink-input-volume "$playerSinkIndex" "$((volume*65536/100))" # 100% → 65536
}
可以添加到.bashrc
/ .zshrc
。
用法:
pacmd-set-app-volume <loosly_app_name> <volume_percentage> # For eg "MPV Media Player" 55 Or "mpv" "75"
获取名称应用程序和二进制文件:
pacmd list-sink-inputs | awk '/index:|application.name |application.process.binary / {print $0};'