Sound auslesen

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

bull_2013
Posts: 5
Joined: 13 Mar 2018, 16:59

Sound auslesen

Post by bull_2013 » 21 Jan 2022, 18:24

Hi,

vielen Programmen kann man eigene Sounddateien (*.wav) zuordnen. Ich würde gerne, wenn einer dieser Sounds abgespielt wurde, eine Aktion ausführen. Z.B. das Programm in den Vordergrund holen.

Kann AKH unterschiedliche Sounds auslesen / erkennen?

Vielen Dank

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Sound auslesen

Post by BoBo » 22 Jan 2022, 18:06

Da sehe ich relativ wenig Hoffnung...
viewtopic.php?f=76&t=75153&hilit=sound+recognition
viewtopic.php?f=76&t=21350&hilit=sound+recognition
Hiermit lässt sich wohl "sound" erkennen, doch ob dies auch auf sound variations zutrifft?
viewtopic.php?p=183523#p183523

Event_System_Sound lässt darauf schließen ...
viewtopic.php?p=131838#p131838

bull_2013
Posts: 5
Joined: 13 Mar 2018, 16:59

Re: Sound auslesen

Post by bull_2013 » 23 Jan 2022, 05:31

Danke für deine Hilfe und Mühe.
Die andere und bestimmt auch einfachere Möglichkeit wäre:
Wenn Programm XY irgendeine Soundausgabe hat, mache ...

Hat jemand schon von dieser Funktion gehört?

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Sound auslesen

Post by BoBo » 23 Jan 2022, 07:09

bull_2013 wrote:
23 Jan 2022, 05:31
Danke für deine Hilfe und Mühe.
Die andere und bestimmt auch einfachere Möglichkeit wäre:
Wenn Programm XY irgendeine Soundausgabe hat, mache ...

Hat jemand schon von dieser Funktion gehört?
:think:

https://www.nch.com.au/action/misc.html#TONEDET

Vielleicht kann auch @just me (& friends) :arrow: hier einen Ansatz zur 'system sound detection' herauslesen?? :shifty: (vll falls man/frau der Anwendung einen eigenen Sound statt eines Systemsounds zuweist?)

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Sound auslesen

Post by swagfag » 23 Jan 2022, 07:40

from first principles:
  • load the sample u want to match
  • load the sample u want to match against or if ure going to be reading from a stream, buffer enough data to match the length of ur "needle" sample
  • then, if ur computer is fast enough:
    • precompute the FFT of the needle sample once at the start
    • compute the FFT of the haystack sample / compute the FFT of whatever data u currently have stored in ur buffer
    • cross-correlate both FFTs
    • if a threshold u specify is exceeded, u probably have a match
  • if ur computer isnt fast:
    • chunk the needle sample several times
    • precompute the FFT of each chunk once at the start
    • set ur buffer size to match the size of one chunk
    • compute the FFT of whatever data u currently have stored in ur buffer
    • cross-correlate the FFT of the first chunk with the FFT of the buffer
    • if a threshold u specify is exceeded, load more data into the buffer and repeat the same process with the second chunk. and so on
    • if u managed to iterate through all chunks, u probably have a match(this isnt going to be very accurate though)
of course all of this will be way too slow to do in pure ahk, so ull have to find some audio APIs and libraries for loading samples and calculating FFTs

bull_2013
Posts: 5
Joined: 13 Mar 2018, 16:59

Re: Sound auslesen

Post by bull_2013 » 02 Feb 2022, 17:27

Das scheint wirklich schwieriger umzusetzen zu sein, als gedacht.
Vll fällt mir noch eine andere Lösung ein, um die Programme in den Vordergrund zu holen. Wäre halt schön universell gewesen :-)

Danke für eure Mühe

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Sound auslesen

Post by BoBo » 03 Feb 2022, 02:03

Code: Select all

#SingleInstance Force

mmedia = "%1%"

DetectHiddenWindows, On
Process, Exist
hAHK := WinExist("ahk_pid " . ErrorLevel)

OnMessage(MM_MCINOTIFY	:= 0x03B9, "MM_MCINOTIFY")
;OnMessage(MM_MCISIGNAL	:= 0x03CB, "MM_MCISIGNAL")

DllCall("winmm\mciSendStringA", "str", "open " . mmedia . "alias mmedia type mpegvideo style overlapped shareable", "Uint", 0, "Uint", 0, "Uint", 0)
DllCall("winmm\mciSendStringA", "str", "play mmedia notify", "Uint", 0, "Uint", 0, "Uint", hAHK)

MM_MCINOTIFY(wParam, lParam)
{
/*
	MCI_NOTIFY_SUCCESSFUL = 0x1
	MCI_NOTIFY_SUPERSEDED = 0x2
	MCI_NOTIFY_ABORTED    = 0x4
	MCI_NOTIFY_FAILURE    = 0x8
*/
	DllCall("winmm\mciSendStringA", "str", "close mmedia", "Uint", 0, "Uint", 0, "Uint", 0)
	ExitApp
}

Kann mir/uns das mal jemand "übersetzen"? Ich vermute hier wird ein sound (media file) detected?? :think:

just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Sound auslesen

Post by just me » 03 Feb 2022, 04:39

Moin @BoBo,

das sieht für mich danach aus, dass das Skript vom Windows Media Player nach Abspielen des Mediums eine Nachricht erhalten will.

Post Reply

Return to “Ich brauche Hilfe”