Jump to content
Proton

As a script to react to a certain melody on the computer ? - (Locked)

Recommended Posts

Hello, friends.

Advise me how to get the autoit script to react on the sound on the computer for a certain tune long 2 seconds (it's a melody, not voice) ?

This file C:\Windows\Media\tada.wav

(provided of course that there are no sounds from any other processes)

But the script should not react to the launch of this file or the appearance of a window with this name, or a process with this address - namely, this sound.

How can this be done with autoit ?

(That is, apparently this sound should be stored somewhere in memory, and the script should always hang in the tray - not to miss this sound)

Share this post


Link to post
Share on other sites

my first attempt would be using _SoundStatus() - although i'm not sure if it works on sound files played by a process other than AutoIt - you'd have to try it out.

if that doesn't work, try reading through this topic:

 

Share this post


Link to post
Share on other sites

orbsI didn't mean the reaction to any sound produced by the sound card.

I mean , a reaction to a particular tune.

Share this post


Link to post
Share on other sites
Posted (edited)

This seems very tricky. I would recommend looking at what software already exists that you might be able to use. It seems possible to record the sound with audacity and take a screenshot of the audio (wave) output in the display area. Then you could trace the outline using PixelSearch() and see if the sound matches a previously identified sound recording within a predetermined margin of error. This type of compromise would only work for prerecorded sounds and would be unable to determine melodic output. Not necessarily the most reliable method and sensitivity will depend on the sound source: experimentation needed.

Edited by czardas

Share this post


Link to post
Share on other sites

czardasI found this a script that simply responds to any sound. How to configure it to respond to the sound of tada (using PixelSearch) ?

#include <GuiConstants.au3>
#include <ProgressConstants.au3>
Global Const $S_OK = 0
;===============================================================================
#interface "IMMDeviceEnumerator"
Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
; Definition
Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _
     "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _
     "GetDevice hresult(wstr;ptr*);" & _
     "RegisterEndpointNotificationCallback hresult(ptr);" & _
     "UnregisterEndpointNotificationCallback hresult(ptr);"
;===============================================================================
;===============================================================================
#interface "IMMDevice"
Global Const $sIID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
; Definition
Global Const $tagIMMDevice = "Activate hresult(clsid;dword;variant*;ptr*);" & _
     "OpenPropertyStore hresult(dword;ptr*);" & _
     "GetId hresult(ptr*);" & _
     "GetState hresult(dword*);"
;===============================================================================
;===============================================================================
#interface "IAudioMeterInformation"
Global Const $sIID_IAudioMeterInformation = "{C02216F6-8C67-4B5B-9D00-D008E73E0064}"
; Definition
Global Const $tagIAudioMeterInformation = "GetPeakValue hresult(float*);" & _
     "GetMeteringChannelCount hresult(dword*);" & _
     "GetChannelsPeakValues hresult(dword;float*);" & _
     "QueryHardwareSupport hresult(dword*);"
;===============================================================================

Global $oAudioMeterInformation = _AudioVolObject()
If Not IsObj($oAudioMeterInformation) Then Exit -1 ; Will happen on non-supported systems
Global $hGUI
Global $hControl = _MakePeakMeterInWindow($hGUI)
; Register function to periodically update the progress control
AdlibRegister("_LevelMeter", 45)

GUISetState()
While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd
AdlibUnRegister()
; Bye, bye...

Func _MakePeakMeterInWindow($hWindow)
$hWindow = GUICreate("ABC", 150, 400)
Return GUICtrlCreateProgress(20, 70, 15, 200, $PBS_VERTICAL)
EndFunc
Func _LevelMeter()
Local $iPeak
If $oAudioMeterInformation.GetPeakValue($iPeak) = $S_OK Then
     $iCurrentRead = 100 * $iPeak
     GUICtrlSetData($hControl, $iCurrentRead + 1)
     GUICtrlSetData($hControl, $iCurrentRead)
EndIf
EndFunc
Func _AudioVolObject()
; Sequences of code below are taken from the source of plugin written for AutoIt for setting master volume on Vista and above systems.
; Code was written by wraithdu in C++.
; MMDeviceEnumerator
Local $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)
If @error Then Return SetError(1, 0, 0)
Local Const $eRender = 0
Local Const $eConsole = 0
; DefaultAudioEndpoint
Local $pDefaultDevice
$oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDefaultDevice)
If Not $pDefaultDevice Then Return SetError(2, 0, 0)
; Turn that pointer into object
Local $oDefaultDevice = ObjCreateInterface($pDefaultDevice, $sIID_IMMDevice, $tagIMMDevice)
Local Const $CLSCTX_INPROC_SERVER = 0x1
; AudioMeterInformation
Local $pAudioMeterInformation
$oDefaultDevice.Activate($sIID_IAudioMeterInformation, $CLSCTX_INPROC_SERVER, 0, $pAudioMeterInformation)
If Not $pAudioMeterInformation Then Return SetError(3, 0, 0)
Return ObjCreateInterface($pAudioMeterInformation, $sIID_IAudioMeterInformation, $tagIAudioMeterInformation)
EndFunc

 

Share this post


Link to post
Share on other sites

well, that was late last night when i responded, so naturally my thinking went astray. what i meant to say is that perhaps you should consider to detect the conditions that triggered the sound, rather to the sound itself. is it a dialog appearing? is it an error message? other phenomenon that can be detected easier?

9 hours ago, Proton said:

I mean , a reaction to a particular tune.

have you tried _SoundStatus() ? it accepts a specific file name to handle. look at the help file.

Share this post


Link to post
Share on other sites
Posted (edited)

czardasWell, not a computer game, and let the film or program excel.

So it is probably the rules of the forum - not a contradiction ?

I mean ANY program that periodically produces a certain sound.

Edited by Proton

Share this post


Link to post
Share on other sites
37 minutes ago, Proton said:

czardas

 

28 minutes ago, Proton said:

czardasWell, not a computer game, and let the film or program excel.

So it is probably the rules of the forum - not a contradiction ?

I mean ANY program that periodically produces a certain sound.

It was not a computer game but "wrong enough" to edit your post and remove the information?

So what is it you are doing here exactly?

Jos

@All other, please stay out until this thread is cleared.


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

JosWhat do you mean, "what am I doing here" ?

I ask a question on the forum:

Advise me how to get the autoit script to react on the sound on the computer for a certain tune long 2 seconds (it's a melody, not voice) ?

 Is that a forbidden question to ask ?

Is he some kind of criminal ?

Share this post


Link to post
Share on other sites
Posted (edited)

No, You are working on a script and czardas tells you that you are in violation of the forum rules, which triggers you to change that post.

So you better have a pretty good explanation why I won't close this thread?

EDIT: I see you just edited it again to even cover it up more...  do you seriously think we are stupid?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

JosThen there's the explanation.

There are a lot of autoit scripts that recognize a piece of the picture on the screen.

But there are no autoit scripts that recognize a piece of melody.

However, there are a huge number of programs that recognize audio SPEECH.

It is essentially the same sound, only more complicated.

So I'm wondering why you can recognize speech, but can't recognize a regular audio file.

For this reason, I decided to write my question on the forum to find out the reason for this contradiction.

And find out how such an algorithm can be done in autoit (or impossible).

Share this post


Link to post
Share on other sites

It Still doesn't explain what you wrote that was in violation and you removed.

I am done with this topic, it will be closed and do not open another one.

Oh, and it also seems you created multiple account which is also against our forum rules, so I advice you to study them carefully as this is the last warning.

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Posted (edited)

Unfortunately you appear to have missed the Forum rules on your way in. Please read them now - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked.

See you soon with a legitimate question I hope.

The Moderation team

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...