Command to mute and unmute a microphone

90,575

Solution 1

Go to System Preferences then Keyboard and click Shortcuts then Custom Shortcuts:

Keyboard shortcuts

Click on Add

Custom shortcut

Fill in:

Toggle Microphone

and

amixer set Capture toggle

For USB webcams you need to chose the device (-c 1), or maybe another number.

amixer -c 1 sset Mic toggle

Click Apply and then associate a new key with this command (e.g. the Pause/Break key).

Solution 2

You can mute the microphone with

amixer set Capture nocap

and unmute the microphone with

amixer set Capture cap

Solution 3

I switch between a USB webcam/mic and my internal mic and the other solutions typically work on the "default" device which is often not the device I'm actively using so I wrote this to mute all microphones

pacmd list-sources | \
        grep -oP 'index: \d+' | \
        awk '{ print $2 }' | \
        xargs -I{} pactl set-source-mute {} toggle

Solution 4

amixer set Capture toggle && amixer get Capture | grep '\[off\]' && notify-send "MIC switched OFF" || notify-send "MIC switched ON"

Solution 5

Simply mute/unmute with this command:

amixer -D pulse sset Capture toggle

You can also add notification to make sure it's on or off, as per vladimirich answer to the same question

amixer -D pulse sset Capture toggle && amixer get Capture | grep '\[off\]' && notify-send "MIC switched OFF" || notify-send "MIC switched ON"

Inspired by Mark Rooney's answer on muting/unmuting sound.

Share:
90,575
Lucian Adrian Grijincu
Author by

Lucian Adrian Grijincu

Updated on September 17, 2022

Comments

  • Lucian Adrian Grijincu
    Lucian Adrian Grijincu over 1 year

    During voice / video conversations I would like to mute/unmute the microphone without having to go through all these steps each time:

    • Sound indicator, Sound preferences, Select Input, Mute or unmute the microphone.

    I'm looking for either:

    • an application that can do this from the command line,
    • a way I can assign a keyboard shortcut that can mute/unmute the microphone
    • JanC
      JanC over 13 years
      If you use Empathy for voice chat, it has a mute button built-in (that works with Google Talk at least, Skype isn't supported yet).
    • Lucian Adrian Grijincu
      Lucian Adrian Grijincu over 13 years
      I'm looking for something that can be made to run through a shortcut, similar to the main volume mute/unmute laptop toggle button.
  • Lucian Adrian Grijincu
    Lucian Adrian Grijincu over 13 years
    These mute the sound from my speakers, not the microphone, but thanks.
  • João Pinto
    João Pinto over 13 years
    You just need to replace 'Master' with the appropriate mixer name, on the terminal use "amixer" to get a list of mixer devices.
  • Lucian Adrian Grijincu
    Lucian Adrian Grijincu over 13 years
    This seems to work: # amixer set Capture toggle
  • Lucian Adrian Grijincu
    Lucian Adrian Grijincu over 13 years
    Can you edit your response (I don't have the necessary karma) to include this answer so I'll accept it?
  • Diego V
    Diego V about 11 years
    Works this with recent releases? Thank you.
  • Pierre-Antoine
    Pierre-Antoine about 11 years
    It does work; thanks to Lucian. I have an "Audio mute" key on my laptop, I mapped it to shift+Audio mute, which is very easy to remember :)
  • Jason Kleban
    Jason Kleban over 10 years
    The command amixer set Mic toggle (not Capture) works for me in terminal but any assigned keyboard shortcut doesn't actually seem to run. I've tried ctrl+Audio Mute but also ctrl+M (captured by keyboard key presses)
  • WhiskerBiscuit
    WhiskerBiscuit about 10 years
    that worked great with raspberry pi, except you substitute Mic for Capture
  • Vitaly
    Vitaly over 9 years
    pacmd is only interactive if you don't give it any commands. I used pacmd list-sources to get a list of inputs and outputs. Under index 2 I had an input devide. (based on its name) Then you can run pacmd set-source-mute 2 1 to mute. Last parameter is a boolean for mute state. 0 or false for unmute and 1 or true for mute.
  • Marceau
    Marceau over 7 years
    Confirmed, this works with Ubuntu 16.10 as well.
  • Stephen Angelico
    Stephen Angelico about 7 years
    On MATE the menus for adding the keybinding are a little different, but it works in the same way. Thanks!
  • Musa Al-hassy
    Musa Al-hassy almost 7 years
    I like the way in which you combine grep and notifications: Super Neat =)
  • gronostaj
    gronostaj over 5 years
    This actually works for me on Ubuntu 16.04. -q can be skipped.
  • Kristof Tak
    Kristof Tak over 5 years
    bindsym XF86AudioMicMute exec --no-startup-id amixer -D pulse sset Capture toggle for i3wm
  • Patrick Dark
    Patrick Dark over 4 years
    This command works for me in Pop_OS! 19.10 (which is based on Ubuntu 19.10). One can explicitly disable microphone capture with the command amixer --device pulse sset Capture nocap and turn the volume of capturing to 0% simultaneously with the command amixer --device pulse sset Capture nocap 0%.
  • brettinternet
    brettinternet over 4 years
    I like this atomic approach. Consider using something like 'index: \d?\d' to account for double-digit source indices.
  • blockloop
    blockloop over 4 years
    'index: \d+' is the more appropriate regexp, but yeah that works :)
  • Pieter Bos
    Pieter Bos almost 4 years
    Here is a one-liner to toggle, instead of set the state: pacmd list-sources | grep -e 'index' -e 'muted:' | sed -n -e '/index: 5/,$p' | head -n2 | tail -n1 | grep yes && pacmd set-source-mute 5 0 || pacmd set-source-mute 5 1. Note that the index occurs in three places, so you need to change those.