Toggle Microphone Mute

Post your working scripts, libraries and tools
Firenyth

Toggle Microphone Mute

01 Apr 2016, 09:00

Code: Select all

Pause::  ;Pause Break button is my chosen hotkey

SoundSet, +1, MASTER, mute,12 ;12 was my mic id number use the code below the dotted line to find your mic id. you need to replace all 12's  <---------IMPORTANT
SoundGet, master_mute, , mute, 12

ToolTip, Mute %master_mute% ;use a tool tip at mouse pointer to show what state mic is after toggle
SetTimer, RemoveToolTip, 1000
return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

Use this code below as a seperate script to find your microphone id number.

tip: set your mic volume to something different like 79% so you can find it in the list
--------------------------------------------------------------

Code: Select all

SetBatchLines -1
SplashTextOn,,, Gathering Soundcard Info...

; Most of the pure numbers below probably don't exist in any mixer, but they're queried for completeness.
; The numbers correspond to the following items (in order): CUSTOM, BOOLEANMETER, SIGNEDMETER, PEAKMETER,
; UNSIGNEDMETER, BOOLEAN, BUTTON, DECIBELS, SIGNED, UNSIGNED, PERCENT, SLIDER, FADER, SINGLESELECT, MUX,
; MULTIPLESELECT, MIXER, MICROTIME, MILLITIME
ControlTypes = VOLUME,ONOFF,MUTE,MONO,LOUDNESS,STEREOENH,BASSBOOST,PAN,QSOUNDPAN,BASS,TREBLE,EQUALIZER,0x00000000, 0x10010000,0x10020000,0x10020001,0x10030000,0x20010000,0x21010000,0x30040000,0x30020000,0x30030000,0x30050000,0x40020000,0x50030000,0x70010000,0x70010001,0x71010000,0x71010001,0x60030000,0x61030000

ComponentTypes = MASTER,HEADPHONES,DIGITAL,LINE,MICROPHONE,SYNTH,CD,TELEPHONE,PCSPEAKER,WAVE,AUX,ANALOG,N/A

; Create a ListView and prepare for the main loop:
Gui, Add, Listview, w400 h400 vMyListView, Component Type|Control Type|Setting|Mixer
LV_ModifyCol(4, "Integer")
SetFormat, Float, 0.2  ; Limit number of decimal places in percentages to two.

Loop  ; For each mixer number that exists in the system, query its capabilities.
{
    CurrMixer := A_Index
    SoundGet, Setting,,, %CurrMixer%
    if ErrorLevel = Can't Open Specified Mixer  ; Any error other than this indicates that the mixer exists.
        break

    ; For each component type that exists in this mixer, query its instances and control types:
    Loop, parse, ComponentTypes, `,
    {
        CurrComponent := A_LoopField
        ; First check if this component type even exists in the mixer:
        SoundGet, Setting, %CurrComponent%,, %CurrMixer%
        if ErrorLevel = Mixer Doesn't Support This Component Type
            continue  ; Start a new iteration to move on to the next component type.
        Loop  ; For each instance of this component type, query its control types.
        {
            CurrInstance := A_Index
            ; First check if this instance of this instance even exists in the mixer:
            SoundGet, Setting, %CurrComponent%:%CurrInstance%,, %CurrMixer%
            ; Checking for both of the following errors allows this script to run on older versions:
            if ErrorLevel in Mixer Doesn't Have That Many of That Component Type,Invalid Control Type or Component Type
                break  ; No more instances of this component type.
            ; Get the current setting of each control type that exists in this instance of this component:
            Loop, parse, ControlTypes, `,
            {
                CurrControl := A_LoopField
                SoundGet, Setting, %CurrComponent%:%CurrInstance%, %CurrControl%, %CurrMixer%
                ; Checking for both of the following errors allows this script to run on older versions:
                if ErrorLevel in Component Doesn't Support This Control Type,Invalid Control Type or Component Type
                    continue
                if ErrorLevel  ; Some other error, which is unexpected so show it in the results.
                    Setting := ErrorLevel
                ComponentString := CurrComponent
                if CurrInstance > 1
                    ComponentString = %ComponentString%:%CurrInstance%
                LV_Add("", ComponentString, CurrControl, Setting, CurrMixer)
            }  ; For each control type.
        }  ; For each component instance.
    }  ; For each component type.
}  ; For each mixer.

Loop % LV_GetCount("Col")  ; Auto-size each column to fit its contents.
    LV_ModifyCol(A_Index, "AutoHdr")

SplashTextOff
Gui, Show
return

GuiClose:
ExitApp
Mod edit: Added code tags.
Taloose

Re: Toggle Microphone Mute

18 Jul 2016, 12:50

Thank you so much. You are my hero. I've been digging and digging on how I can hotkey my microphone boost and this completely figured it out for me.
KORR

Re: Toggle Microphone Mute

13 May 2017, 17:17

Thanks man! Worked perfectly. Now I don't need separate hotkeys in all my apps/games/whatever.
azsheepdog
Posts: 1
Joined: 26 Jul 2017, 13:37

Re: Toggle Microphone Mute

26 Jul 2017, 19:51

Just wanted to say thanks for this. Worked great and the Mouse pointer tooltip was an unexpected bonus. Script worked for both a windows 10 and 7 computer , just had to change the numbers for each computer.
Tmara Huko

Re: Toggle Microphone Mute

29 Oct 2017, 15:36

how can i get the current status of the mic if its mute or unmute?
User avatar
elModo7
Posts: 186
Joined: 01 Sep 2017, 02:38
GitHub: elModo7
Location: Spain
Contact:

Re: Toggle Microphone Mute

06 Nov 2017, 05:08

Works like a charm!
Thanks for sharing :)
:beer:
lipsmoker
Posts: 1
Joined: 03 May 2019, 18:22

Re: Toggle Microphone Mute

03 May 2019, 18:25

Id like to add in 2019 this works great for Fortnite, Which doesn't have a mute option for the mic, only push to talk. If it keeps pulling you out of fullscreen however, make sure you compile the script and run it as admin. (And throw it in your windows startup folder if you want it all the time) :D :D :D Thankyou! I'm working on a way to find out if it's on or off (In a fullscreen game) , maybe via the num lock status light or something, Will update when I figure it out eventually
myfregat
Posts: 1
Joined: 04 Nov 2019, 12:36

Re: Toggle Microphone Mute

04 Nov 2019, 12:48

Thanks! It still works!
alcamtar
Posts: 1
Joined: 30 Mar 2020, 15:59

Re: Toggle Microphone Mute

30 Mar 2020, 16:38

Thanks for this, works perfectly. Using it to toggle the mic in Teams.
User avatar
geekyadam
Posts: 33
Joined: 01 Aug 2016, 17:11

Re: Toggle Microphone Mute

08 Apr 2020, 10:48

Found this code via YT video (https://www.youtube.com/watch?v=JV7fPXIpm8A) and works great in Windows 10. Thanks for the code! #creditwheredue
medellinrob
Posts: 7
Joined: 08 Jan 2019, 21:53

Re: Toggle Microphone Mute

11 May 2020, 15:26

Hi.
This works, but I have an issue... My machine is ID #2, but when I connect my usb headset its #3, is it ok to duplicate the code and have both ID's?
I'm running it like this (code below) and it seems to be ok, but for any reason could it screw up something?

Code: Select all

#F5::  ;Win+F5 is my chosen hotkey because I have it mapped to the macro mouse. Source is https://www.autohotkey.com/boards/viewtopic.php?t=15509

SoundSet, +1, MASTER, mute,2 ;For GE's dell default or 3.5mm mic it was 2, had to test by random because it wasn't 33%, it was 100%
SoundGet, master_mute, , mute, 2 ;For GE's dell or 3.5mm it was 2, had to test by random because it wasn't 33%, it was 100%
ToolTip, Mute %master_mute% ;use a tool tip at mouse pointer to show what state mic is after toggle
SetTimer, RemoveToolTip, 1000

SoundSet, +1, MASTER, mute,3 ;For Jabra usb headset it was 2, had to test by random because it wasn't 33%, it was 100%
SoundGet, master_mute, , mute, 3 ;For Jabra usb headset it was 3, had to test by random because it wasn't 
ToolTip, Mute %master_mute% 
SetTimer, RemoveToolTip, 1000

return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
Thanks for the amazing code!
Solomon
Posts: 1
Joined: 13 Jun 2020, 14:53

Re: Toggle Microphone Mute

13 Jun 2020, 15:05

Hey!

I registered an account here just to say thanks for this awesome script! You're a real life-saver.
WABDave
Posts: 1
Joined: 16 Jun 2020, 09:46

Re: Toggle Microphone Mute

16 Jun 2020, 10:02

Hello all,

Anyone having issues with these scripts and Windows 10 - 1909+ ? Does this work with bluetooth headsets?

I can't seem to get it to work with my bluetooth headset. At first I thought it may be the wrong device ID in use so I blocked them all (11 devices listed!). I can see the sound icon in the system tray "X" out and in when I hit the hotkey CapsLock.

I'm looking for a global PTT function so I don't have to rely on muting myself via various software apps (Teams, Webex, GoToMeeting, internal softphone app etc).

Also is there a temp disable option that can be potentially be also scripted, say when I want to give a presentation and not have to hold the PTT.
ch_rob
Posts: 1
Joined: 19 Jun 2020, 15:18

Re: Toggle Microphone Mute

19 Jun 2020, 15:26

Still works for me: Win 10 1909 build 18363.900

To find the Id, I run the second script, screenshot. Change the mic level. Run the second script again, compare to the screenshot. Find the level that changed... that's the id.

Note that my Id changes when I dock, undock, attach a HDMI monitor - essentially any action that changes the list of audio devices. I just have multiple SoundSet and SoundGet to cover my identified (possible) configurations...

Code: Select all

^!m::  ; Ctrl-Alt-M is my chosen hotkey

; Taken from here: https://www.autohotkey.com/boards/viewtopic.php?t=15509

;Control panel > Sound > Recording > Select headset > Properties > Levels > Change > Apply

SoundSet, +1, MASTER, mute, 12 ; 9 is my Jabra id when attached to the dock, 6 when not connected, determined by DetermineMicId.ahk... After adding Bluetooth headset, it is 12
SoundGet, master_mute12, , mute, 12

SoundSet, +1, MASTER, mute, 6 ; 9 is my Jabra id when attached to the dock, 6 when not connected, determined by DetermineMicId.ahk... 
SoundGet, master_mute6, , mute, 6

SoundSet, +1, MASTER, mute, 9 ; 9 is my Jabra id when attached to the dock, 6 when not connected, determined by DetermineMicId.ahk
SoundGet, master_mute9, , mute, 9

ToolTip, Mute Status New(12): %master_mute12% -Standalone(6): %master_mute6% - Docked(9): %master_mute9% ;use a tool tip at mouse pointer to show what state mic is after toggle
SetTimer, RemoveToolTip, 2000
return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

WABDave wrote:
16 Jun 2020, 10:02
Hello all,

Anyone having issues with these scripts and Windows 10 - 1909+ ? Does this work with bluetooth headsets?

I can't seem to get it to work with my bluetooth headset. At first I thought it may be the wrong device ID in use so I blocked them all (11 devices listed!). I can see the sound icon in the system tray "X" out and in when I hit the hotkey CapsLock.

I'm looking for a global PTT function so I don't have to rely on muting myself via various software apps (Teams, Webex, GoToMeeting, internal softphone app etc).

Also is there a temp disable option that can be potentially be also scripted, say when I want to give a presentation and not have to hold the PTT.
ajhauk
Posts: 1
Joined: 09 Jul 2020, 13:49

Re: Toggle Microphone Mute

09 Jul 2020, 14:02

Hey all,

So I ran the first script, found my mic's ID, swapped that in, and ran the script.

Tooltip shows as muted.

Before:
https gyazo.com /bee5c492e44bf88a80352099b139bf11 Broken Link for safety

After:
https gyazo.com /3ab89a5c84eab1d3bba523f9b5bff038 Broken Link for safety

The thing is my mic still picks up and records all sounds?

Can anyone please help?

Thanks!

EDIT: It's muting the microphone's speakers, not the microphone itself. I have now tried all mics listed from the first script.

Double edit: Got it, excellent script and a lifesaver, thank you!
OsquoWassen
Posts: 1
Joined: 17 Aug 2020, 06:03

Re: Toggle Microphone Mute

17 Aug 2020, 06:08

Hi, i have the exact same problem as the last guy, (Script is muting my speakers instead of mic) difference is i cant figure it out. Could someone help please?
User avatar
boardtc
Posts: 27
Joined: 12 Feb 2016, 10:13
Contact:

Re: Toggle Microphone Mute

16 Oct 2020, 05:51

Having tried MicMute on Windows 10 and being disappointed to find it flaky with Microsoft Teams I was excited to find this!
  1. Using my headset control I adjusted the volume to 78. I saved the mic id script as mic_id.ahk and double-clicked to run. After a while gathering the soundcardinfo this is what comes up:
    Image
    the mixer reads 2, I assume this is the id mentioned.
  2. I added the code, updated from 12 to 2, to the main script using hotkey CapsLock. Running a Microsoft teams call I press CapsLock and get the excellent tooltip. However, as previously reported the speakers are muted instead - Teams tells me that my speakers are muted. Doing a test call confirms this, my test call is all recorded while the mute toggle is on.
Is it working for anyone now for the mic?
Has anyone got this working with Teams?

Update: I remapped the Ctrl+Shit+M mute shortcut in Teams to the CapsLock:

Code: Select all

CapsLock::^+m	
thanks to @gregster

Return to “Scripts and Functions”

Who is online

Users browsing this forum: robmar-zl and 16 guests