Log notes from when I wanted a simple command line tool to toggle audio stuff on my Ubuntu 22.04 box (Hive). Turns out the way to do this has changed up a bit. Here is the story leading to the solution.

Tried this script:
https://nikhilwanpal.in/blog/mute-mic-with-keyboard-shortcut-on-ubuntu-or-linux-mint/
No luck. This didn't work because Ubuntu 22.04 is now using PulseAudio not ALSA.

$ amixer set Capture toggle
amixer: Unable to find simple control 'Capture',0

Level-up focusing on Pulse Audio Output Toggle

I'm using pactl in my scripts. From man page:

set-sink-mute SINK 1|0|toggle: Set the mute status of the specified sink (identified by its symbolic name or numerical index)

To mute:

pactl set-sink-mute @DEFAULT_SINK@ true

To unmute:

pactl set-sink-mute @DEFAULT_SINK@ false

To toggle:

pactl set-sink-mute @DEFAULT_SINK@ toggle

Use 0 instead of @DEFAULT_SINK@ to set the sink with numerical index 0. true=="1", false=="0".

Tested on Ubuntu 12.10.
In my setup sometimes amixer unmute fails for some reason.

This proves to work..

Toggle speakers:

pactl set-sink-mute @DEFAULT_SINK@ toggle

Toggle microphone:

pactl set-source-mute @DEFAULT_SOURCE@ toggle