Music related command?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Noam527
Posts: 83
Joined: 08 Aug 2016, 17:20

Music related command?

10 Aug 2016, 15:57

Is it possible to set a command (or a set of commands) to activate once a certain song has started? (by once, I mean that if it got to that command and the song didn't start yet, the script pauses until the song starts)
punchin
Posts: 439
Joined: 17 Jan 2014, 17:54

Re: Music related command?

10 Aug 2016, 16:07

I have seen a voice recognition script around here somewhere. You might be able to use part of that to detect sound and trigger events based on that.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Music related command?

10 Aug 2016, 16:13

Needs more info. What are you using to listen to music? Browser, media player, game, etc., and if it's on a browser, what website? Does it put the name in the title of the browser tab? In the future, please be more descriptive with your questions.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
Noam527
Posts: 83
Joined: 08 Aug 2016, 17:20

Re: Music related command?

10 Aug 2016, 16:16

Masonjar13 wrote:Needs more info. What are you using to listen to music? Browser, media player, game, etc., and if it's on a browser, what website? Does it put the name in the title of the browser tab? In the future, please be more descriptive with your questions.
it's a media player... it's a song downloaded on my PC, an MP3 file. The song is being played by a different application, and I want a command that can recognize when it's being played there
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Music related command?

10 Aug 2016, 16:51

If it's title, window text, or control text shows the information, that can be done without any extra, and very easily. You'll have to figure that out yourself though; use AU3_Spy, included in the AHK installation, and see what you can find.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
JoeWinograd
Posts: 2213
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Music related command?

10 Aug 2016, 17:41

It's not clear if you're trying to recognize that a song is being played by analyzing the audio stream, such as what SoundHound and Shazam do, or if you're fine with simply looking at what's in the Title bar of the media player. If the former, that's tough stuff, and I don't have a clue; if the latter, it should be relatively easy, but it will depend a bit on your media player. I use VLC, and when it's playing a song, it puts the Performer tag and the Track Name tag (with a space-hyphen-space separator) in the Title bar. In other words, when a song starts playing, the Title bar looks like this:

Bob Dylan - Forever Young - VLC media player

When the song stops playing, the Title bar becomes this:

VLC media player

So your script could have something like this:

Code: Select all

SetTitleMatchMode:=3
PerformerName:="set this variable"
TrackName:="set this variable"
SongInTitleBar:=PerformerName . " - " . TrackName . " - VLC media player"
Loop
{
  IfWinExist,%SongInTitleBar%
  {
    ; code goes here for specified song started playing
    ; for test purposes, a msgbox and break the loop
    msgbox,4160,song playing,%SongInTitleBar%
    break
  }
  Else
  {
    ; code goes here for the specified song not playing
    ; for test purposes, a msgbox with a 3-second timeout and continue the loop
    msgbox,4144,song not playing,%SongInTitleBar%,3
  }
}
Of course, the code above may need modification depending on the media player.

Regards, Joe
Noam527
Posts: 83
Joined: 08 Aug 2016, 17:20

Re: Music related command?

10 Aug 2016, 18:21

JoeWinograd wrote:It's not clear if you're trying to recognize that a song is being played by analyzing the audio stream, such as what SoundHound and Shazam do, or if you're fine with simply looking at what's in the Title bar of the media player. If the former, that's tough stuff, and I don't have a clue; if the latter, it should be relatively easy, but it will depend a bit on your media player. I use VLC, and when it's playing a song, it puts the Performer tag and the Track Name tag (with a space-hyphen-space separator) in the Title bar. In other words, when a song starts playing, the Title bar looks like this:

Bob Dylan - Forever Young - VLC media player

When the song stops playing, the Title bar becomes this:

VLC media player

So your script could have something like this:

Code: Select all

SetTitleMatchMode:=3
PerformerName:="set this variable"
TrackName:="set this variable"
SongInTitleBar:=PerformerName . " - " . TrackName . " - VLC media player"
Loop
{
  IfWinExist,%SongInTitleBar%
  {
    ; code goes here for specified song started playing
    ; for test purposes, a msgbox and break the loop
    msgbox,4160,song playing,%SongInTitleBar%
    break
  }
  Else
  {
    ; code goes here for the specified song not playing
    ; for test purposes, a msgbox with a 3-second timeout and continue the loop
    msgbox,4144,song not playing,%SongInTitleBar%,3
  }
}
Of course, the code above may need modification depending on the media player.

Regards, Joe
Thanks for taking time to answer me, but unfortunately, it was the former one...
Does it help if I know exactly which MP3 file is being played, but played through a different application?
User avatar
JoeWinograd
Posts: 2213
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Music related command?

10 Aug 2016, 19:58

Does it help if I know exactly which MP3 file is being played, but played through a different application?
I don't know. My gut tells me that you're talking about a huge effort. I'm pretty sure Shazam and SoundHound don't have APIs, but there may be an API out there that would work for you. I would research the web for a music recognition API. Here's an interesting article that discusses how Shazam works:
https://www.toptal.com/algorithms/shaza ... ecognition

Good luck on the project. Regards, Joe
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Music related command?

10 Aug 2016, 20:27

Doing some kind of sound recognition was a feature I had mentioned in some unofficial survey about how you use AHK, answering the question of what you'd like to see in it.

To my knowledge, there's no native way to identify most anything audio. You can produce audio, but that's about it. With things like ImageSearch, it would be neat to have an AudioSearch that looks through the played audio to try to identify a matching clip. Much of AHK's automation is either "senseless" or visual, though you can consider temporal a factor too (assessing how long it has been between certain checkpoints).

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], peter_ahk and 141 guests