Author Topic: Toggle Listening Workaround  (Read 4471 times)

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Toggle Listening Workaround
« on: May 09, 2017, 01:28:13 PM »
I just wanted to post this in case others might have use for it. In one of my profiles I give the user the option to specify whether or not he wants to use a keypress (or combination keypress) to toggle VA listening (I'm trying to minimize the amount of time the user must directly interface with VA). In this case it would be useful to be able to set as well as check the value of the the profile's "Override Recognition Global Hotkey" option based on the user's input.

Since this type of option does not currently exist (and one of my feature requests somewhat addresses this) I've resorted to the following workaround:

The user is queried about enabling/disabling a keypress to make VA listen, and the result is stored in "voiceattack listen button." The following command is executed by the keyboard shortcut [Left Ctrl+Num7].
Code: [Select]
Begin Text Compare : [voiceattack listen button] Equals '1'
    Start Loop While : ([{STATE_KEYSTATE:NUM7}] Equals '1' AND [{STATE_KEYSTATE:LCTRL}] Equals '1')
        Begin Text Compare : [{STATE_LISTENING}] Equals '0'
            Execute command, 'Start Listening' (and wait until it completes)
        End Condition
    End Loop
    Execute command, 'Stop Listening' (and wait until it completes)
End Condition
So while LCtrl and Num7 are simultaneously pressed the command will loop through the state checks and activate listening without completely clogging the event log with a ton of "listening resumed" statements (yes this can be turned off by running in "Quiet Mode" but that's not the point here). When either key is released VA goes back to not listening.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: Toggle Listening Workaround
« Reply #1 on: May 09, 2017, 03:20:14 PM »
Is the check within the loop intended to make sure listening remains enabled at all costs?

If listening is unlikely to toggle back off while the keyboard shortcut is held down(through actions outside of this command), it can be done this way as well:
Code: [Select]
Begin Text Compare : [voiceattack listen button] Equals '1'
    Execute command, 'Start Listening' (and wait until it completes)
    Start Loop While : ([{STATE_KEYSTATE:NUM7}] Equals '1' AND [{STATE_KEYSTATE:LCTRL}] Equals '1')
    End Loop
    Execute command, 'Stop Listening' (and wait until it completes)
End Condition

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Toggle Listening Workaround
« Reply #2 on: May 10, 2017, 08:27:21 AM »
Very nice suggestion Pfeil! I haven't done much with empty looping, but I'll definitely need to implement it more! :)

For my application I want listening to occur under two circumstances:
  • the user requests it (and whether or not listening stays on after it is requested will depend on the state of "voiceattack listen button")
  • VA is requesting voiced input from the user
I updated the command with additional functionality so that it can handle:
  • toggle listening ON/OFF when the command is called via the voiced command phrase
  • start/stop listening if the command is called via keypress combination (and not as a subcommand) and the user wants VA to listen only when the combination is pressed
  • toggle listening if the command is called as a subcommand or via keypress combination and the user has NOT indicated that he wants VA to listen only when the combination is pressed
When I say: [Start; Stop] Listening
When I press keys: Left Ctrl+Num Sub
Code: [Select]
Begin Text Compare : [{LASTSPOKENCMD}] Equals '{CMD}'
    //Command is directly executed via the voiced command phrase
    Begin Text Compare : [{CMDSEGMENT:0}] Equals 'Start'
        Start VoiceAttack listening
    Else
        Stop VoiceAttack listening
    End Condition
Else
    Begin Condition : ([{CMDISSUBCOMMAND}] Equals '0' AND [voiceattack listen button] Equals '1')
        //Command is not a subcommand (and was directly executed via keypress) and user previously indicated listening should be ON during a button (or key) press
        Start VoiceAttack listening
        //Stay in a loop while the trigger key combination is pressed
        Start Loop While : ([{STATE_KEYSTATE:LCTRL}] Equals '1' AND [{STATE_KEYSTATE:NUM-}] Equals '1')
        End Loop
        Stop VoiceAttack listening
    Else
        //Command is a subcommand or user has not indicated that listening should be ON during a button (or key) press
        Begin Text Compare : [{STATE_LISTENING}] Equals '0'
            Start VoiceAttack listening
        Else
            Stop VoiceAttack listening
        End Condition
    End Condition
End Condition
« Last Edit: May 25, 2017, 07:53:42 AM by Exergist »