Jump to content

Detecting Sound


 Share

Recommended Posts

Hello am trying to detect when when an addon in World of Warcraft is done. When this addon is done it will play a sound. I have searched the forum and I got the feeling that that seems tricky. So I looked up if I could detect the sound file being opened but so far my search has ended up whit no results that I could use. I was hoping some one could point me in the right direction or post an example.

http://www.autoitscript.com/autoit3/docs/functions/FileOpen.htm (Checks if the file is readable?)

http://www.autoitscript.com/forum/index.php?showtopic=42511&st=0 (Only create and delete?)

Link to comment
Share on other sites

It may not be the best way, but I heard that newer versions of windows removed the internal speaker beep code (or something)

So, you can use a system sound by doing something like

#Include <WinAPI.au3>

$path= full path to some wav file (or mp3 or whatever)

$type = _WinAPI_FindExecutable($path)

Run($type & " " & $path)

*edit*

just realized you wanted to listen for a sound, not play a sound... I believe I remember something about this in another thread, I will go look for it.

*edit*

Here is a link where someone detected a sound and had it do something

My link

However, _SoundStatus() may be enough if you know what sound file WoW is using. Then all you need to do is check for a change in a loop (theoretically)

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Reading that topic that you linked, it seems that project was using a mic to pick up if there is someone in that room and then turn on the music. This does not apply to my project as it is running in an virtual machine and it will need to pick up an specific sound.

I think that my first post is kind of misleading ill change that in a sec. What am trying to do is find out if an specific .ogg file is played. Trying to pick this up via sound card might be over complicating things it might be easier to detect when this sound file is opened. Although this is my first project whit autoit so am not sure what is easier

Edit

It seems that am unable to change the original topic the clarify and change the title

Edited by eddie4
Link to comment
Share on other sites

You might be able to use the _SoundStatus method on that ogg file then. If I'm not mistaken you could put it in a loop such as

$check=_SoundStatus(path\file.ogg)

While $check = whatever the state of _soundStatus is on an unused file

$check=_SoundStatus(path\file.ogg)

sleep(10)

wend

code

Theoretically, it should sleep until the status of the file changes, then exit the loop and perform your code.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Hmm.. interesting situation. You could try to see if the file is in use - check out _FileInUse. Or perhaps monitor the folder (I'm not sure if individual file monitoring is available..) - Folder Monitor. There is a '$FILE_NOTIFY_CHANGE_LAST_ACCESS' option, but I wouldn't know how to get all that to work, or if it really would work properly (seems to not register some events for me)

Link to comment
Share on other sites

I took the time to try the options you have suggested whit no success so far. To try and see if handle.exe from sysinternals could be of help I have been trying to see if it could detect the usage of the sound file whit no luck so far. My fear is that WoW will loaded all addon files at starting the game so detecting it from being read from disk seems small. So I guess it back to detecting what comes out of the speakers

Link to comment
Share on other sites

If you have a stand-alone mic you could point it at the speakers so when sound comes out of the speakers, it's picked up by the mic, then you know when the sound it played...

I know, that's silly. I'm going to do some tests with _soundstatus and _fileinuse and see if I can come up with anything.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

I figured out how to monitor if a file has been accessed (NTFS file system), but this will only help once the file is closed. For different games and applications I've tested this on, it works well. Some games or processes will not close a file handle until they exit (bad coding practice), which means the file's Last-Access time won't be updated until the program exits. However, for 'well-behaved' programs this should work well.

The reason we can't just monitor a Last-Access time without first altering it is due to the way NTFS works (quote below from 'How NTFS Works: Local File Systems'):

The Last Access Time on disk is not always current because NTFS looks for a one-hour interval before forcing the Last Access Time updates to disk. NTFS also delays writing the Last Access Time to disk when users or programs perform read-only operations on a file or folder, such as listing the folder’s contents or reading (but not changing) a file in the folder. If the Last Access Time is kept current on disk for read operations, all read operations become write operations, which impacts NTFS performance.

#include <Date.au3>
Local $sFile,$sLastAccess,$sNewDate,$aTemp
;~ $sFile="G:\Games\Singularity(TM)\RvGame\Movies\ravenlogo.bik"    ; doesn't seem to update until program exits
;~ $sFile="G:\Games\Prince of Persia The Forgotten Sands\Videos\Ubi_new_logo.bik"
$sFile="G:\Games\Prince of Persia\Videos\Ubi_Logo.bik"

; Subtract 1 hour from File's Last-Access Time (to workaround NTFS File System's one-hour interval updates)
$aTemp=FileGetTime($sFile,2,0)  ; Last-Access, Return as array
If @error=0 Then
    ConsoleWrite("Changing date.."&@CRLF)
    $sNewDate=_DateAdd('h',-1,$aTemp[0]&'/'&$aTemp[1]&'/'&$aTemp[2]&' '&$aTemp[3]&':'&$aTemp[4]&':'&$aTemp[5])  ; format for function
    If @error=0 Then
        $sNewDate=StringRegExpReplace($sNewDate,'[\s/:]','')    ; remove formatting and put into YYYYMMDDHHMMSS form
        ConsoleWrite("New Time:"&$sNewDate&@CRLF)
        FileSetTime($sFile,$sNewDate,2) ; finally set Last-Access Time to -1 Hour
    EndIf
EndIf
; Now grab the Last Access time and monitor for changes in it
$sLastAccess=FileGetTime($sFile,2,1)
ConsoleWrite("Base time:"&$sLastAccess&@CRLF)
Do
    Sleep(10)
Until $sLastAccess<>FileGetTime($sFile,2,1)
ConsoleWrite("Accessed!:"&FileGetTime($sFile,2,1)&@CRLF)
Beep()
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...