Author Topic: How do I speak a variable?  (Read 9314 times)

rocketbosszach

  • Guest
How do I speak a variable?
« on: January 23, 2017, 09:37:47 AM »
I don't know if VA has this capability, but I'd like to be able to set a variable by speaking. For instance, I would like the flow to go something like this:

Code: [Select]
Speak: Log out

<set int var confquery="1000 < random > 9999">
<tts="Please confirm with code {Int:confquery}>
<Summon external command Confirmation

Code: [Select]
Confirmation

Speak: ?
<set int var confirmation="speak">

Code: [Select]
Speak: Log out (continued)
If int var confirmation=confquery
Exit app
else
<tts="Incorrect confirmation">

There are easier ways of doing this. Like setting a constant confirmation code and just waiting for me to execute a command to trigger the boolean, but this seems more fun.

I apologize if my code is jumbled. I'm not really a programmer, but I've been spending a lot of time with voice attack and would like to make my commands a little more powerful.
« Last Edit: January 23, 2017, 10:12:42 AM by rocketbosszach »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do I speak a variable?
« Reply #1 on: January 23, 2017, 10:21:45 AM »
If I understand your attempt at "pseudocode" correctly:
Your pseudocode isn't quite clear to me, but try this:
Code: [Select]
Set small int (condition) [confquery] value as random from 1000 to 9999
Say, 'Please confirm with code {SMALL:confquery}'
Set Boolean [DictationComplete] to False
Start Loop While : [DictationComplete] Equals False
    Start Dictation Mode (Clearing Dictation Buffer)
    Start Loop While : [{DICTATION}] Equals ''
    End Loop
    Stop Dictation Mode
    Begin Text Compare : [{EXP: {DICTATION} = {SMALL:confquery}}] Equals '1'
        Close 'VoiceAttack' process
        Set Boolean [DictationComplete] to True
    Else
        Say, 'Incorrect confirmation'
        Set Boolean [DictationComplete] to True
    End Condition
End Loop

Good luck trying to dictate four digits in one go.
It's not so much a VoiceAttack limitation, but one of the Microsoft Speech recognition engine it relies on, that freeform speech(as in, recognizing any spoken words without context) is spotty at best. At times you may be able to get descent recognition, but it's likely to be somewhat unreliable.


EDIT:
Code: [Select]
Set small int (condition) [confquery] value as random from 1000 to 9999
Say, 'Please confirm with code {SMALL:confquery}'
Start Dictation Mode (Clearing Dictation Buffer)
Start Loop While : [{DICTATION}] Equals ''
End Loop
Stop Dictation Mode
Begin Text Compare : [{EXP: {DICTATION} = {SMALL:confquery}}] Equals '1'
    Close 'VoiceAttack' process
Else
    Say, 'Incorrect confirmation'
End Condition
No need for the outer loop as the dictation is one-shot only in this case.
« Last Edit: January 23, 2017, 10:46:13 AM by Pfeil »

rocketbosszach

  • Guest
Re: How do I speak a variable?
« Reply #2 on: January 23, 2017, 10:50:15 AM »
Thanks. This was just one example that I was thinking of, but it'll come in handy in the future.

rocketbosszach

  • Guest
Re: How do I speak a variable?
« Reply #3 on: January 23, 2017, 08:58:45 PM »
So this is what I ended up doing. It works pretty well, actually. Above 90% accuracy in a quiet room.

Code: [Select]
Set small int (condition) [confquery] value as random from 1000 to 9999
Marker: restart
Say, 'Please confirm with code: {SMALL:confquery}'  (and wait until it completes)
Pause 0.51 seconds
Start Dictation Mode (Clearing Dictation Buffer)
Start Loop While : [{DICTATION}] Equals ''
End Loop
Stop Dictation Mode
Begin Text Compare : [{EXP:{DICTATION}={SMALL:confquery}}] Equals '1'
    Say, '[Well done' or ' I'm so proud of you' or ' what an accomplishment' or ' amazing:] [commander' or ' sir' or ' ]'  (and wait until it completes)
    Set small int (condition) [bigredbutton] value to 1
    Exit Command
Else If Text Compare : [{DICTATION}] Equals 'cancel'
    Say, 'Confirmation cancelled'  (and wait until it completes)
    Set small int (condition) [bigredbutton] value to 0
    Exit Command
Else
    Say, 'Try again commander'  (and wait until it completes)
    Set small int (condition) [bigredbutton] value to 0
    Jump to Marker: restart
End Condition

EDIT: The issue I'm having now (If you could call it an issue) is it says the number out completely, i.e. Five thousand two hundred and twenty nine. It's not a huge deal, but I was wondering if there was a way to get it to say each number individually without it being a big thing.

I'm essentially using it as a switch. Other commands call this one and depending on the outcome, the action is allowed to proceed.

Like this:

Code: [Select]
Say, 'On one condition'  (and wait until it completes)
Execute command, 'Confirmation' (and wait until it completes)
Begin Small Integer Compare : [bigredbutton] Equals 0
    Say, 'I'd rather not'
Else If Small Integer Compare : [bigredbutton] Equals 1
    Say, 'Commencing backflip. Happy now?'
End Condition

edits upon edits:  I apologize for my "pseudocode". I was at work and I remembered the syntax but not the commands.
« Last Edit: January 23, 2017, 09:06:55 PM by rocketbosszach »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do I speak a variable?
« Reply #4 on: January 23, 2017, 10:11:29 PM »
I was wondering if there was a way to get it to say each number individually without it being a big thing.
Code: [Select]
Say, 'Please confirm with code {TXTSUBSTR:"{SMALL:confquery}":0:1}, {TXTSUBSTR:"{SMALL:confquery}":1:1}, {TXTSUBSTR:"{SMALL:confquery}":2:1}, {TXTSUBSTR:"{SMALL:confquery}":3:1}'
I'm using ", " as a simple pause between digits.

If you really want to fine-tune that you'll have to use SSML:
Code: [Select]
<?xml version="1.0"?>
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.w3.org/2001/10/synthesis
                   http://www.w3.org/TR/speech-synthesis/synthesis.xsd"
         xml:lang="en-US">
Please confirm with code <break time ="250ms"/><prosody rate="60%">{TXTSUBSTR:"{SMALL:confquery}":0:1},</prosody><break time ="250ms"/><prosody rate="60%">{TXTSUBSTR:"{SMALL:confquery}":1:1},</prosody><break time ="250ms"/><prosody rate="60%">{TXTSUBSTR:"{SMALL:confquery}":2:1},</prosody><break time ="250ms"/><prosody rate="60%">{TXTSUBSTR:"{SMALL:confquery}":3:1}</prosody>
</speak>

edits upon edits:  I apologize for my "pseudocode". I was at work and I remembered the syntax but not the commands.
It was a bit unclear to me, but I was in a grumpy mood to be fair. My apologies as well.

rocketbosszach

  • Guest
Re: How do I speak a variable?
« Reply #5 on: January 24, 2017, 11:56:17 AM »
That was perfect, thank you. I do have one more question, though. In order to make my original question work the text compare had to be

Code: [Select]
Begin Text Compare : [{EXP:{DICTATION}={SMALL:confquery}}] Equals '1'
I see that it's comparing them, and when they are the same, it's setting some variable to '1'. What variable is that, and what is happening behind the scenes? Why not zero or two?

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: How do I speak a variable?
« Reply #6 on: January 24, 2017, 12:44:14 PM »
Some background...  EXP, just like all tokens, are text-based.  That means, when a token is rendered, the result is always text.  Rendering it as text means it can be used in TTS or Quick Input as well as allow the value to be converted and used in other places (such as integer, decimal and text condition statements, variable pauses, keypress variables, etc) without having to have a function for every data type.  The drawback outside of TTS or Quick Input is that it's just that... text that must be converted. 

In this case, EXP is being used to render a Boolean (true/false) value: 
Code: [Select]
Begin Text Compare : [{EXP:{DICTATION}={SMALL:confquery}}] Equals '1'
In VA, 'true' is represented in text as '1', and false is represented as '0'.  The check above is looking to make sure the result is true ('1').  There is no variable being set, EXP will be rendered either as '0' or '1'.


rocketbosszach

  • Guest
Re: How do I speak a variable?
« Reply #7 on: January 24, 2017, 02:05:42 PM »
Ah, that makes sense. Thank you for enlightening me. Also, thank you for conceiving and continuing to develop Voice Attack. I've only had it for less than a week, but I've already dumped so many hours into it.