Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Help me with a script(mute and unmute microphone).


  • Please log in to reply
6 replies to this topic
Vargaas
  • Members
  • 8 posts
  • Last active: Jun 30 2013 09:43 PM
  • Joined: 08 May 2013

Im playing arma with ACRE and teamspeak 3.
My Push to talk in Teamspeak is "Mousebutton 5"
And in Arma my radio button is "Caps Lock".

If i want to record while i play with my friends i must leave the microphone open, because fraps and dxtory dosent allow multiple push to talk buttons.

I got the tip to use this program to mute and unmute my microphone whenever i click my buttons (either "caps lock" or "mousebutton 5").

Basically.
When i start up the script:
Mute my microphone.

When i holding down capslock OR mousebutton 5:
unmute microphone

When i realese my capslock OR moushbutton 5:
mute microphone.


This should also work in different combinations, say W+A+"CapsLock". and so on.

is this possible to fix?

 

I also found this, but it seems outdated:
~$LControl::VA_SetMute(false,0,"Microphone")
~$LControl up::VA_SetMute(true,0,"Microphone")

~$Tab::VA_SetMute(false,0,"Microphone")
~$Tab up::VA_SetMute(true,0,"Microphone")

 



bigkevin112
  • Members
  • 22 posts
  • Last active: Jun 07 2013 04:29 AM
  • Joined: 17 Apr 2013

I found a couple scripts that should help you out. I have not tested these scrips so don't hold me to them.

 

Credit from these go to Peter Provost. His github is at https://github.com/PProvost/AutoHotKey

 

SOUNDCARD ANALYSIS AHK (Run First)

; SOUNDCARD ANALYSIS
; Use the following script to discover your soundcard's capabilities (component types and control types).
; It displays the results in a simple ListView.

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 . ":" . CurrInstance
                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

TOGGLE MIC AHK (Modify then run second)

; ToggleMic.ahk
;
; Author: Peter Provost
; Git Repo: http://github.com/PProvost/AutoHotKey
; 
; Description: Toggles the microphone on and off when mouse 
; button 4 is pressed

#NoEnv
#SingleInstance force

; MouseButton4 (XButton2 in AHK) will toggle the microphone mute
; state. Note: the mixer value (4) may need to change for your
; system. Use the SoundCardAnalysis script from the AHK docs
; for the SoundSet function to find your mixer value.
*XButton2::
	SoundSet, +1, Microphone, Mute, 4
	SoundGet, mute, Microphone, MUTE, 4

	SoundPlay, %soundfile%
	; TrayTip, ToggleMic, %soundfile%, 3
	TrayTip, ToggleMic, Microphone mute is %mute%, 3
return

Just make sure to run the soundcard analysis first to see what number your microphone is so you can put it in the Toggle Mic ahk. Also just change XButton2(Mousebutton 4) to the button you want to use. Like LControl or XButton1(Mousebutton 5)



Vargaas
  • Members
  • 8 posts
  • Last active: Jun 30 2013 09:43 PM
  • Joined: 08 May 2013

Hm. This is not working as i intended.
This toggles the mute.

Is there a simple function to make it nontoggle, so you need to keep pressing down the button to unmute?



bigkevin112
  • Members
  • 22 posts
  • Last active: Jun 07 2013 04:29 AM
  • Joined: 17 Apr 2013

I guess I miss understood. Sorry about that. No I know what your wanting. Try this code:

#SingleInstance,Force

OnExit, ExitSub
SoundSet, 1, MICROPHONE, MUTE, ##
Return

$LControl:: ;Change this for the button you want to use
    SoundSet, 0, MICROPHONE, MUTE, ##
    KeyWait, LControl ;MAKE SURE IF YOU CHANGE THE KEYBINDING BUTTON TO CHANGE THIS
    SoundSet, 1, MICROPHONE, MUTE, ##
    Return

ExitSub:
    SoundSet, 0, MICROPHONE, MUTE, ##
    ExitApp

 

I have tested this and this worked for me. Make sure to run the SOUNDCARD ANALYSIS AHK I had posted before and replace all the ## with the number for your computers mic. Also change the LControl to what ever you wanting. But make sure to change it in both places that its showing. 



Vargaas
  • Members
  • 8 posts
  • Last active: Jun 30 2013 09:43 PM
  • Joined: 08 May 2013

I guess I miss understood. Sorry about that. No I know what your wanting. Try this code:

#SingleInstance,Force

OnExit, ExitSub
SoundSet, 1, MICROPHONE, MUTE, ##
Return

$LControl:: ;Change this for the button you want to use
    SoundSet, 0, MICROPHONE, MUTE, ##
    KeyWait, LControl ;MAKE SURE IF YOU CHANGE THE KEYBINDING BUTTON TO CHANGE THIS
    SoundSet, 1, MICROPHONE, MUTE, ##
    Return

ExitSub:
    SoundSet, 0, MICROPHONE, MUTE, ##
    ExitApp

 

I have tested this and this worked for me. Make sure to run the SOUNDCARD ANALYSIS AHK I had posted before and replace all the ## with the number for your computers mic. Also change the LControl to what ever you wanting. But make sure to change it in both places that its showing. 

 

This Worked for me also! Thank you.

Now i just need to get rid of the "static noise" that appear the first two-three seconds when i activate the microphone.



bigkevin112
  • Members
  • 22 posts
  • Last active: Jun 07 2013 04:29 AM
  • Joined: 17 Apr 2013

Glad to hear it worked for you. Not sure why it is doing static noise. I don't think it was doing it for me. But hey at least it is working!! :D



Necromancer
  • Members
  • 13 posts
  • Last active: Oct 24 2014 07:01 AM
  • Joined: 10 Jul 2013

hey there, i came across this post as i was looking for the exact same thing.

only it doesn't work for me sad.png

 

SOUNDCARD ANALYSIS gives me this:

Ia3xlMm.jpg

 

what number do i need to put in exactly?

 

 

and how do i add another key that add mute/unmute the mic? the point is to have several keys that unmute/mute the mic. do i just copy-paste the code several times with different keys?

 

also, what is the key for Mousebutton 4? i tried XButton2 but when i pressed it, it didn't even register in the script.