Weird Bing Script Behavior - Skipping Sections

 
#1

Either my code is miss written or there a a bug in the works. Here's what's happening;
I'm writing a script to place inside the Bing control. So far it has four sections (sorry, I'm not sure of the terms). So, each section will result in a different action depending on what is spoken, recognized by the control and inserted in the valuable ($BingSpeech).

When I speak the first phrase "Do you know where you are" which is the first "if" section, Bing recognizes this section and the script acts properly. When I speak the second or third words "Hello" or "Thank You" in the following Elseif sections, Bing recognizes these words properly but the script skips to the last Else section (Tell me a joke) and executes this last section instead. This happens no matter how many sections I have listed.

If I change the last section from a Else to a Elseif the script will not run at all (which I think is would happen?).

Here's my script. See anything weird?

Code:


if ($BingSpeech = "Do you know where you are")
set(D0, on)
Set(D16, on)
Set(D11, on)
Set(D12, on)
Set( D18, on )
ControlCommand("Speech Recognition", Pauseon)
ControlCommand("Soundboard v4", Track_33)
Sleep(1000)
ControlCommand("Head Section", ScriptStart, "Radar Sweep")
uartWrite(1, 0, "1, p70000 s20000", 0x0d) #rotate a little left of center
Sleep(2000)
uartWrite(1, 0, "1, p100000 s20000", 0x0d) #rotate a little rt of center
Sleep(2000)
ControlCommand("Leg Section", ScriptStart, "Waist Center")
Sleep(3000)
ControlCommand("Soundboard v4", Track_18)
ControlCommand("Head Section", ScriptStop, "Bubble Up and Down")
Sleep(4000)
Set(D12, off)
Sleep(2000)
set(D0, off)
Set(D16, off)
Set(D11, off)
Set( D18, off )
ControlCommand("Speech Recognition", Pauseoff)

ELSEif ($BingSpeech = "Hello")
ControlCommand("Head Section", ScriptStart, "Bubble Up and Down")
Sleep(100)
ControlCommand("Soundboard v4", Track_4)

ELSEif ($BingSpeech = "Thank You")
ControlCommand("Head Section", ScriptStart, "Bubble Up and Down")
Sleep(100)
ControlCommand("Soundboard v4", Track_32)

ELSE ($BingSpeech = "Tell me a joke")
ControlCommand("Personality Generator", PauseOn)
ControlCommand("Soundboard v4", Track_19)
ControlCommand("Speech Recognition", PauseMS, 9000)
ControlCommand("Head Section", ScriptStart, "Happy, Sad Bubble")
Set(D0, on)
Set(D16, on)
Set(D11, on)
Set(D14, on)
Sleep(5000)
ControlCommand("Leg Section", ScriptStart, "Hip Down Full")
Sleep(2000)
ControlCommand("Leg Section", ScriptStart, "Up with Hips")
Sleep(2000)
Set(D0, off)
Set(D16, off)
Set(D11, off)
Set(D14, off)
ControlCommand("Personality Generator", PauseOff)

endif

#2

OK, never mind. I've got this figured out.

I need to format my phrases exactly the way Bing hears them including punctuation. I can see the way Bing hears what I'm saying in the control's debug window. Once I matched my formatting with the way the word or phrase shows in the debug window the script works properly.

For example; If I write "Thank You" and Bing hears and returns "Thank you." then that is the way I need to place the word or phrase in my script.

Also it seems that all words or phrases are returned with a capital at the start and a period or question mark at the end. Even a single word. I guess correct grammar counts. Grin

#3

And an ELSE doesn't have any parameters.

An ELSE is an ELSE. It's just that. It doesn't have parameters. An ELSE means anything else.

Please use Blockly to help learn programming. We put an absolute crazy amount of effort to implement Blockly into EZ-Builder for questions like this. It's the best way to learn to program.

The structure of IF conditioning has..

Code:


IF (some comparison)
# do something
ELSEIF (some other comparision)
# do something
ELSEIF (some other comparision)
# do something
ELSE
# do something because nothing matched
ENDIF



Take a look at how easy Blockly makes this...


User-inserted image

#4

Thanks DJ. I love Blockly. It does help a lot and makes coding easy.

#5

Dave, another thing that might help you in the future is to use the Contains() function in the script, as Bing Speech sometimes recognizes more words than it should. Something like this should work for your "Thank you" example:

Code:

if (Contains($BingSpeech, "Thank"))



So if the $BingSpeech variable has "Thank whatever", you would have a true statement on your "if" clause.

#6

Humm, Thanks Gilvan! This sounds like a great idea.

I'll try to figure out the code and give it a try. Smile

I know @DJ.... "Use Blockly". Tongue

#7

I would suggest using API.AI to parameterize what is being said, and then make your script handle the parameters. This is a perfect use case for it. It would allow someone to say "Thanks, blah blah blah" or "Thank you" or "please allow me to appreciate your help through a verbal method of appreciation" and you understand that someone is trying to thank you.

By grabbing the APIAction you would know what type of script or where in the script you should go. By looking at the variables returned by API.AI, you would then be able to call the correct specific section of your script. It also removes the punctuation situation.

Here is an example...

"What is 5 time 4"
From this being sent to API.AI, you would be able to know that this is a request for the math action.
It could return variables of multiplication, 5 and 4
From there, in a script, you could have it then look for the APIAction seeing that the user is asking for math functions to be performed and call a math script
From there, you could evaluate the first parameter for Addition, Subtraction, Multiplication, Division, sine, cosine, tangent or whatever function you want to script out and call the correct section of the script (in this case multiplication).
From there you would simply pass in the 2nd and 3rd pieces of information and do the math of 5x4 or 20.

You could also do things like "What is pi x 20?" and evaluate for that and so on.

There is a lot to be offered by API.AI, but it does require setup on in API.AI along with more scripting and such to make it work out.