Author Topic: Can I use 1 key/phrase to toggle something on/off with "ON" or "OFF" feedback?  (Read 3353 times)

OneSwitch

  • Newbie
  • *
  • Posts: 12
I'd like to do the following in the brilliant VoiceAttack:

INPUT = F12 key.
OUTPUT = Upon release of F12 key, the system will toggle between one of two states.
                State 1 = say "SYSTEM LISTENING" and start listening
                 State 2 = say "DEACTIVATED" and stop listening.


I'd also like to do something very similar to help disabled people use the Game Control Mixer system with just a single joystick and speech: https://youtu.be/D53liD5PBso

INPUT = LEFT-SHIFT key / "SHIFT" speech.
OUTPUT = Upon detection of L-SHIFT or "SHIFT" speech, the system will toggle between one of two states.
                State 1 = Backspace key is HELD ON and feedback is "SHIFT ON". OR...
                State 2 = Backspace key is toggled OFF and feedback is "SHIFT OFF".


Any help much appreciated.

Barrie
OneSwitch.org.uk

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Yes, all that is possible either by getting the actual current state of feature/control, and/or by using variables to keep track of a given state.


Listening can be toggled using the native "Recognition Global Hotkey" option on the "Hotkeys" tab of the VoiceAttack options window (mouse and joystick equivalents are also available there), though those activate when the key is pressed rather than when it's released.

To toggle on release, you'll need to create a command and set up its hotkey/button with the "Shortcut is invoked only when all keys are released"/"Shortcut is invoked only when all buttons are released" option checked, containing something like
Code: [Select]
Toggle VoiceAttack listening
Begin Text Compare : [{STATE_LISTENING}] Equals '1'
    Say, 'System listening'
Else
    Say, 'Deactivated'
End Condition


The command for toggling a key can check the state of that key, E.G.
Code: [Select]
Begin Device State Check :  Keyboard Key 'Backspace' Is Not Pressed
    Press down Back key
    Say, 'Shift on'
Else
    Release Back key
    Say, 'Shift off'
End Condition
Note that pressing and releasing the physical backspace key would also cause the holding down to stop, so you'd want another command that monitors the release of that key to notify of the state change.



Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer for information on VoiceAttack's features.

OneSwitch

  • Newbie
  • *
  • Posts: 12
Thank you, very much. I'll try this out next week. Much appreciated.

OneSwitch

  • Newbie
  • *
  • Posts: 12
Struggling a bit with building the code...

Code: [Select]
Toggle VoiceAttack listening
Begin Text Compare : [{STATE_LISTENING}] Equals '1'
    Say, 'System listening'
Else
    Say, 'Deactivated'
End Condition

I can get the command looking just like that (apart from the Equals '1' part... that just says Equals 1).

The speech only says "Deactivated" when I use this method, unless I've entered it incorrectly. I'm using the Begin a Conditional (if Statement) Block. I tried Small Integer, True/False and Decimal with no luck. Any ideas where I'm going wrong here?

Appreciate the help.

Barrie

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
You may note the example literally says "Begin Text Compare"...


Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer for information on VoiceAttack's features.
The "Text (and Text-To-Speech) Tokens" section would be of particular interest

OneSwitch

  • Newbie
  • *
  • Posts: 12
Ooof. Apologies. I have it as you specified now (I believe), but it is erratic. Sometimes it works, sometimes not.

I don't know if the flag is just not staying in sync with the toggle feature. I'll try experimenting, but no luck so far.


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Which part isn't working consistently? Is the actual listening state not changing (as shown in the log/by the icon on the main window)?

That command works without issue on my machine.

OneSwitch

  • Newbie
  • *
  • Posts: 12
It seems to behave almost entirely randomly. I presume I've got something muddled, but what I have displayed perfectly replicates your code.

Don't suppose you could send me your working profile to my e-mail oneswitch [hat] gmail [hot] com, please? I think that would set me on my way,

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
I've attached the command to this post.

OneSwitch

  • Newbie
  • *
  • Posts: 12
Thank you. I'm using v1.8.6, and your profile I've just imported is doing the same thing.

The system turning ON/OFF is reliable from the text window feedback.

The headset on/off icon is not reliable.

The speech is clearly not reliable. It looses synchronicity with the text window.

OneSwitch

  • Newbie
  • *
  • Posts: 12
Actually, it's not reliable in the text window either. Strange.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
How are you testing the command? If I spam F12 rapidly for a number of seconds, the listening state does eventually stop changing (until I reduce the frequency of the presses, at which point it starts working again), however that's not a normal scenario

OneSwitch

  • Newbie
  • *
  • Posts: 12
I noticed this when switching to your profile:

"9:36:36.079 UNABLE TO EXECUTE PROFILE INITIALIZE COMMAND. COMMAND NOT AVAILABLE."


I pressed F12 once - and it said "system listening".

Waited 3 seconds, pressed it again, and it said "system listening".

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
I noticed this when switching to your profile:

"9:36:36.079 UNABLE TO EXECUTE PROFILE INITIALIZE COMMAND. COMMAND NOT AVAILABLE."
The profile I exported the command from has a command set to execute when the profile as loaded, but that command wasn't exported so it can't be executed. That shouldn't affect anything in this context.


What you are reporting is not normal behavior. Does the same issue occur when you click the headset icon on the main window? Does it occur when using the "Recognition Global Hotkey" option set to "Toggle listening start / stop"?

OneSwitch

  • Newbie
  • *
  • Posts: 12
I think my issue was background-noise. It seems to be working well now.

Sorry, and huge thanks. Can I send you a few quid/euros for a drink, as thanks?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Aha. Yes, that could certainly be it.

In that case enabling the "Reject Pending Speech" option on the "Recognition" tab of the VoiceAttack options window should remedy the blocking of the actual toggling (though I notice that under those conditions the icon doesn't update, which I'll let Gary, the developer, know).


Aside from interfering with this specific feature, obviously having a lot of background noise is problematic for speech recognition as well; You'll want to check the input volume for your microphone, and/or consider switching to a microphone with better noise cancelling (a good-quality headset is recommended).
You could also try NVIDIA's RTX Voice, provided you have a relatively recent graphics card of theirs.

OneSwitch

  • Newbie
  • *
  • Posts: 12
Thank you. You've been really helpful to a novice, VoiceAttack user. Really looking forwards to getting to better grips with it.