如何通过命令行将声音系统静音?
amixer set Master mute
amixer set Master unmute
amixer set Master toggle
-D pulse
选项(由于问题标记为pulseaudio,这应该是被接受的答案)。有关此解决方案的更多详细信息,请参见这里和这里在askubuntu上。 - taniusamixer -q -D pulse sset Master mute
和amixer -q -D pulse sset Master unmute
。在Ubuntu 16.04上效果非常好。 - CPBL要静音:
set-sink-mute SINK 1|0|toggle
:设置指定音频输出设备(通过符号名称或数字索引标识)的静音状态
pactl set-sink-mute @DEFAULT_SINK@ true
pactl set-sink-mute @DEFAULT_SINK@ false
切换:
pactl set-sink-mute @DEFAULT_SINK@ toggle
0
而不是@DEFAULT_SINK@
来设置索引为0的音频输出设备。true等于"1",false等于"0"。pactl set-sink-mute 0 toggle
。 - Matthias Braunpactl set-sink-mute 1 0
来取消静音它们。 - nnnmmm在终端上输入以下内容以静音
amixer set Master mute
类型
amixer set Master unmute
DEFAULT_SINK=$(pactl info | grep "Default Sink" | cut -d " " -f3)
pactl set-sink-mute "$DEFAULT_SINK" "1"
取消静音:
pactl set-sink-mute "$DEFAULT_SINK" "0"
volume
,提供执行权限chmod +x volume
并将其添加到你的路径中ln -sv $PWD/volume /usr/local/bin/
。以下是我的脚本:#!/bin/bash
# script name: volume
# Author: glaudistong at gmail.com
# depends on: yad, coreutils, pulseaudio
ps -ef | grep "yad" | grep -E "Volume [^+\-]" | tr -s " " | cut -d " " -f2 | xargs -i kill "{}" 2>/dev/null
DEFAULT_SINK=$(pactl info | grep "Default Sink" | cut -d " " -f3)
DEFAULT_SOURCE=$(pactl info | grep "Default Source" | cut -d " " -f3)
case "$1" in
init)
{
ps -fe | grep yad | grep -q volume ||
{
yad --notification --command "volume up" --text "+ Volume +" --image ~/Pictures/volume-up-dark.png &
yad --notification --command "volume down" --text "- Volume -" --image ~/Pictures/volume-down-dark.png &
}
};;
up)
{
pactl set-sink-volume "$DEFAULT_SINK" +5%
P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
iconl="$(echo -ne "\U1F50A")"
iconr="$(echo -ne "\U1F56A")"
timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$iconl Volume $P% $iconr" --no-focus --center --skip-taskbar --on-top &
};;
down)
{
pactl set-sink-volume "$DEFAULT_SINK" -5%
P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
iconl="$(echo -ne "\U1F509")"
iconr="$(echo -ne "\U1F569")"
timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$iconl Volume $P% $iconr" --no-focus --center --skip-taskbar --on-top &
};;
mute)
{
ismute=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Mute" | grep "Name:" -A1 | tail -1 |cut -d: -f2| tr -d " ")
if [ "$ismute" == no ]; then
s=1
P=0
icon="$(echo -ne "\U1F507")"
else
P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
icon=""
s=0
fi
pactl set-sink-mute "$DEFAULT_SINK" "$s"
echo $s > /sys/devices/platform/thinkpad_acpi/leds/platform::mute/brightness
timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume $P%" --no-focus --center --skip-taskbar --on-top &
};;
mic-up)
{
pactl set-source-volume "$DEFAULT_SOURCE" +5%
P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
icon="$(echo -en "\U1F3A4")"
timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
};;
mic-down)
{
pactl set-source-volume "$DEFAULT_SOURCE" -5%
icon="$(echo -en "\U1F3A4")"
P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
};;
mic-mute)
{
ismute=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Mute" | grep "Name:" -A1 | tail -1 |cut -d: -f2| tr -d " ")
if [ "$ismute" == no ]; then
s=1
P=0
icon="$(echo -en "\U1F507\U1F3A4")"
else
P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
s=0
icon="$(echo -en "\U1F3A4")"
fi
pactl set-source-mute "$DEFAULT_SOURCE" "$s"
echo $s > /sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness
timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
};;
*)
echo invalid option;;
esac;
@DEFAULT_SINK@
和@DEFAULT_SOURCE@
的默认接收器/发送器来引用,而不是对查询结果进行grep操作。 - ForeverZer0pactl -- set-sink-mute @DEFAULT_SINK@ toggle # Also true/false to mute/unmute
静音和取消静音
如果使用alsa,请使用以下内容
amixer sset 'Master' toggle
静音和取消静音
sudo amixer
并找到与Simple mixer control 'Speaker',0
匹配的输出行来进行替换。 - brycemcd