Neeeewbie

is there a way to detect ANY sound file played?

8 posts in this topic

#1 ·  Posted (edited)

I use a program that makes a small sound when you get a notification.

 

The problem is I don't hear it :/ and you can't change what sound file it uses. I'd like to make a script that plays a much more noticeable sound when that sound is played.

 

I've been looking around and found https://www.autoitscript.com/autoit3/docs/libfunctions/_SoundStatus.htm but the problem is i can't find where that sound file is located. It might be a default window file/sound? but I just don't know.

 

is there a way to detect ANY sound file played? so I can make a log of played sound files and hunt that sucker down.

Edited by Neeeewbie

Share this post


Link to post
Share on other sites



The easy way it find the sound file and replace with yours one. At least you want to do some DSP with your sound. Or a better alternative for you need is Windows Audio Session API.

 

Saludos

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The easy way it find the sound file and replace with yours one. At least you want to do some DSP with your sound. Or a better alternative for you need is Windows Audio Session API.

 

Saludos

That's the problem. Can't find it.

 

Windows Audio Session API seems to be C++ related? I've tried coding C++ before I'm not very good at it in fact it confused the shit out of me.

 

/edit I might just have try all the default window sounds till I find it/what sounds like it? and hopes its one of them.

Edited by Neeeewbie

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I had some free time and I wrote this:

Run The code. Play some music on window media player and it will display a msgbox.

;Danyfirex 02/08/2015
#include <Array.au3>
Opt("MustDeclareVars", 1)

Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count
;~ AudioSessionState

Global Const $CLSCTX_INPROC_SERVER = 0x01
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(struct*;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(ptr);" & _
        "SetDisplayName hresult(wstr);GetIconPath hresult(ptr);" & _
        "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(ptr)" & _
        "GetSessionInstanceIdentifier hresult(ptr);" & _
        "GetProcessId hresult(dword*);IsSystemSoundsSession hresult();" & _
        "SetDuckingPreferences hresult(bool);"

HotKeySet("{ESC}", "Terminate")

Global $bExit = False

Local $pIAudioSessionEnumerator = 0
Local $oIAudioSessionEnumerator = 0
Local $pIAudioSessionManager2 = 0
Local $oIAudioSessionManager2 = 0
Local $pIAudioSessionControl2 = 0
Local $oIAudioSessionControl2 = 0
Local $pIAudioMeterInformation = 0
Local $oIAudioMeterInformation = 0
Local $pIMMDevice = 0
Local $oMMDevice = 0
Local $nSessions = 0
Local $ProcessID = 0
Local $fPeakValue = 0

Local $sProcessToDetectName = "wmplayer.exe";Check If a Process is playing something based on Peak Value > 0
MsgBox(0, "", "Play Some music on " & $sProcessToDetectName & " to be Detected", 5)

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

If Not IsObj($oMMDeviceEnumerator) Then Exit

If FAILED($oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eMultimedia, $pIMMDevice)) Then Exit


$oMMDevice = ObjCreateInterface($pIMMDevice, $sIID_IMMDevice, $sTagIMMDevice)
If Not IsObj($oMMDevice) Then Exit

If FAILED($oMMDevice.Activate(__uuidof($sIID_IAudioSessionManager2), $CLSCTX_INPROC_SERVER, 0, $pIAudioSessionManager2)) Then Exit

$oIAudioSessionManager2 = ObjCreateInterface($pIAudioSessionManager2, $sIID_IAudioSessionManager2, $sTagIAudioSessionManager2)
If Not IsObj($oIAudioSessionManager2) Then Exit






While Not $bExit
If FAILED($oIAudioSessionManager2.GetSessionEnumerator($pIAudioSessionEnumerator)) Then ContinueLoop
$oIAudioSessionEnumerator = ObjCreateInterface($pIAudioSessionEnumerator, $sIID_IAudioSessionEnumerator, $sTagIAudioSessionEnumerator)
If Not IsObj($oIAudioSessionEnumerator) Then ContinueLoop

    If FAILED($oIAudioSessionEnumerator.GetCount($nSessions)) Then ContinueLoop
    For $i = 0 To $nSessions - 1
        if SUCCEEDED($oIAudioSessionEnumerator.GetSession($i, $pIAudioSessionControl2)) Then

        $oIAudioSessionControl2 = ObjCreateInterface($pIAudioSessionControl2, $sIID_IAudioSessionControl2, $sTagIAudioSessionControl2)
        if @error Then ContinueLoop
        $oIAudioSessionControl2.GetProcessId($ProcessID)
        If $ProcessID = ProcessExists($sProcessToDetectName) Then

            $oIAudioMeterInformation = ObjCreateInterface($pIAudioSessionControl2, $sIID_IAudioMeterInformation, $sTagIAudioMeterInformation)
            if @error Then ContinueLoop
            $oIAudioSessionControl2.AddRef() ;stabilize
            $oIAudioMeterInformation.GetPeakValue($fPeakValue)
            If $fPeakValue > 0 Then
                MsgBox(0, $sProcessToDetectName, "Sound Played Detected on " & $sProcessToDetectName & @CRLF & "Bye :)")
                Exit
            EndIf

        EndIf

        $ProcessID = 0
        $oIAudioMeterInformation = 0 ;Free
        $oIAudioSessionControl2 = 0 ;Free

        EndIf
    Next
    $oIAudioSessionEnumerator=0
    Sleep(30)
WEnd


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

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

Func Terminate()
    $bExit = True
EndFunc   ;==>Terminate

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

 

Saludos

Edited by Danyfirex
1 person likes this

Share this post


Link to post
Share on other sites

And here a script to play all WAV sounds on C:

#include <Array.au3
#include <File.au3>
$handle = SplashTextOn("WAV player", " Searching all files.", 900, 100, -1, -1, 0, "", 8)
$aWAV = _FileListToArrayRec(@HomeDrive, "*.wav", 1, 1, 0, 2)
_ArrayDisplay($aWAV, "Array of WAV files")
For $i = 1 To $aWAV[0]
    ControlSetText($handle, "", "Static1", @CRLF & $i & " of " & $aWAV[0] & @CRLF & @CRLF & $aWAV[$i], 1)
    SoundPlay($aWAV[$i], 1)
    Sleep(500)
Next
ControlSetText($handle, "", "Static1", " End of WAV player ", 1)
_ArrayDisplay($aWAV, "Array of WAV files")

 


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks for the help guys!

 

but I found it in my network history :/ it's a url (www.url.com/sounds/soundname.ogg) it must download on start or for each use?

 

I think there's a way in my router maybe? I can trick it to use another URL/sound gota look into it.

 

/edit nope my router does do redirect's gota think about it more.

Edited by Neeeewbie

Share this post


Link to post
Share on other sites

you could also use Process Explorer to see what files the process opens and plays.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

     but I found it in my network history :/ it's a url (www.url.com/sounds/soundname.ogg) it must download on start or for each use?

 

I think there's a way in my router maybe? I can trick it to use another URL/sound gota look into it.

Could you reroute the URL in your HOSTS file (C:\Windows\System32\drivers\etc) and then host your own sound file?

HOSTS entry would look like this:
127.0.0.1    www.url.com

You would also need to setup a local web server, but that's not hard either, especially just for hosting your own sound file.

FYI, it would render www.url.com basically useless for that PC, so if the real URL is www.google.com, or if it's a site you want to get to all the time, it might not be the best idea...

Edited by MuffinMan
Addtl Info

Share this post


Link to post
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