Answers:
amixer
在状态栏中单线分析输出的音量:
awk -F"[][]" '/dB/ { print $2 }' <(amixer sget Master)
[][]
意思
]
或[
。
F
vol=$(awk '/%/ {gsub(/[\[\]]/,""); print $4}' <(amixer sget Master))
您可以amixer
用来执行此操作。
$ amixer get Master
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined penum
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 65536 [100%] [off]
Front Right: Playback 65536 [100%] [off]
您还可以更改它并使其静音,如下所示:
设定音量75%
$ amixer set Master 75%
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined penum
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 49152 [75%] [on]
Front Right: Playback 49152 [75%] [on]
静音/取消静音
$ amixer set Master toggle
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined penum
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 65536 [100%] [on]
Front Right: Playback 65536 [100%] [on]
如果您不想通过--quiet
开关看到任何输出,则可以使输出静音。
$ amixer --quiet set Master 75%
$
对
amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print $2 }'
85%
剩下
amixer sget Master | grep 'Left:' | awk -F'[][]' '{ print $2 }'
85%
声音服务器
如果未将Pulseaudio用作默认值,则可以指定要与amixer
哪个服务器一起使用-D pulse
amixer -D pulse sget Master | grep 'Left:' | awk -F'[][]' '{ print $2 }'
85%
/var/lib/alsa/asound.state
。