Jump to content

Microphone sound enable / disable


Seminko
 Share

Go to solution Solved by Danyfirex,

Recommended Posts

Hey fellas,

 

I have a full ear headphones which isolate sound very well. Therefore I like to hear myself in my headphones when I'm on Mumble etc.

 

But it is getting really tedious clicking it manually. It goes like this:

 

1) Click the Speaker icon and then the SB Audigy Icon

ZlG0Fpk.jpg

 

2) Then click Levels and Mute / Unmute Microphone

BtprdYZ.jpg

 

I was able to make the script mute / unmute the mic when I have the specific window opened. But then again, it would require the script to open the settings etc etc.

Func MicMute()
    ControlClick("Reproduktory – vlastnosti", "", "[CLASS:Button; INSTANCE:14]", "left")
EndFunc
Is there a cleaner way of achieving this? Preferably without no additional windows being opened?

 

Thanks indeed

Edited by Seminko
Link to comment
Share on other sites

Hi.

I think something like this should work.

Opt("MustDeclareVars", 1)

Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count

Global Const $CLSCTX_INPROC_SERVER = 1
Global Const $DEVICE_STATE_ACTIVE = 0x00000001
Global Const $CLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $IID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $tagIMMDeviceEnumerator = _
        "EnumAudioEndpoints hresult(int;dword;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr)"

Global Const $IID_IMMDeviceCollection = "{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}"
Global Const $tagIMMDeviceCollection = "GetCount hresult(uint*);Item hresult(uint;ptr*)"

Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $tagIMMDevice = _
        "Activate hresult(struct*;dword;ptr;ptr*);" & _
        "OpenPropertyStore hresult(dword;ptr*);" & _
        "GetId hresult(wstr*);" & _
        "GetState hresult(dword*)"


Global Const $IID_IAudioEndpointVolume = "{5CDF2C82-841E-4546-9722-0CF74078229A}"
Global Const $tagIAudioEndpointVolume = _
        "RegisterControlChangeNotify hresult(ptr);" & _
        "UnregisterControlChangeNotify hresult(ptr);" & _
        "GetChannelCount hresult(uint*);" & _
        "SetMasterVolumeLevel hresult(float;ptr);" & _
        "SetMasterVolumeLevelScalar hresult(float;ptr);" & _
        "GetMasterVolumeLevel hresult(float*);" & _
        "GetMasterVolumeLevelScalar hresult(float*);" & _
        "SetChannelVolumeLevel hresult(uint;float;ptr);" & _
        "SetChannelVolumeLevelScalar hresult(uint;float;ptr);" & _
        "GetChannelVolumeLevel hresult(uint;float*);" & _
        "GetChannelVolumeLevelScalar hresult(uint;float*);" & _
        "SetMute hresult(int;ptr);" & _
        "GetMute hresult(int*);" & _
        "GetVolumeStepInfo hresult(uint*;uint*);" & _
        "VolumeStepUp hresult(ptr);" & _
        "VolumeStepDown hresult(ptr);" & _
        "QueryHardwareSupport hresult(dword*);" & _
        "GetVolumeRange hresult(float*;float*;float*)"


Local $oMMDeviceEnumerator = ObjCreateInterface($CLSID_MMDeviceEnumerator, $IID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)

Local $pDeviceCollection = 0
$oMMDeviceEnumerator.EnumAudioEndpoints($eCapture, $DEVICE_STATE_ACTIVE, $pDeviceCollection)

Local $oIMMDeviceCollection = ObjCreateInterface($pDeviceCollection, $IID_IMMDeviceCollection, $tagIMMDeviceCollection)

Local $iDeviceCount = 0
$oIMMDeviceCollection.GetCount($iDeviceCount)



Local $pDevice = 0
Local $oMMDevice = 0
Local $pEndpointVolume = 0
Local $oIAudioEndpointVolume = 0



For $i = 0 To $iDeviceCount - 1
    $oIMMDeviceCollection.Item($i, $pDevice)
    $oMMDevice = ObjCreateInterface($pDevice, $IID_IMMDevice, $tagIMMDevice)
    $oMMDevice.Activate(CLSIDFromString($IID_IAudioEndpointVolume), $CLSCTX_INPROC_SERVER, 0, $pEndpointVolume)
    $oIAudioEndpointVolume = ObjCreateInterface($pEndpointVolume, $IID_IAudioEndpointVolume, $tagIAudioEndpointVolume)
    $oIAudioEndpointVolume.SetMute(True, Null)
    $oMMDevice = 0
    $oIAudioEndpointVolume = 0
Next
$oIMMDeviceCollection = 0
$oMMDeviceEnumerator = 0

Func CLSIDFromString($sGUID)
    Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
    DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID)
    Return $tGUID
EndFunc   ;==>CLSIDFromString

this will mute all active microphone devices. I made the code but not tested with microphone(I don't have one) but it should work.

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

hi again. I change to a funtion MUTE.

just call MUTE to enable or disable.

Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count

Global Const $CLSCTX_INPROC_SERVER = 1
Global Const $DEVICE_STATE_ACTIVE = 0x00000001
Global Const $CLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $IID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $tagIMMDeviceEnumerator = _
        "EnumAudioEndpoints hresult(int;dword;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr)"

Global Const $IID_IMMDeviceCollection = "{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}"
Global Const $tagIMMDeviceCollection = "GetCount hresult(uint*);Item hresult(uint;ptr*)"

Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $tagIMMDevice = _
        "Activate hresult(struct*;dword;ptr;ptr*);" & _
        "OpenPropertyStore hresult(dword;ptr*);" & _
        "GetId hresult(wstr*);" & _
        "GetState hresult(dword*)"


Global Const $IID_IAudioEndpointVolume = "{5CDF2C82-841E-4546-9722-0CF74078229A}"
Global Const $tagIAudioEndpointVolume = _
        "RegisterControlChangeNotify hresult(ptr);" & _
        "UnregisterControlChangeNotify hresult(ptr);" & _
        "GetChannelCount hresult(uint*);" & _
        "SetMasterVolumeLevel hresult(float;ptr);" & _
        "SetMasterVolumeLevelScalar hresult(float;ptr);" & _
        "GetMasterVolumeLevel hresult(float*);" & _
        "GetMasterVolumeLevelScalar hresult(float*);" & _
        "SetChannelVolumeLevel hresult(uint;float;ptr);" & _
        "SetChannelVolumeLevelScalar hresult(uint;float;ptr);" & _
        "GetChannelVolumeLevel hresult(uint;float*);" & _
        "GetChannelVolumeLevelScalar hresult(uint;float*);" & _
        "SetMute hresult(int;ptr);" & _
        "GetMute hresult(int*);" & _
        "GetVolumeStepInfo hresult(uint*;uint*);" & _
        "VolumeStepUp hresult(ptr);" & _
        "VolumeStepDown hresult(ptr);" & _
        "QueryHardwareSupport hresult(dword*);" & _
        "GetVolumeRange hresult(float*;float*;float*)"


MUTE()

Func MUTE()
    Local $pDevice = 0
    Local $oMMDevice = 0
    Local $pEndpointVolume = 0
    Local $iStatus = 0
    Local $HRESULT = 0
    Local $bMute = False

    Local $oMMDeviceEnumerator = ObjCreateInterface($CLSID_MMDeviceEnumerator, $IID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)

    Local $pDeviceCollection = 0
    $oMMDeviceEnumerator.EnumAudioEndpoints($eCapture, $DEVICE_STATE_ACTIVE, $pDeviceCollection)

    Local $oIMMDeviceCollection = ObjCreateInterface($pDeviceCollection, $IID_IMMDeviceCollection, $tagIMMDeviceCollection)

    Local $iDeviceCount = 0
    $oIMMDeviceCollection.GetCount($iDeviceCount)

    For $i = 0 To $iDeviceCount - 1
        $oIMMDeviceCollection.Item($i, $pDevice)
        $oMMDevice = ObjCreateInterface($pDevice, $IID_IMMDevice, $tagIMMDevice)
        $oMMDevice.Activate(__uuidof($IID_IAudioEndpointVolume), $CLSCTX_INPROC_SERVER, 0, $pEndpointVolume)
        $oIAudioEndpointVolume = ObjCreateInterface($pEndpointVolume, $IID_IAudioEndpointVolume, $tagIAudioEndpointVolume)
        $oIAudioEndpointVolume.GetMute($bMute)
        $oIAudioEndpointVolume.SetMute(Not($bMute), Null)
        $oMMDevice = 0
        $oIAudioEndpointVolume = 0
    Next
    $oIMMDeviceCollection = 0
    $oMMDeviceEnumerator = 0

EndFunc   ;==>MUTE

Func __uuidof($sGUID)
    Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
    DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID)
    If @error Then Return SetError(@error, @extended, 0)
    Return $tGUID
EndFunc   ;==>__uuidof

Saludos

Link to comment
Share on other sites

Hello Danyfirex,

the script works correctly but is not exactly what I need.

Your script mutes the microphone, which means that ppl don't hear me when I talk.

What I actually need is a script that would disable the microphone feed into my headphones. Which is explained above.

So the microphone does not have to be turned off, just muted as shown in the second screen.

Is that something you could update the script with?

THanks indeed!

Edited by Seminko
Link to comment
Share on other sites

Hello Danyfirex,

the script works correctly but is not exactly what I need.

Your script mutes the microphone, which means that ppl don't hear me when I talk.

What I actually need is a script that would disable the microphone feed into my headphones. Which is explained above.

So the microphone does not have to be turned off, just muted as shown in the second screen.

Is that something you could update the script with?

THanks indeed!

I don't get what you mean.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Let me explain with ... AN IMAGE :)
 

This is a usual set up:

28vY4PZ.jpg

My setup:

dw3lHwS.jpg

As you can see, the speech is going OUT to the other listeners BUT ALSO it is being fed into my headphones - this set up is used by pilots for example, because the noise is so loud they would not be able to hear themselves and would be inclined to shouting. As the headphones in the image isolate sound very well I have the same inclination and therefore have it set up so the sound goes out to the listeners, which Danyfirex's script cuts out, but it also feeds into my headphones and this is what I wanna cut out as there is no point of having it enabled when I am not on Mumble, Skype etc.

Thanks

Link to comment
Share on other sites

When you click in that  does  it work?
BtprdYZ.jpg

Becouse my code does same as if you click there.

Saludos

Link to comment
Share on other sites

When I click it manually it works obviously ;).

But with your script it doesn't, unfortunately as the option above is for Speaker settings not for Recording settings. So everything you see there is the INPUT to the speakers.

EDIT:

Your script mutes this which are the Recording settings so the OUTPUT of the microphone is muted. But even though the output gets muted the INPUT to the speakers is still enabled.

fhtTqG7.jpg

Edited by Seminko
Link to comment
Share on other sites

try this:

Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count

Global Const $CLSCTX_INPROC_SERVER = 1
Global Const $DEVICE_STATE_ACTIVE = 0x00000001
Global Const $CLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $IID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $tagIMMDeviceEnumerator = _
        "EnumAudioEndpoints hresult(int;dword;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr)"

Global Const $IID_IMMDeviceCollection = "{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}"
Global Const $tagIMMDeviceCollection = "GetCount hresult(uint*);Item hresult(uint;ptr*)"

Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $tagIMMDevice = _
        "Activate hresult(struct*;dword;ptr;ptr*);" & _
        "OpenPropertyStore hresult(dword;ptr*);" & _
        "GetId hresult(wstr*);" & _
        "GetState hresult(dword*)"


Global Const $IID_IAudioEndpointVolume = "{5CDF2C82-841E-4546-9722-0CF74078229A}"
Global Const $tagIAudioEndpointVolume = _
        "RegisterControlChangeNotify hresult(ptr);" & _
        "UnregisterControlChangeNotify hresult(ptr);" & _
        "GetChannelCount hresult(uint*);" & _
        "SetMasterVolumeLevel hresult(float;ptr);" & _
        "SetMasterVolumeLevelScalar hresult(float;ptr);" & _
        "GetMasterVolumeLevel hresult(float*);" & _
        "GetMasterVolumeLevelScalar hresult(float*);" & _
        "SetChannelVolumeLevel hresult(uint;float;ptr);" & _
        "SetChannelVolumeLevelScalar hresult(uint;float;ptr);" & _
        "GetChannelVolumeLevel hresult(uint;float*);" & _
        "GetChannelVolumeLevelScalar hresult(uint;float*);" & _
        "SetMute hresult(int;ptr);" & _
        "GetMute hresult(int*);" & _
        "GetVolumeStepInfo hresult(uint*;uint*);" & _
        "VolumeStepUp hresult(ptr);" & _
        "VolumeStepDown hresult(ptr);" & _
        "QueryHardwareSupport hresult(dword*);" & _
        "GetVolumeRange hresult(float*;float*;float*)"


MUTE()

Func MUTE()
    Local $pDevice = 0
    Local $oMMDevice = 0
    Local $pEndpointVolume = 0
    Local $iStatus = 0
    Local $HRESULT = 0
    Local $bMute = False

    Local $oMMDeviceEnumerator = ObjCreateInterface($CLSID_MMDeviceEnumerator, $IID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)

    Local $pDeviceCollection = 0
    $oMMDeviceEnumerator.EnumAudioEndpoints($eCapture, $DEVICE_STATE_ACTIVE, $pDeviceCollection)

    Local $oIMMDeviceCollection = ObjCreateInterface($pDeviceCollection, $IID_IMMDeviceCollection, $tagIMMDeviceCollection)

    Local $iDeviceCount = 0
    $oIMMDeviceCollection.GetCount($iDeviceCount)

    For $i = 0 To $iDeviceCount - 1
        $oIMMDeviceCollection.Item($i, $pDevice)
        $oMMDevice = ObjCreateInterface($pDevice, $IID_IMMDevice, $tagIMMDevice)
        $oMMDevice.Activate(__uuidof($IID_IAudioEndpointVolume), $CLSCTX_INPROC_SERVER, 0, $pEndpointVolume)
        $oIAudioEndpointVolume = ObjCreateInterface($pEndpointVolume, $IID_IAudioEndpointVolume, $tagIAudioEndpointVolume)
        if  $i=3 then
$oIAudioEndpointVolume.GetMute($bMute)
        $oIAudioEndpointVolume.SetMute(Not($bMute), Null)
endif
        $oMMDevice = 0
        $oIAudioEndpointVolume = 0
    Next
    $oIMMDeviceCollection = 0
    $oMMDeviceEnumerator = 0

EndFunc   ;==>MUTE

Func __uuidof($sGUID)
    Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
    DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID)
    If @error Then Return SetError(@error, @extended, 0)
    Return $tGUID
EndFunc   ;==>__uuidof

saludos

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

  • Solution

Hi again.

I made another mute function.

when you call the funtion it exchange the microphone state.

Opt("MustDeclareVars", 1)

Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count
Global Enum $eConsole, $eMultimedia, $eCommunications, $ERole_enum_count
Global Const $CLSCTX_INPROC_SERVER = 1
Global Const $E_NOTFOUND = 0x80070490
Global Const $S_OK = 0

Global Const $CLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $IID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $tagIMMDeviceEnumerator = _
        "EnumAudioEndpoints hresult(int;dword;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr)"


Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $tagIMMDevice = _
        "Activate hresult(struct*;dword;ptr;ptr*);" & _
        "OpenPropertyStore hresult(dword;ptr*);" & _
        "GetId hresult(wstr*);" & _
        "GetState hresult(dword*)"


Global Const $IID_IDeviceTopology = "{2A07407E-6497-4A18-9787-32F79BD0D98F}"
Global Const $tagIDeviceTopology = "GetConnectorCount hresult(int*);GetConnector hresult(int;ptr*);" & _
        "GetSubunitCount hresult(int*);GetSubunit hresult(int;ptr*);GetPartById hresult(int,ptr*);GetDeviceId hresult(ptr*);GetSignalPath hresult(ptr;ptr;bool;ptr*)"


Global Const $IID_IConnector = "{9c2c4058-23f5-41de-877a-df3af236a09e}"
Global Const $tagIConnector = "GetType hresult(ptr*);GetDataFlow hresult(ptr*);ConnectTo hresult(ptr);Disconnect hresult(none);IsConnected hresult(int*);" & _
        "GetConnectedTo hresult(ptr*);GetConnectorIdConnectedTo hresult(wstr*);GetDeviceIdConnectedTo hresult(wstr*)"


Global Const $IID_IPart = "{AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9}"
Global Const $tagIPart = "GetName hresult(wstr*);GetLocalId hresult(uint*);GetGlobalId hresult(wstr*);GetPartType hresult(ptr);GetSubType hresult(ptr);" & _
        "GetControlInterfaceCount hresult(uint*);GetControlInterface hresult(int;ptr*);EnumPartsIncoming hresult(ptr*);EnumPartsOutgoing hresult(ptr*);" & _
        "GetTopologyObject hresult(ptr*);Activate hresult(dword;struct*;ptr*);RegisterControlChangeCallback hresult(ptr);UnregisterControlChangeCallback hresult(ptr)"

Global Const $IID_IPartsList = "{6DAA848C-5EB0-45CC-AEA5-998A2CDA1FFB}"
Global Const $tagIPartsList = "GetCount hresult(uint*);GetPart hreuslt(uint;ptr*)"

Global Const $IID_IAudioMute = "{DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E}"
Global Const $tagIAudioMute = "SetMute hresult(bool;ptr);GetMute hresult(int*)"

MUTE()

Func MUTE()
Local $hr = -1

Local $oMMDeviceEnumerator = ObjCreateInterface($CLSID_MMDeviceEnumerator, $IID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)
If @error Then
    ConsoleWrite("!Error Creating IMMDeviceEnumerator Interface" & @CRLF)
    Exit
EndIf

Local $pDevice = 0
$hr = $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDevice)

If FAILED($hr) Then
    ConsoleWrite("!Error Getting Default Render Endpoint Device" & @CRLF)
    $oMMDeviceEnumerator = 0
    Exit
EndIf


Local $oMMDevice = ObjCreateInterface($pDevice, $IID_IMMDevice, $tagIMMDevice)
If @error Then
    ConsoleWrite("!Error Creating IMMDevice Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    Exit
EndIf


Local $pDeviceTopology = 0
$hr = $oMMDevice.Activate(__uuidof($IID_IDeviceTopology), $CLSCTX_INPROC_SERVER, 0, $pDeviceTopology)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting Device Topology" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    Exit
EndIf

Local $oDeviceTopology = ObjCreateInterface($pDeviceTopology, $IID_IDeviceTopology, $tagIDeviceTopology)

If @error Then
    ConsoleWrite("!Error Creating IDeviceTopology Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    Exit
EndIf


Local $pConnEndpoint = 0
$hr = $oDeviceTopology.GetConnector(0, $pConnEndpoint)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting endpoint Connector" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $oIConnector = ObjCreateInterface($pConnEndpoint, $IID_IConnector, $tagIConnector)
If @error Then
    ConsoleWrite("!Error Creating IConnector Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $pConnDevice = 0
$hr = $oIConnector.GetConnectedTo($pConnDevice)
If FAILED($hr) Then
    ConsoleWrite("!Error GetConnectedTo Device" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $oConnDevice = ObjCreateInterface($pConnDevice, $IID_IConnector, $tagIConnector)

If @error Then
    ConsoleWrite("!Error Creation oConnDevice(IConnector) Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $pPart = 0
$hr = $oConnDevice.QueryInterface($IID_IPart, $pPart)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting Part" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    $oConnDevice = 0
    Exit
EndIf

Local $oIPart = ObjCreateInterface($pPart, $IID_IPart, $tagIPart)
If @error Then
    ConsoleWrite("!Error Creating IPart Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


ConsoleWrite(">>>>>>>>>>>>>>>>>BEGIN<<<<<<<<<<<<<<<<<<<<" & @CRLF)
GetPart($oIPart)
$oIPart = 0
EndFunc

Func GetPart(ByRef $oIPart)
    Local $sPartName = ""
    Local $PartLocalId = ""
    Local $hr = -1
    ConsoleWrite("+Part" & @CRLF)

    $hr = $oIPart.GetName($sPartName)
    If FAILED($hr) Then
        ConsoleWrite("Not Part Name" & @CRLF)
        Return $hr
    EndIf

    $oIPart.GetLocalId($PartLocalId)
    If FAILED($hr) Then
        ConsoleWrite("Not Part ID" & @CRLF)
        Return $hr
    EndIf

    ConsoleWrite(">" & $sPartName)
    ConsoleWrite(" ID: " & $PartLocalId & @CRLF)

    If StringInStr($sPartName, "mic") Then
        Local $pIAudioMute = 0
        Local $bMute = 0
        Local $oIAudioMute = 0
        $hr = $oIPart.Activate($CLSCTX_INPROC_SERVER, __uuidof($IID_IAudioMute), $pIAudioMute)
        If SUCCEEDED($hr) Then
            $oIAudioMute = ObjCreateInterface($pIAudioMute, $IID_IAudioMute, $tagIAudioMute)
            If @error Then
                ConsoleWrite("!Error Creating IAudioMute Interface")
            EndIf
            $hr = $oIAudioMute.GetMute($bMute)
            If FAILED($hr) Then
                ConsoleWrite("!Error Getting Mute State" & @CRLF)
            EndIf
            $hr = $oIAudioMute.SetMute(Not ($bMute), Null)
            If SUCCEEDED($hr) Then
                ConsoleWrite("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!") & @CRLF)
                TrayTip("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!"), "Danyfirex", 2, 1)
                Sleep(2000)
            EndIf
        EndIf
    EndIf

    Local $pIncomingParts = 0
    $hr = $oIPart.EnumPartsIncoming($pIncomingParts)
    If ($hr = $E_NOTFOUND) Then
        ConsoleWrite("Not incoming Parts in Part" & @CRLF)
        Return $S_OK
    EndIf

    If FAILED($hr) Then
        ConsoleWrite("!ERROR Enumerating incoming Parts" & @CRLF)
        Return $hr
    EndIf

    Local $oIPartsList = ObjCreateInterface($pIncomingParts, $IID_IPartsList, $tagIPartsList)
    If @error Then
        ConsoleWrite("!Error Creating IPartsList Interface")
    EndIf

    Local $iNParts = 0
    $oIPartsList.GetCount($iNParts)

    If FAILED($hr) Then
        ConsoleWrite("Couldn't get count of incoming parts")
        Return $hr
    EndIf

    Local $pIncomingPart = 0
    Local $oIPart2 = 0
    For $i = 0 To $iNParts - 1
        $hr = $oIPartsList.GetPart($i, $pIncomingPart)
        If (FAILED($hr)) Then
            ConsoleWrite("Not Got Part" & @CRLF)
            $oIPartsList = 0
            Return $hr
        EndIf
        Local $oIPart2 = ObjCreateInterface($pIncomingPart, $IID_IPart, $tagIPart)
        If @error Then
            ConsoleWrite("!Error Creating IPartsList(2) Interface")
            $oIPartsList = 0
            Return $hr
        EndIf

        $hr = GetPart($oIPart2)
        If FAILED($hr) Then
            $oIPartsList = 0
            $oIPart2 = 0
            Return $hr
        EndIf
    Next
    $oIPart2=0
    Return $S_OK
EndFunc   ;==>GetPart



Func __uuidof($sGUID)
    Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
    DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID)
    If @error Then Return SetError(@error, @extended, 0)
    Return $tGUID
EndFunc   ;==>__uuidof

Func SUCCEEDED($hr)
    Return ($hr >= 0)
EndFunc   ;==>SUCCEEDED

Func FAILED($hr)
    Return ($hr < 0)
EndFunc   ;==>FAILED

Tell me if it works correctly.

it show a tooltip when mute on and mute off the microphone. Disable it if you want.

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

@JohnOne

I did not understand your message :S lol

@Seminko

I glad to help you. Not needed to repay  :)

 

Saludos

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...