Stumbled over this strange problem with Ubuntu and sound muting using command line interface (CLI). Everywhere on the internet I found that it can be done with amixer:
amixer sset Master mute amixer sset Master unmute amixer sset Master toggle
For some reason, muting works fine, but unumuting or toggle has no effect. Upon further investigation I noticed that by muting Master channel, “PCM” and “Master Mono” channels are muted too. Unmuting Master does not unmute those two channels. I could have solved this issue by running a bash script that mutes the sound with
amixer sset Master mute
… and unmutes all channels with
amixer sset Master unmute amixer sset PCM unmute amixer sset "Master Mono" unmute
… but what fun is that? You can however mute and unmute with pactl. This requires just a single command line per action:
pactl set-sink-mute 0 1 pactl set-sink-mute 0 0
i’ve been working out how to do stuff using pactl as well. here’s a bash function and alias pair i’ve been using:
alias huixian=”pacmd <<< "list-sink-inputs" | grep index | awk '{ print $2 }'"
luohe () {
r=`pacmd <<< "list-sink-inputs" | grep "sample spec" | awk '{print $5}' | sed -r 's/[A-Za-z]//g'`
c=`pacmd <<< "list-sink-inputs" | grep "sample spec" | awk '{print $4}' | sed -r 's/[A-Za-z]//g'`
pactl load-module module-null-sink sink_name=$2
pactl move-sink-input $1 $2
parec -d $2.monitor | sox -t raw -b 16 -e signed -c $c -r $r – $2.ogg silence 1 0.50 0.1% 1 3.0 0.1%
}
(all of my functions and aliases are named after cities in china, otherwise i'd run out of names.)
the alias lists the currently running sink inputs. these are processes that produce sound card output. the function takes a sink index number (output by the alias) and a basefilename, and records whatever it hears. it starts after a few seconds of silence, and stops after a few seconds of silence, so that what gets recorded is just sound.
Thanks for sharing! :)
Helpful tip, pactl worked perfectly!