Command to mute and unmute a microphone
Solution 1
Go to System Preferences then Keyboard and click Shortcuts then Custom Shortcuts:
Click on Add
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.
Lucian Adrian Grijincu
Updated on September 17, 2022Comments
-
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 over 13 yearsIf 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 over 13 yearsI'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 over 13 yearsThese mute the sound from my speakers, not the microphone, but thanks.
-
João Pinto over 13 yearsYou 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 over 13 yearsThis seems to work: # amixer set Capture toggle
-
Lucian Adrian Grijincu over 13 yearsCan you edit your response (I don't have the necessary karma) to include this answer so I'll accept it?
-
Diego V about 11 yearsWorks this with recent releases? Thank you.
-
Pierre-Antoine about 11 yearsIt 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 over 10 yearsThe command
amixer set Mic toggle
(notCapture
) works for me in terminal but any assigned keyboard shortcut doesn't actually seem to run. I've triedctrl+Audio Mute
but alsoctrl+M
(captured by keyboard key presses) -
WhiskerBiscuit about 10 yearsthat worked great with raspberry pi, except you substitute Mic for Capture
-
Vitaly over 9 yearspacmd 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 runpacmd 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 over 7 yearsConfirmed, this works with Ubuntu 16.10 as well.
-
Stephen Angelico about 7 yearsOn MATE the menus for adding the keybinding are a little different, but it works in the same way. Thanks!
-
Musa Al-hassy almost 7 yearsI like the way in which you combine grep and notifications: Super Neat =)
-
gronostaj over 5 yearsThis actually works for me on Ubuntu 16.04.
-q
can be skipped. -
Kristof Tak over 5 years
bindsym XF86AudioMicMute exec --no-startup-id amixer -D pulse sset Capture toggle
fori3wm
-
Patrick Dark over 4 yearsThis 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 commandamixer --device pulse sset Capture nocap 0%
. -
brettinternet over 4 yearsI like this atomic approach. Consider using something like
'index: \d?\d'
to account for double-digit source indices. -
blockloop over 4 years
'index: \d+'
is the more appropriate regexp, but yeah that works :) -
Pieter Bos almost 4 yearsHere 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.