Author Topic: Help with detecting an empty payload  (Read 2397 times)

0 Members and 1 Guest are viewing this topic.

Methos

  • Jr. Member
  • **
  • Posts: 14
  • Karma: 0
    • View Profile
Help with detecting an empty payload
« on: July 04, 2014, 01:37:53 AM »
Lets say I have 3 payloads {1} - {3}, and I want to assign each one to a variable {var.a} - {var.c}, however if 1 of the payloads is empty then I do not want to assign that variable or have it be empty.

Then create a TTS sentence using the variables (think of Mad Libs), so the sentence would be formed like so:

The {var.a} jumped over the {var.b} and startled the {var.c}.

So you could say: dog, fence, cat and plug it into the sentence, or leave out the 2nd word and have that var be empty in the sentence.

Correct me if I'm wrong, but I believe you would use logic to determine if a payload is empty, like:

If A==B {2} null
then (leave this blank)
else Results.SetVar a {2}

I have tried testing for null and leaving it empty but "{2}" still shows up in the sentence. Any help would be appreciated.

Thanks

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Help with detecting an empty payload
« Reply #1 on: July 04, 2014, 04:06:47 AM »
Hi Methos, maybe you can try insteed of:

If A==B {2} null
then (leave this blank)
else Results.SetVar a {LastResult}

I can't try it now, because I'm not at home  ;)
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Help with detecting an empty payload
« Reply #2 on: July 04, 2014, 08:07:55 AM »
There is no such thing as an "empty" payload.

What do you mean by empty payload and how are you getting it?

If you use {3} when you only have two payloads, then it will be left as {3}

You can check how many payloads you have using {#P}

You will never have a first and third payload with no second payload.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Help with detecting an empty payload
« Reply #3 on: July 04, 2014, 08:16:31 AM »
If you're open to posting your actual command xml, it will be easier for us to help you.

http://voxcommando.com/mediawiki/index.php?title=XML_on_the_forum
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Methos

  • Jr. Member
  • **
  • Posts: 14
  • Karma: 0
    • View Profile
Re: Help with detecting an empty payload
« Reply #4 on: July 04, 2014, 09:24:31 AM »
Here is the code, but from what James said it may not be possible. I originally thought it might not be possible to have an empty payload which is why I was setting variables instead of using the payloads directly in the sentence formation.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 1.9.5.6-->
<command id="362" name="Mad Libs" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{1}&amp;&amp;Null</ifParams>
    <then />
    <else>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>x</param>
          <param>{1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{2}&amp;&amp;Null</ifParams>
    <then />
    <else>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>y</param>
          <param>{2}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{3}&amp;&amp;</ifParams>
    <then />
    <else>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>z</param>
          <param>{3}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>The {var.x} jumped over the {var.y} and startled the {var.z}.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.SpeakSync</cmdType>
    <params>
      <param>The {var.x} jumped over the {var.y} and startled the {var.z}.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>first word</phrase>
  <payloadDictation>payloadDictation: Regular</payloadDictation>
  <phrase>second word</phrase>
  <payloadDictation>payloadDictation: Regular</payloadDictation>
  <phrase>third word</phrase>
  <payloadDictation>payloadDictation: Regular</payloadDictation>
</command>

The end goal was to create a "vox game" that would go something like this:

Vox: "Please give me a noun."
Me: (payload dictation which gets saved to {var.a})

Vox: "Please give me an adjective."
Me: "Skip it" ({var.b} would be blank, and nothing would show up in the sentence when that variable is referenced)

Vox: "Please give me a verb."
Me: (payload dictation which gets saved to {var.c})

Then vox will plug in the variables to construct a sentence, and ideally the sentence itself would be pulled together using random sentence fragments from a map or payloadXML.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Help with detecting an empty payload
« Reply #5 on: July 04, 2014, 09:33:12 AM »
What you are describing as your end goal makes more sense. It will require more than one command.

The XML you are posting is for a single command, and there can be no empty payload in this case, so there should be no problem, but it is not very usable like this.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Help with detecting an empty payload
« Reply #6 on: July 04, 2014, 09:45:46 AM »
There are various ways to implement this, though the aim as a whole is kind of an advanced challenge to launch with.

In keeping with your description, you can do the following:

Each time you provide a sentence-part, it will be its own command within your MadLibs command group.

If you say "Skip it", the command can set the variable to be blank. http://voxcommando.com/mediawiki/index.php?title=Variables

 Otherwise, it will set it to whatever it understood. (You might want to set these commands to require confirmation.)

... Composing the final sentence structure is its own special challenge. :)

« Last Edit: July 04, 2014, 09:49:14 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Methos

  • Jr. Member
  • **
  • Posts: 14
  • Karma: 0
    • View Profile
Re: Help with detecting an empty payload
« Reply #7 on: July 04, 2014, 09:59:51 AM »
Ah ok, then in my end goal scenario, how can i set up a command where vox would ask me a question and wait for a response (in dictation form). This was my original method but I could not get it to work, which is why I switched to a single command format, allow me to explain. (I would post code, but I deleted everything when I switched methods.)

Command 1
Phrase - "Lets play a game"
TTS "Great, let's play mad libs"
VC.TriggerEvent q1

Command 2
(event q1)
TTS "Please give me a noun."
*** This is where I could not figure out how to make vox wait for a response. I tried VC.pause but it wont listen while paused. ***
Results.SetVar a {1}
TTS "Good choice. | Excellent, thank you."
OSD.ShowText "You choose {var.a}."
VC. TriggerEvent q2

Command 3
This is a  copy of command 2 essentially

..and so on, etc.

Then last command would build the sentence using the above variables.

**** I just saw your post nime5ter, thanks for the confirmation idea, I like that. ****
« Last Edit: July 04, 2014, 10:02:33 AM by Methos »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Help with detecting an empty payload
« Reply #8 on: July 04, 2014, 10:25:08 AM »
You can't make it wait for a response per se, but since VoxCommando is always waiting for a response of some sort, this is not really a problem.

You just need to put all your commands for setting the various types of words into a group.  You can turn the group on when you are playing the game.

Since a command can't have only a payload (it needs a phrase too) you can have a command such as :

"my noun is X"

and another for

"my verb is X"

etc.

There are many different ways to handle it.

If you would prefer to say "my word is X" then your command that prompts the user for an adverb could store a variable so that it would know the next word offered is going to be an adverb.

In your commands where you allow the user to set a word using dictation you will almost certainly want to make those commands that require confirmation, because quite often it is going to get the word wrong.

I understand that in certain situations like this one it would be easier to "pause for input" but that is not currently an option.

You are probably going to run into problems with verb conjugation as well, but that is a whole other can of words.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Help with detecting an empty payload
« Reply #9 on: July 04, 2014, 10:40:04 AM »
Along the lines of:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.0.0.0-->
<commandGroup open="True" name="Mad libs" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="333" name="Let's play madlibs" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Great! Let's play mad libs. Please give me a noun.</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Let's play a game</phrase>
  </command>
  <command id="380" name="++My noun is {1}" enabled="true" alwaysOn="False" confirm="True" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Where I use {var.noun} here you could also use {1}, but this way you have confirmation that the variable was stored.">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)Contains(B)</ifType>
      <ifParams>{PreviousSpoken}&amp;&amp;skip the noun</ifParams>
      <then>
        <action>
          <cmdType>Results.SetVar</cmdType>
          <params>
            <param>noun</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Okay, we'll skip the noun.|Fine, let's move on.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>Results.SetVar</cmdType>
          <params>
            <param>noun</param>
            <param>{1}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>OK, your noun is {var.noun}.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Now, let's have an adjective.|Next, please give me an adjective.</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>My noun is, skip the noun</phrase>
    <payloadDictation>payloadDictation: Regular</payloadDictation>
  </command>
  <command id="393" name="++My adjective is {1}" enabled="true" alwaysOn="False" confirm="True" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Where I use {var.adjective} you could also use {1}, but this way you have confirmation that the variable was stored.">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)Contains(B)</ifType>
      <ifParams>{PreviousSpoken}&amp;&amp;skip the adjective</ifParams>
      <then>
        <action>
          <cmdType>Results.SetVar</cmdType>
          <params>
            <param>adjective</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Okay, we'll skip the adjective.|Fine, let's move on.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>Results.SetVar</cmdType>
          <params>
            <param>adjective</param>
            <param>{1}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>OK, your adjective is {var.adjective}.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Now, let's have a verb.|Next up, a verb please.</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>My adjective is, skip the adjective</phrase>
    <payloadDictation>payloadDictation: Regular</payloadDictation>
  </command>
  <command id="397" name="++My verb is {1}" enabled="true" alwaysOn="False" confirm="True" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)Contains(B)</ifType>
      <ifParams>{PreviousSpoken}&amp;&amp;skip the verb</ifParams>
      <then>
        <action>
          <cmdType>Results.SetVar</cmdType>
          <params>
            <param>verb</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Okay, we'll skip the verb.| Fine, let's move on.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>Results.SetVar</cmdType>
          <params>
            <param>verb</param>
            <param>{1}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>OK, your verb is {var.verb}.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>How about an adverb.|Next up, an adverb.</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>My verb is, skip the verb</phrase>
    <payloadDictation>payloadDictation: Regular</payloadDictation>
  </command>
</commandGroup>

Above I follow your script. Each grammar part requires confirmation, which means that my logic block needs to use the variable {PreviousSpoken} rather than {LastSpoken}, since the last phrase spoken is my confirmation.

The computer poses the question at the end of the command that precedes it. You don't need to use any triggers, actually. But you'll need to be thoughtful in creating your phrases. For example, doing it this way, we can't just use "Skip it" as a phrase for all the commands since each command needs unique phrases. Instead, we use "Skip the noun", "Skip the adjective", etc.

[IMPORTANT EDIT: I just remembered that one can run into problems when chaining commands that require confirmation. I've edited the xml above to hopefully handle that. It requires threading.]
« Last Edit: July 04, 2014, 11:41:20 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Methos

  • Jr. Member
  • **
  • Posts: 14
  • Karma: 0
    • View Profile
Re: Help with detecting an empty payload
« Reply #10 on: July 04, 2014, 10:57:56 AM »
Ok, thanks Nime5ter. I will give this a shot. This is also why I was asking about dictating numbers, though now I am using the spelling as you suggested James.

Can you group Groups? When I installed Vox I chose the XBMC config and I like how it's broken up into groups but I would like to have all of those under one "XBMC Commands" group, is this possible?

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Help with detecting an empty payload
« Reply #11 on: July 04, 2014, 10:59:55 AM »
No, unfortunately it's not possible to group groups.

http://voxcommando.com/forum/index.php?topic=1369.0
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)