Author Topic: Playing sound on command recognition  (Read 5700 times)

mikethelab

  • Newbie
  • *
  • Posts: 4
Playing sound on command recognition
« on: January 02, 2021, 02:30:17 PM »
As the title suggests, I think it would be nice to have a little sound effect play every time a command is recognised and for longer commands (like a keypress for 5 seconds) to have that same sound effect after the command is resolved.

I understand that you can add a play sound command at any point of a macro, but this can be quite tedious to set up across all macros in all profiles. It would be nice if there was a checkbox to play a default sound for this sort of situation, just like when VoiceAttack starts or stops "listening" to commands in the first place.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Playing sound on command recognition
« Reply #1 on: January 02, 2021, 02:57:03 PM »
While not as practical as a built-in option, you can try the attached command.

It needs to be executed once, after which it will remain functional until all commands are stopped (which also occurs when switching or reloading profiles), so if you want it to start automatically you'd want to set it up to be executed by the "Execute a command each time this profile is loaded" option, either directly, or using an "Execute Another Command" action within your existing initialization command.

Note that it has not been tested with more than 1000 command executions within the same session (I.E. since the VoiceAttack application was started), though that should theoretically work.

mikethelab

  • Newbie
  • *
  • Posts: 4
Re: Playing sound on command recognition
« Reply #2 on: January 03, 2021, 11:17:52 AM »
This certainly helped a bit so I appreciate it :) However sometimes it doesn't work or only works after being triggered 2-3 times. I'm not a programmer so I have no idea how or why ^^

I think I'll just use the old method until it becomes a built-in feature :) Huge thanks for help though!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Playing sound on command recognition
« Reply #3 on: January 03, 2021, 01:43:04 PM »
It works reliably on my machine.

As long as the command is started initially, it should work whenever VA.Command.ExecutionCount() is incremented, and the entry is added to the VA.Command.SpokenHistory() list

Note that this applies to recognized spoken commands only; Anything else is ignored.

You could try disabling the "Ignore an Unrecognized Word or Phrase" action at the top of the command, to check whether the command is getting executed by the inline function, even if the sound isn't playing

mikethelab

  • Newbie
  • *
  • Posts: 4
Re: Playing sound on command recognition
« Reply #4 on: April 30, 2021, 10:13:30 AM »
Hi there.

I know it's been quite a while, but I ran into an issue recently and I was wondering if there is something that could be done about it. Just like you were saying, it wasn't tested to handle more than a 1000 commands and once that number is reached, the whole VA goes haywire, playing the sound on loop and button mashing the last spoken command which often leads to slowing down my PC until I force close VA in the task manager. Is there any chance we could up that number from 1000 to like 100000 commands? Or maybe find a different solution altogether since it's been a while :) I need to use a ton of commands in certain games (especially racing ones) so a 1000 and reset every time doesn't really work well in my situation.

Cheers!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Playing sound on command recognition
« Reply #5 on: April 30, 2021, 07:42:10 PM »
Try inserting a "break" statement in the for loop:
Code: [Select]
//If the previous list of spoken commands does not match the current list, another command phrase must have been spoken and recognized
for (int i = 0; i < spokenHistory.Count; i++)
{
if (spokenHistory[i] != previousSpokenHistory[i])
{
//VA.WriteToLog("New spoken command detected by compare");
VA.Command.Execute("Command Recognition Beep");
break;
}
}

As it's going through the list newest to oldest, what is currently happening is that it encounters a mismatched item, and correctly plays the beep, but instead of stopping when it's found the first mismatch, it just keeps going down all remaining 999 items in the list, playing another beep for each mismatch.

The "break" statement should make it stop after the first mismatch.

mikethelab

  • Newbie
  • *
  • Posts: 4
Re: Playing sound on command recognition
« Reply #6 on: April 30, 2021, 08:49:51 PM »
Thank you so much! I'll be sure to let you know if something breaks again :)

guimcast

  • Newbie
  • *
  • Posts: 2
Re: Playing sound on command recognition
« Reply #7 on: June 03, 2023, 01:37:48 PM »
I think this command is not working anymore :(

Any workarounds?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Playing sound on command recognition
« Reply #8 on: June 03, 2023, 01:41:16 PM »
The "Execute a command each time a command phrase is recognized" option was added with v1.10, so this is pretty much wholly redundant.

You can instead assign a command to that profile-level option, containing a "Play a Sound" or "Play a Random Sound" action.

guimcast

  • Newbie
  • *
  • Posts: 2
Re: Playing sound on command recognition
« Reply #9 on: June 03, 2023, 04:11:01 PM »
Thank you for replying so fast! Indeed your file works, my mistake.

unfortunately after trying for a few hours, only my unrecognized sound works. Thats why ive been trying to use yours, but i cant because of a "reset active profile" command i have that makes VA run in a loop when i put both commands on "execute command on profile loading".

I'm probably doing something wrong, but even when i put the same command from "unrecogonized phrase" on "recognized phrase", but it only plays the sound when phrase is unrecognized...

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Playing sound on command recognition
« Reply #10 on: June 04, 2023, 12:45:12 AM »
I'll try to clarify: the command I posted in this topic is no longer needed to have a sound play each time a command is recognized, assuming you are running VoiceAttack v1.10 or later (v1.10.4 is the latest version at the time of writing)

You can delete the command from your profile.


After removing the old command, create a new command that simply contains either the "Play a Sound" action, or the "Play a Random Sound" action, configured to play the sound(s) you want to hear when a command is recognized.

After creating that command, adding one of the mentioned actions to it, and clicking "OK" to add it to the command list, click the "Options" button near the top of the "Edit a Profile" window, to the right of the "Profile Name" field

Then, on the "Profile Options" window, click the "Profile Exec" tab, check the box to the left of the "Execute a command each time a command phrase is recognized" option, then use the dropdown below that option to select the command you created

(the "Execute even if rejected for low confidence" option should not be checked, as commands rejected for low confidence aren't actually executed, so you wouldn't want to have the sound play for those)

Finally, click "OK" to confirm the changes to the profile options, then click "Done" to save the changes to the profile.