Jump to content

need help with sounds


Recommended Posts

Hello, i need something that could be getting beeps of the window volumen in a loop. (I dont know  exactly whats that).

Example

When its at 20% of the bar, as the image it will send an alert.

Screenshot_7.png.22eb7f553dc3bcc87c7f16fa09779bb9.png

(This bar changes depending the people talking) but i dont want input, i want output all noise.

I hope you can help me :)

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

55 minutes ago, Nine said:

Sigh...  Search did not work ?

You will need to get peak value, like in this example :

Replace eCapture by eRender and mix codes with previous example.

#include <WinAPICom.au3>
#include <Process.au3>
#include <Array.au3>


Opt("MustDeclareVars", 1)

Global Const $CLSCTX_INPROC_SERVER = 0x01 + 0x02 + 0x04 + 0x10
Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count
Global Enum $AudioSessionStateInactive, $AudioSessionStateActive, $AudioSessionStateExpired
Global Const $eMultimedia = 1


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


Global Const $sIID_IAudioMeterInformation = "{C02216F6-8C67-4B5B-9D00-D008E73E0064}"
Global Const $sTagIAudioMeterInformation = "GetPeakValue hresult(float*);" & _
        "GetMeteringChannelCount hresult(dword*);" & _
        "GetChannelsPeakValues hresult(dword;float*);" & _
        "QueryHardwareSupport hresult(dword*);"


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


Global Const $sIID_IAudioSessionManager2 = "{77aa99a0-1bd6-484f-8bc7-2c654c9a9b6f}"
Global Const $sTagIAudioSessionManager = "GetAudioSessionControl hresult(ptr;dword;ptr*);" & _
        "GetSimpleAudioVolume hresult(ptr;dword;ptr*);"
Global Const $sTagIAudioSessionManager2 = $sTagIAudioSessionManager & "GetSessionEnumerator hresult(ptr*);" & _
        "RegisterSessionNotification hresult(ptr);" & _
        "UnregisterSessionNotification hresult(ptr);" & _
        "RegisterDuckNotification hresult(wstr;ptr);" & _
        "UnregisterDuckNotification hresult(ptr)"


Global Const $sIID_IAudioSessionEnumerator = "{e2f5bb11-0570-40ca-acdd-3aa01277dee8}"
Global Const $sTagIAudioSessionEnumerator = "GetCount hresult(int*);GetSession hresult(int;ptr*)"

Global Const $sIID_IAudioSessionControl = "{f4b1a599-7266-4319-a8ca-e70acb11e8cd}"
Global Const $sTagIAudioSessionControl = "GetState hresult(int*);GetDisplayName hresult(wstr*);" & _
        "SetDisplayName hresult(wstr);GetIconPath hresult(wstr*);" & _
        "SetIconPath hresult(wstr;ptr);GetGroupingParam hresult(ptr*);" & _
        "SetGroupingParam hresult(ptr;ptr);RegisterAudioSessionNotification hresult(ptr);" & _
        "UnregisterAudioSessionNotification hresult(ptr);"


Global Const $sIID_IAudioSessionControl2 = "{bfb7ff88-7239-4fc9-8fa2-07c950be9c6d}"
Global Const $sTagIAudioSessionControl2 = $sTagIAudioSessionControl & "GetSessionIdentifier hresult(wstr*);" & _
        "GetSessionInstanceIdentifier hresult(wstr*);" & _
        "GetProcessId hresult(dword*);IsSystemSoundsSession hresult();" & _
        "SetDuckingPreferences hresult(bool);"

Global $g_bExit = Not False
Global $g_bIsRunning = False

;Program To start and Program to Close
Global $_gAppToRun = "notepad.exe"
Global $g_AppToFinish = "notepad.exe"



HotKeySet("{ESC}", "_Exit")
_WinAPI_CoInitialize()
Local $aApp = 0
While $g_bExit
    $aApp = _GetAppsPlayingSound()
    _RunCloseAppIfSoundPlayingByProcessName("chrome.exe",$aApp)
    Sleep(100)
WEnd
_WinAPI_CoUninitialize()


Func _RunCloseAppIfSoundPlayingByProcessName($sProcessName, $aApp)
    If Not $g_bIsRunning Then
        If _ArraySearch($aApp, $sProcessName)>-1 Then
            ShellExecute($_gAppToRun)
            $g_bIsRunning = True
        EndIf
    EndIf

    If $g_bIsRunning Then
        If _ArraySearch($aApp, $sProcessName)=-1 Then
            ProcessClose($g_AppToFinish)
            $g_bIsRunning = False
        EndIf
    EndIf

EndFunc   ;==>_RunCloseAppIfSoundPlayingByProcessName





Func _Exit()
    $g_bExit = False
EndFunc   ;==>_Exit


Func _GetAppsPlayingSound()

    Local $pIMMDevice = 0
    Local $oMMDevice = 0
    Local $pIAudioSessionManager2 = 0
    Local $oIAudioSessionManager2 = 0
    Local $pIAudioSessionEnumerator = 0
    Local $oIAudioSessionEnumerator = 0
    Local $nSessions = 0
    Local $oMMDeviceEnumerator = 0
    Local $aApp[0]
    Local $pIAudioSessionControl2 = 0
    Local $oIAudioSessionControl2 = 0
    Local $oIAudioMeterInformation = 0
    Local $ProcessID = 0
    Local $fPeakValue = 0
    Local $iState = 0
    Local $iVolume = 0
    Local $oErrorHandler = 0

    $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")


    $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $sTagIMMDeviceEnumerator)

    If @error Then Return $aApp

    If SUCCEEDED($oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eMultimedia, $pIMMDevice)) Then ;eRender


        $oMMDevice = ObjCreateInterface($pIMMDevice, $sIID_IMMDevice, $sTagIMMDevice)

        $oMMDevice.Activate($sIID_IAudioSessionManager2, $CLSCTX_INPROC_SERVER, 0, $pIAudioSessionManager2)

        $oIAudioSessionManager2 = ObjCreateInterface($pIAudioSessionManager2, $sIID_IAudioSessionManager2, $sTagIAudioSessionManager2)

        $oIAudioSessionManager2.GetSessionEnumerator($pIAudioSessionEnumerator)

        $oIAudioSessionEnumerator = ObjCreateInterface($pIAudioSessionEnumerator, $sIID_IAudioSessionEnumerator, $sTagIAudioSessionEnumerator)

        $oIAudioSessionEnumerator.GetCount($nSessions)


        For $i = 0 To $nSessions - 1
            $oIAudioSessionEnumerator.GetSession($i, $pIAudioSessionControl2)
            $oIAudioSessionControl2 = ObjCreateInterface($pIAudioSessionControl2, $sIID_IAudioSessionControl2, $sTagIAudioSessionControl2)
            $oIAudioSessionControl2.GetState($iState)
            If $iState = $AudioSessionStateActive Then
                $oIAudioSessionControl2.GetProcessId($ProcessID)
                $oIAudioMeterInformation = ObjCreateInterface($pIAudioSessionControl2, $sIID_IAudioMeterInformation, $sTagIAudioMeterInformation)
                $oIAudioSessionControl2.AddRef
                $oIAudioMeterInformation.GetPeakValue($fPeakValue)
                If $fPeakValue > 0 Then
                    ReDim $aApp[UBound($aApp) + 1][2]
                    $aApp[UBound($aApp) - 1][0] = _ProcessGetName($ProcessID)
                    $aApp[UBound($aApp) - 1][1] = $fPeakValue
                EndIf

            EndIf
            $fPeakValue = 0
            $iState = 0
            $ProcessID = 0
            $oIAudioMeterInformation = 0
            $oIAudioSessionControl2 = 0

        Next
        $oIAudioSessionEnumerator = 0
        $oIAudioSessionManager2 = 0
        $oMMDevice = 0
        $oMMDeviceEnumerator = 0

        If UBound($aApp) = 0 Then $aApp = 0
        Return $aApp
    Else
        Return $aApp
    EndIf


EndFunc   ;==>_GetAppsPlayingSound




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

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

This detect the sounds as i need, do you know how make it to return % as music changes?

Link to comment
Share on other sites

11 hours ago, Nine said:

See my last post.  You need to call getPeakValue in a loop (in my case, it is an adlibregister).  Multiply by 100.

Please if you could make the modification would be amazing, i have hours and hours searching and trying and i cant get it :(

Link to comment
Share on other sites

@Nine has provided you a gem of a script.  You are encouraged to take the time to make the modifications yourself, once you understand what you need to do.

In the meantime, here is an absolutely crappy script, that may work for you, if you are lucky.  It's based on code I wrote as a test a while ago.  I have since moved to Nine's way of monitoring audio, as you should when you are ready.

A few tips on using it,

1) Before running the script, have your Volume Mixer launched and positioned where it wont be obscured and then don't move it!

2) When calibrating, make sure and position mouse over a dark green pixel at the bottom of the meter, but DON'T click or do anything to lose focus of the MsgBox.

3) If you want to recalibrate it or quit, press ctrl-l as in "level"

4) Replace the ToolTip line with whatever alert and threshold you want.

5) Accuracy can be affected by the level control obscuring the level reading, not by too much though.

6) Odds are about 50/50 it works for you, so don't spend too much time on it if it doesn't.  It still works on my machine.

7) If you redistribute this code, please do NOT credit me.

😎 Good Luck!

Global $ga_CalXY, $ga_SampXY, $gi_SampColor
HotKeySet("^l", "CalibrateSampler")
If @OSVersion = 'WIN_10' Then DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext" , "HWND", "DPI_AWARENESS_CONTEXT" -2)
If @OSVersion = 'WIN_81' Then DllCall("User32.dll", "bool", "SetProcessDPIAware")

CalibrateSampler()

While Sleep(300)
   $ga_SampXY=PixelSearch($ga_CalXY[0], $ga_CalXY[1]-115, $ga_CalXY[0], $ga_CalXY[1], $gi_SampColor, 100)
   If Not @error Then
      $gi_pct=Round(($ga_CalXY[1]-$ga_SampXY[1])/115*100)
      If $gi_pct >= 20 Then ToolTip($gi_pct & "%")
   EndIf
WEnd

Func CalibrateSampler()
   WinActivate("[TITLE:Volume Mixer]","")
   If MsgBox(1,"To Calibrate", "Position Mouse (But Don't Click) Over Lowest Dark Green Pixel of Audio Meter to Sample Then Hit Enter") = 2 Then Exit
   $ga_Calxy=MouseGetPos()
   $gi_SampColor=PixelGetColor($ga_CalXY[0], $ga_CalXY[1])
EndFunc

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

6 hours ago, JockoDundee said:

@Nine has provided you a gem of a script.  You are encouraged to take the time to make the modifications yourself, once you understand what you need to do.

In the meantime, here is an absolutely crappy script, that may work for you, if you are lucky.  It's based on code I wrote as a test a while ago.  I have since moved to Nine's way of monitoring audio, as you should when you are ready.

A few tips on using it,

1) Before running the script, have your Volume Mixer launched and positioned where it wont be obscured and then don't move it!

2) When calibrating, make sure and position mouse over a dark green pixel at the bottom of the meter, but DON'T click or do anything to lose focus of the MsgBox.

3) If you want to recalibrate it or quit, press ctrl-l as in "level"

4) Replace the ToolTip line with whatever alert and threshold you want.

5) Accuracy can be affected by the level control obscuring the level reading, not by too much though.

6) Odds are about 50/50 it works for you, so don't spend too much time on it if it doesn't.  It still works on my machine.

7) If you redistribute this code, please do NOT credit me.

😎 Good Luck!

 

use a pixelsearch its really good idea for a noob like me!  it wont be an exact value but it will work.

im going to create my own function for that. Thank you.

Link to comment
Share on other sites

14 minutes ago, rednaxela said:

use a pixelsearch its really good idea for a noob like me!

pixelsearch is the last refuge of a scoundrel.

16 minutes ago, rednaxela said:

im going to create my own function for that

make sure you post it.

Code hard, but don’t hard code...

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...