Author Topic: How to use Dictation as a variable?  (Read 7709 times)

SaveMySoul

  • Guest
How to use Dictation as a variable?
« on: January 07, 2017, 01:36:27 AM »
Hello!

Below is something I am currently trying to code. A selfdestruction sequence that is triggered by [a word] and has to be confirmed by another [word] within the command in order to be successfully executed.

Apparently the problem/error I have, is that I am unable to save my answer as {DICTATION}. In the code below I am unable to get VoiceAttack to run the IF-true-then part, as it jumps right away to the else part.

Does anybody know what I am doing wrong? How can I save the {DICTATION} correctly as a variable, so that I can compare it to a text?

Help would be very much appreciated  :)

Code: [Select]
Trigger the command by saying "Selfdestruct"
Code: [Select]
Say, 'Confirm selfdestruction.'  (and wait until it completes)

Start Dictation Mode (Clearing Dictation Buffer)
Start Loop While : [{DICTATION}] Equals ' '
End Loop
Stop Dictation Mode

Begin Text Compare : [{DICTATION}] Equals 'confirmed'
    Say, 'Selfdestruction confirmed.'
    #PLACEHOLDER: KEYS PRESSED TO ACTUALLY SEFDESTRUCT; UNIMPORTANT HERE#
Else
    Say, 'Selfdestruction aborted.'
End Condition

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: How to use Dictation as a variable?
« Reply #1 on: January 07, 2017, 03:40:26 AM »
Your command is not waiting for dictation because your statement is "Start Loop While the value of '{Dictation}' equals character 32, A.K.A. Space", which it doesn't.

That should instead be
Code: [Select]
Start Loop While : [{DICTATION}] Equals ''Which changes the statement to "Start Loop While the value of '{Dictation}' equals blank, A.K.A. an empty string".
Make sure to check the "Evaluate 'Not Set' as empty (blank)" checkbox in the "Loop Start" action, so it always compares to an empty string or the actual contents, rather than "Not Set"(the equivalent of "NULL" in VoiceAttack).

SaveMySoul

  • Guest
Re: How to use Dictation as a variable?
« Reply #2 on: January 07, 2017, 04:04:49 AM »
Great, it works!!

Thanks alot! :)

mikelimtw

  • Jr. Member
  • **
  • Posts: 51
Re: How to use Dictation as a variable?
« Reply #3 on: February 05, 2017, 01:38:17 AM »
I have a similar problem. I am setting up an Autofire routine which can be triggered verbally. The part I am having trouble with is that {DICTATION} doesn't recognize my stop command 'ceasefire'.

Start dictation mode (clearing buffer)
While {DICTATION} <> 'ceasefire'
   clear buffer
   perform actions
LOOP END


By the way, I'm always posting pseudo-code because I don't know how to paste the actual code here. Can you tell me how to do that?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: How to use Dictation as a variable?
« Reply #4 on: February 05, 2017, 09:20:00 AM »
I don't know how to paste the actual code here. Can you tell me how to do that?
In the action list, either select the specific actions you want to paste by clicking and dragging, holding Shift and clicking the start and end points, and/or selecting specific action by using CTRL, then right click and click "Copy Selected as Text" in the context menu; Or, right click any action and click "Copy All as Text" in the context menu.

{DICTATION} doesn't recognize my stop command 'ceasefire'.
Now that you know how to paste the actions from your command, please do.

mikelimtw

  • Jr. Member
  • **
  • Posts: 51
Re: How to use Dictation as a variable?
« Reply #5 on: February 05, 2017, 09:56:45 AM »
Thanks Pfeil,

Ok here is the code I am trying to get working. I have an "autofire" command that holds down the fire key. I am using the code below to exit the routing and release the fire key.

        Start Dictation Mode (Clearing Dictation Buffer)
        Start Loop While : [{DICTATION:LOWERCASE:LATEST}] Does Not Equal 'ceasefire'
            Begin Boolean Compare : [AutoPower] Equals True
                Begin Boolean Compare : [Shields] Equals True
                    Begin Text Compare : [PowerMode] Does Not Equal 'Offense'
                        Execute command, 'set[power;][grid;][to;]offensive' (and wait until it completes)
                    End Condition
                Else
                    Begin Text Compare : [PowerMode] Does Not Equal 'Close'
                        Execute command, 'set[power;][grid;][to;]close[quarters;]' (and wait until it completes)
                    End Condition
                End Condition
            End Condition
            Pause 0.5 seconds
        End Loop


A few things:

1) I have tried using ceasefire, cancel fire nothing works. The log shows ceasefire or cancel fire as appended to the dictation buffer, but the routine doesn't seem to exit from the loop.

2) I have put a 0.5 second pause in the loop in an attemp to control the speed of the loop, I don't want it getting a bunch of noise and appending it into the buffer and eating up memory. Is this even something I should be concerned about?
« Last Edit: February 05, 2017, 10:37:13 AM by mikelimtw »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: How to use Dictation as a variable?
« Reply #6 on: February 05, 2017, 10:21:03 AM »
When the "{DICTATION}" token is used with any options, it inserts a trailing "space" character, so the text is no longer "ceasefire" but "ceasefire ", which is why the loop keeps going.

The documentation does state
Quote
SPACEX - Replace the, 'X' with an integer number, and that many extra spaces will be
placed at the end of each phrase.  The default is one space.

I was unaware of this, erm, feature, myself.

You can override the default thusly:
Code: [Select]
{DICTATION:LOWERCASE:SPACE0:LATEST}This will stop the space from being inserted.


As an aside, do make sure you place a "Stop Dictation Mode" action at the end of your command, or it will remain active when it's done executing.

mikelimtw

  • Jr. Member
  • **
  • Posts: 51
Re: How to use Dictation as a variable?
« Reply #7 on: February 05, 2017, 02:41:21 PM »
Huh, and I thought it was me doing something wrong...  :P

Well, technically I was, but that little "feature" needs to be more prominent in the documentation. As it turns out, I read right past that part and it didn't register. Anyway, thanks for pointing it out. So all {DICTATION} commands need to use the SPACE0 option to work. And yes, I do stop dictation... I only snipped out the relevant code.

Thanks for the help!

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: How to use Dictation as a variable?
« Reply #8 on: February 05, 2017, 02:43:53 PM »
Thanks, Pfeil.

Yeah... Dictation was never intended to be used in this manner.  Since the speech engine (in this context) uses pauses in speech to indicate the end of speech, this was found to be far easier than requiring users to add their own spaces when expressing more than one phrase.

It's easy to blame the documentation.  I mean, its 150+ pages.  I suppose I could make it bold, but I found people generally don't read that document anyway.  It's down there, around page 110.
« Last Edit: February 05, 2017, 02:52:27 PM by Gary »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: How to use Dictation as a variable?
« Reply #9 on: February 05, 2017, 03:01:44 PM »
So all {DICTATION} commands need to use the SPACE0 option to work.
Only the ones that use options, E.G. "{DICTATION:LATEST}"; Using the token without options("{DICTATION}") does not append a space to the end of the last dictation phrase, only between phrases(which is probably why this hasn't come up before, as people don't use the options).