Ubuntu Command for Mic Mute with Pulsemixer

One of the major problems I run into with video conferencing tools is how many of them are not at all accessible. I'm a keyboard-only user so if I need to hover a pointer in a particular area of the screen and then click an icon to mute ... then I can't do that. And if you mute me when I join because there are a lot of people here, then I can't participate at all. To work around this, I need a one-liner to mute (and unmute) my mic ... so here it is.

pulsemixer --id source-5 --toggle-mute

Seems easy, right? There's a catch!

The source-5 identifier changes on boot. Check out your list of sources:

pulsemixer --source-list

Pick your mic from the list, run the toggle command so it's in your command history, and then repeat as needed. You could even wrap it up in a shell script, or as I do, hook it up to your streamdeck or other external input. It would be even better if you could automate finding your source .... I have this dumped in a comment in the code but I haven't dared to use it for real yet:

pulsemixer --list-sources | cut -f3 | grep 'UMC404HD 192k Multichannel' | cut -d ',' -f 1 | cut -c 6-

I will leave it here just in case it's useful to you!

Pro-tip: More and more of the video conference tools seem to be introducing support for muting and unmuting you when your system microphone is muted or unmuted. This is brilliant because people can still see that you actively unmuted to say something!


Also published on Medium.

2 thoughts on “Ubuntu Command for Mic Mute with Pulsemixer

  1. I found the following command to toggle mute the default mic input:
    [code]
    pactl set-source-mute @[email protected] toggle
    [/code]

    I also wanted to map a key to this command, but wanted some visual feedback to see if the mic was muted or not. I found out that there is a key code defined named XF86AudioMicMute which, at least in Linux Mint/Cinnamon, shows a OSD notification. I think it might also work on Ubuntu. I mapped Scroll Lock to it using xmodmap:
    [code]
    xmodmap -e "keycode 78 = XF86AudioMicMute"
    [/code]

    If you want to map another key then scroll lock (code 78), you can find all keycodes using:
    [code]
    xmodmap -pk
    [/code]

  2. The Pulseaudio source index integer doesn't just change on boot, it changes when you remove a USB device and plug it back in, too.

    There are some more reliable ways to target the device.

    1. Like Bert says, `pactl` recognizes the `@[email protected]` special name. It corresponds to whichever source Pulseaudio *currently* thinks is the default. This might be enough, but I wouldn't like to make any assumptions about what the default source currently is. Many desktop environments (Mate, Plasma) let you choose the default device via a GUI, and some distros also change the default device automatically when you plug in a USB sound card or headset.

    2. You can target specific devices with `pactl`, using machine-names which seem to be reliable. Compare the output of `pulsemixer` with `pactl`...

    [code]
    $ # Shows some human readable names, and volatile ID integers
    $ pulsemixer --list-sources
    Source: ID: source-0, Name: Monitor of Built-in Audio Analogue Stereo, Mute: 0, Channels: 2, Volumes: ['100%', '100%']
    Source: ID: source-1, Name: Built-in Audio Analogue Stereo, Mute: 1, Channels: 2, Volumes: ['55%', '55%']
    Source: ID: source-8, Name: Monitor of G35 Headset Analogue Stereo, Mute: 0, Channels: 2, Volumes: ['100%', '100%']
    Source: ID: source-9, Name: G35 Headset Mono, Mute: 0, Channels: 1, Volumes: ['80%'], Default

    $ # Shows some reliable machine-names, and volatile ID integers
    $ pactl list short sources
    0 alsa_output.pci-0000_00_1b.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 48000Hz SUSPENDED
    1 alsa_input.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
    8 alsa_output.usb-Logitech_Logitech_G35_Headset-00.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
    9 alsa_input.usb-Logitech_Logitech_G35_Headset-00.mono-fallback module-alsa-card.c s16le 1ch 44100Hz SUSPENDED
    [/code]

    The latter tells you some machine names for the Pulseaudio sources, and you can target these directly:

    [code]
    $ pactl set-source-mute alsa_input.usb-Logitech_Logitech_G35_Headset-00.mono-fallback toggle
    [/code]

    AFAICT these machine-names are reliable. The laptop's built-in devices are named after their PCI path, and the USB devices are named after the machine-readable vendor/model information. They remain the same across reboots and USB hot-plugging, and it doesn't matter which USB socket you use. I'm a bit suspicious of the `00` in the name of my headset; I suppose those digits would disambiguate sources if I plugged in two headsets of the same model? That's not something I'll be doing in practice. I don't know if the name changes when there are USB hubs/docks between the host and audio device.

    3. Maybe you can write a `udev` rule which reacts to a particular device being plugged in, by telling Pulseaudio to treat it as the default source? I haven't tried that yet.

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.