Author Topic: Adding Voice Detection  (Read 1592 times)

Natustell

  • Newbie
  • *
  • Posts: 4
Adding Voice Detection
« on: February 05, 2022, 07:56:29 PM »
Can I use this to add voice activation functionality to a game that only has push to talk?

Can VoiceAttack hold a key as long as mic input of a certain minimum volume is detected?

SemlerPDX

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 291
  • Upstanding Lunatic
    • My AVCS Homepage
Re: Adding Voice Detection
« Reply #1 on: February 05, 2022, 08:31:50 PM »
VoiceAttack works by hearing a voice phrase then reacting.

It would be extremely difficult to get consistent actions to detect audio and become a 'voice activation detection' system.

You could make a command such as, "Start Talking" (or this could be a keyboard key or combo) and it could hold down another keyboard key until you say something like, "Stop Talking", (or again, a keyboard input), for example.

There may be some round-about way of getting a system to work as you want, but there are no direct actions or options in VoiceAttack to achieve this.  Perhaps some sort of C# or VB.net code in an inline function, or maybe some sort of plugin - but I'm personally not aware of any which presently exist that can do this.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Adding Voice Detection
« Reply #2 on: February 05, 2022, 08:52:31 PM »
While the "{STATE_AUDIOLEVEL}" token could be used to get the current detected input volume for the recording device used by the speech recognition engine, and that value could be used in a loop combined with a number of different actions to check the value, press the key, and provide a delay before the key is released, there are two main caveats to consider:

Because there is no buffer for the actual audio, you may find that the beginning of what you say is cut off, E.G. "hello" may come out as "lo"

The value returned by the speech recognition system (and thus, the token) may be too coarse to find a balance between not being so sensitive as to trigger on background noise, and being sensitive enough to reliably trigger quickly when you're speaking

Natustell

  • Newbie
  • *
  • Posts: 4
Re: Adding Voice Detection
« Reply #3 on: February 08, 2022, 07:36:43 PM »
This is my starting point:



Obviously, this is not working yet because it's triggered by the phrase "voice activation". Can I set "When I say" to a wildcard word so that anything I say will activate the command? Can I trick VoiceAttack into thinking that anything I say is the trigger word by messing with the training?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Adding Voice Detection
« Reply #4 on: February 08, 2022, 07:39:22 PM »
No. You'd want the loop itself to keep running in the background to monitor the audio level, and press or release the key as needed.

Natustell

  • Newbie
  • *
  • Posts: 4
Re: Adding Voice Detection
« Reply #5 on: February 08, 2022, 09:27:33 PM »


I tried talking while holding F9 and after tapping F9, neither worked. I don't know how exactly "When I press keys" is interpreted. I would like to be able to toggle this loop with a key.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Adding Voice Detection
« Reply #6 on: February 08, 2022, 09:45:21 PM »
The "When I press keys" option starts a command. By default, it does not then further interact with the command, unless you have enabled the "Repeat command while keys are held down" option, in which case the command does exactly that.


You're going to want to read the documentation, especially if you're going to make use of more advanced features; press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer.

These topics may also be of use, in addition to the official documentation:
Control flow (If, Else, ElseIf, Loop, Jump) basics
Variables and tokens summed up

Natustell

  • Newbie
  • *
  • Posts: 4
Re: Adding Voice Detection
« Reply #7 on: February 09, 2022, 12:27:22 AM »
The posts that you made explaining variables led me to understand that tokens and variables may not be interchangeable in this situation. I added a line that defines a variable as the value of {STATE_AUDIOLEVEL} and it worked.



The issue regarding a lack of an audio buffer appeared as you predicted. The first 0.2 seconds of what I say is cut off. This is manageable, but I ask if there is a way to reduce this latency?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Adding Voice Detection
« Reply #8 on: February 09, 2022, 08:28:58 AM »
There will likely always be at least some delay, as mentioned.

The "Resource balance offset" option could be used to allow the command to use more resources, which in turn may provide a slightly faster response time.
However, as mentioned in the documentation, this option should be used with caution: If the entered value is too high, especially with an infinite loop like this that has no explicit delay, resource usage may become high enough that it affects both VoiceAttack itself, and potentially other processes on your machine.