Asked — Edited

Scripting

Ok, I'm stumped. I have tried to do this myself for 3 days, time for help. Is there any reason why a script that works in Windows 7 not work on Windows 10? Below is a script (Credit to Luis Vazquez who wrote this years back, I only added to it) that I can not get to run on my new Windows 10 computer. It is the exact same script on both machines. I know, if it works on one it should work on the other!

The program starts out:

Program says "Oh good, I love to do math."

"What would you like to do ... addition, subtraction, multiplication or division?"

(Your answer) ... "addition"

Program says back "I heard you say addition." "OK, I will give you 5 addition math questions." "Lets begin"

This is where the problem begins!

I does not give a addition question but a division question on the W10 machine?

It is the exact script, copied from one to the other ... lol.


# Initialise Variables
$QuestionNumber = 0

SayWait("Oh good, I love to do math")

:StartTheSquence
SayWait("What would you like to do, addition, subtraction, multiplication or division?")
$MathTypeResponse = WaitForSpeech(10, "Addition", "Subtraction", "Multiplication", "Division")



# Repeat MathTypeResponse 
if ($MathTypeResponse = "timeout" )
SayWait("I did not hear what you said.")
SayWait("Lets start over.")
Goto(StartTheSquence)
Else
SayWait("I heard you say " + $MathTypeResponse )
SayWait("Ok, I will give you 5 " + $MathTypeResponse  + " math questions.")
SayWait("Lets begin.")
endif 


# Go to math type catagory
if ($MathTypeResponse = "Addition" )
goto(Addition)
ELSEif ($MathTypeResponse = "Subtraction" )
goto(Subtraction)
ELSEif ($MathTypeResponse = "Multiplication" )
goto(Multiplication)
ELSE
goto(Division)
endif 


# If MathResponse was addition.

:Addition
$FirstAdditionNumber = GetRandomUnique(0,5)
$SecondAdditionNumber = GetRandomUnique(0,5)
$AdditionAnswer = $FirstAdditionNumber + $SecondAdditionNumber

:loop
$QuestionNumber = $QuestionNumber + 1
if ($QuestionNumber = 6)
SayWait("That was 5 " + $MathTypeResponse + "questions.")
SayWait("Would you like to start over again?")
$StartOverResponse = WaitForSpeech(10, "No", "Affirmative", "Okay", "Yeah", "Negative", "Maybe", "Yes" )
Goto(StartOverQuestion)
endif

SayWait("What is " + $FirstAdditionNumber + " plus " + $SecondAdditionNumber )
sleep(1000)
$AdditionResponse = WaitForSpeech(20, "0","1","2","3","4","5","6","7","8","9","10")
SayWait("You said" + $AdditionResponse)
if ($AdditionResponse  == $AdditionAnswer) 
SayWait("Good job! Yes " +  $AdditionAnswer + " is the correct answer")
goto(Addition)
Else
SayWait("Sorry " + $AdditionResponse + " is not correct. please try again.")
sleep(1000)
goto(loop)
endif


# If MathResponse was subtraction.

:Subtraction
$FirstSubtractionNumber = GetRandomUnique(5,10)
$SecondSubtractionNumber = GetRandomUnique(0,5)
$SubtractionAnswer = $FirstSubtractionNumber - $SecondSubtractionNumber

:loop
$QuestionNumber = $QuestionNumber + 1
if ($QuestionNumber = 6)
SayWait("That was 5 " + $MathTypeResponse + "questions.")
SayWait("Would you like to start over again?")
$StartOverResponse = WaitForSpeech(20, "No", "Affirmative", "Okay", "Yeah", "Negative", "Maybe", "Yes" )
Goto(StartOverQuestion)
endif

SayWait("what is " + $FirstSubtractionNumber + " minus " + $SecondSubtractionNumber )
sleep(1000)
$SubtractionResponse = WaitForSpeech(20, "0","1","2","3","4","5","6","7","8","9","10")
SayWait("You said" + $SubtractionResponse)
if ($SubtractionResponse  == $SubtractionAnswer ) 
SayWait("Good job! Yes " +  $SubtractionAnswer + " is the correct answer")
Goto (Subtraction)
else
SayWait("Sorry " + $SubtractionResponse + " is not correct. please try again.")
sleep(1000)
goto(loop)
endif




# If MathResponse was multiplication.

:Multiplication
$FirstMultiplicationNumber = GetRandomUnique(1,5)
$SecondMultiplicationNumber = GetRandomUnique(0,5)
$MultiplicationAnswer = $FirstMultiplicationNumber * $SecondMultiplicationNumber

:loop
$QuestionNumber = $QuestionNumber + 1
if ($QuestionNumber = 6)
SayWait("That was 5 " + $MathTypeResponse + "questions.")
SayWait("Would you like to start over again?")
$StartOverResponse = WaitForSpeech(20, "No", "Affirmative", "Okay", "Yeah", "Negative", "Maybe", "Yes" )
Goto(StartOverQuestion)
endif

SayWait("what is " + $FirstMultiplicationNumber + " times " + $SecondMultiplicationNumber )
sleep(1000)
$MultiplicationResponse = WaitForSpeech(20, "0","1","2","3","4","5","6","7","8","9","10","12","15","16","20","25")
SayWait("You said" + $MultiplicationResponse)
if ($MultiplicationResponse  == $MultiplicationAnswer) 
SayWait("Good job! Yes " +  $MultiplicationAnswer + " is the correct answer")
goto(Multiplication)
Else
SayWait("Sorry " + $MultiplicationResponse + " is not correct. please try again.")
sleep(1000)
goto(loop)
endif


# If MathResponse was division.

:Division
$FirstDivisionNumber = GetRandomUnique(2,6)
$SecondDivisionNumber = GetRandomUnique(1,2)
$DivisionAnswer = $FirstDivisionNumber / $SecondDivisionNumber

:loop
$QuestionNumber = $QuestionNumber + 1
if ($QuestionNumber = 6)
SayWait("That was 5 " + $MathTypeResponse + "questions.")
SayWait("Would you like to start over again?")
$StartOverResponse = WaitForSpeech(20, "No", "Affirmative", "Okay", "Yeah", "Negative", "Maybe", "Yes" )
Goto(StartOverQuestion)
endif

SayWait("what is " + $FirstDivisionNumber + " divided by " + $SecondDivisionNumber )
sleep(1000)
$DivisionResponse = WaitForSpeech(20, "0","1","2","3","4","5","6","7","8","9","10","12","15","16","20","25")
SayWait("You said" + $DivisionResponse)
if ($DivisionResponse  == $DivisionAnswer) 
SayWait("Good job! Yes " +  $DivisionAnswer + " is the correct answer")
goto(Division)
Else
SayWait("Sorry " + $DivisionResponse + " is not correct. please try again.")
sleep(1000)
goto(loop)
endif
#Halt()


# Start over response

:StartOverQuestion

if ($StartOverResponse = "Yes" )
goto(Yes)
ELSEif ($StartOverResponse = "No" )
goto(No)
ELSEif ($StartOverResponse = "Affirmative" )
goto(Yes)
ELSEif ($StartOverResponse = "Okay" )
goto(Yes)
ELSEif ($StartOverResponse = "Yeah" )
goto(Yes)
ELSEif ($StartOverResponse = "Negative" )
goto(No)
ELSE 
goto(StartTheSquence)
endif
Return() 
Halt()

:Yes
Goto(StartTheSquence)
Halt() 


:No
SayWait("I enjoyed doing math with you.")
SayWait("Maybe we can do it again soon.")
HALT()



ARC Pro

Upgrade to ARC Pro

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.

#1  

So you told "division" but it went to the behaved as if it heard "addition"? There are not program errors, it just behaves differently?

#2  

On your Win7 machine, did you need to code in Speech Recognition setting $MathTypeResponse because I don't see where it would get set otherwise? Did you just copy the script from your Win7 machine or the enter project? I feel like your are missing something else for the project.

PRO
USA
#3  

@HerrBall

The script has been fixed:


SayWait("Oh good, I love to do math")

:StartTheSquence

# Initialise Variables
$QuestionNumber = 0

SayWait("What would you like to do, addition, subtraction, multiplication or division ?")
# ptp: changed the phrases to lowercase
$MathTypeResponse = WaitForSpeech(10, "addition", "subtraction", "multiplication", "division")


# Repeat MathTypeResponse
if ($MathTypeResponse = "timeout")
  SayWait("I did not hear what you said.")
  SayWait("Lets start over.")
  Goto(StartTheSquence)
ELSE
  SayWait("I heard you say " + $MathTypeResponse )
  SayWait("Ok, I will give you 5 " + $MathTypeResponse + " math questions.")
  SayWait("Lets begin.")
endif


# Go to math type catagory
# ptp: compare lowercase phrases
if ($MathTypeResponse = "addition")
  goto(Addition)
ELSEif ($MathTypeResponse = "subtraction")
  goto(Subtraction)
ELSEif ($MathTypeResponse = "multiplication")
  goto(Multiplication)
ELSE
  goto(Division)
endif


  # If MathResponse was addition.

:Addition
$FirstAdditionNumber = GetRandomUnique(0,5)
$SecondAdditionNumber = GetRandomUnique(0,5)
$AdditionAnswer = $FirstAdditionNumber + $SecondAdditionNumber

:addition_loop
$QuestionNumber = $QuestionNumber + 1
if ($QuestionNumber = 6)
  SayWait("That was 5 " + $MathTypeResponse + " questions.")
  SayWait("Would you like to start over again?")
  # ptp : changed to lowercase
  $StartOverResponse = WaitForSpeech(10, "no", "affirmative", "okay", "yeah", "negative", "maybe", "yes")
  Goto(StartOverQuestion)
endif

SayWait("What is " + $FirstAdditionNumber + " plus " + $SecondAdditionNumber )
sleep(1000)
$AdditionResponse = WaitForSpeech(20, "0","1","2","3","4","5","6","7","8","9","10")
SayWait("You said " + $AdditionResponse)
if ($AdditionResponse = $AdditionAnswer)
  SayWait("Good job! Yes " + $AdditionAnswer + " is the correct answer")
  goto(Addition)
ELSE
  SayWait("Sorry " + $AdditionResponse + " is not correct. please try again.")
  sleep(1000)
  goto(addition_loop)
endif


  # If MathResponse was subtraction.

:Subtraction
$FirstSubtractionNumber = GetRandomUnique(5,10)
$SecondSubtractionNumber = GetRandomUnique(0,5)
$SubtractionAnswer = $FirstSubtractionNumber - $SecondSubtractionNumber

:subtraction_loop
$QuestionNumber = $QuestionNumber + 1
if ($QuestionNumber = 6)
  SayWait("That was 5 " + $MathTypeResponse + " questions.")
  SayWait("Would you like to start over again?")
  # ptp : changed to lowercase
  $StartOverResponse = WaitForSpeech(20, "no", "affirmative", "okay", "yeah", "negative", "maybe", "yes")
  Goto(StartOverQuestion)
endif

SayWait("what is " + $FirstSubtractionNumber + " minus " + $SecondSubtractionNumber )
sleep(1000)
$SubtractionResponse = WaitForSpeech(20, "0","1","2","3","4","5","6","7","8","9","10")
SayWait("You said " + $SubtractionResponse)
if ($SubtractionResponse = $SubtractionAnswer )
  SayWait("Good job! Yes " + $SubtractionAnswer + " is the correct answer")
  Goto(Subtraction)
ELSE
  SayWait("Sorry " + $SubtractionResponse + " is not correct. please try again.")
  sleep(1000)
  Goto(subtraction_loop)
endif


  # If MathResponse was multiplication.

:Multiplication
$FirstMultiplicationNumber = GetRandomUnique(1,5)
$SecondMultiplicationNumber = GetRandomUnique(0,5)
$MultiplicationAnswer = $FirstMultiplicationNumber * $SecondMultiplicationNumber

:multiplication_loop
$QuestionNumber = $QuestionNumber + 1
if ($QuestionNumber = 6)
  SayWait("That was 5 " + $MathTypeResponse + " questions.")
  SayWait("Would you like to start over again?")
  # ptp : changed to lowercase
  $StartOverResponse = WaitForSpeech(20, "no", "affirmative", "okay", "yeah", "negative", "maybe", "yes")
  Goto(StartOverQuestion)
endif

SayWait("what is " + $FirstMultiplicationNumber + " times " + $SecondMultiplicationNumber )
sleep(1000)
$MultiplicationResponse = WaitForSpeech(20, "0","1","2","3","4","5","6","7","8","9","10","12","15","16","20","25")
SayWait("You said " + $MultiplicationResponse)
if ($MultiplicationResponse = $MultiplicationAnswer)
  SayWait("Good job! Yes " + $MultiplicationAnswer + " is the correct answer")
  Goto(multiplication)
ELSE
  SayWait("Sorry " + $MultiplicationResponse + " is not correct. please try again.")
  sleep(1000)
  goto(multiplication_loop)
endif


  # If MathResponse was division.

:Division
$FirstDivisionNumber = GetRandomUnique(2,6)
$SecondDivisionNumber = GetRandomUnique(1,2)
$DivisionAnswer = $FirstDivisionNumber / $SecondDivisionNumber

:division_loop
$QuestionNumber = $QuestionNumber + 1
if ($QuestionNumber = 6)
  SayWait("That was 5 " + $MathTypeResponse + " questions.")
  SayWait("Would you like to start over again?")
  # ptp : changed to lowercase
  $StartOverResponse = WaitForSpeech(20, "no", "affirmative", "okay", "yeah", "negative", "maybe", "yes")
  Goto(StartOverQuestion)
endif

SayWait("what is " + $FirstDivisionNumber + " divided by " + $SecondDivisionNumber )
sleep(1000)
$DivisionResponse = WaitForSpeech(20, "0","1","2","3","4","5","6","7","8","9","10","12","15","16","20","25")
SayWait("You said " + $DivisionResponse)
if ($DivisionResponse = $DivisionAnswer)
  SayWait("Good job! Yes " + $DivisionAnswer + " is the correct answer")
  goto(Division)
ELSE
  SayWait("Sorry " + $DivisionResponse + " is not correct. please try again.")
  sleep(1000)
  goto(division_loop)
endif
  # Halt()


  # Start over response

:StartOverQuestion

# ptp: compare lowercase phrases
if ($StartOverResponse = "yes")
  goto(Yes)
ELSEif ($StartOverResponse = "no")
  goto(No)
ELSEif ($StartOverResponse = "affirmative")
  goto(Yes)
ELSEif ($StartOverResponse = "okay")
  goto(Yes)
ELSEif ($StartOverResponse = "yeah")
  goto(Yes)
ELSEif ($StartOverResponse = "negative")
  goto(No)
ELSE
  goto(StartTheSquence)
endif
Return()
Halt()

:Yes
Goto(StartTheSquence)
Halt()


:No
SayWait("I enjoyed doing math with you.")
SayWait("Maybe we can do it again soon.")
HALT()

EDIT 1: Changed phrases and comparison to lowercase EDIT 2: Replaced == with = EDIT 3: Multiple loop tags e.g. :loop

PRO
USA
#4  

@HerrBall,

EZ-Script help:

Quote:

WaitForSpeech( timeOut Seconds, phrases ) Pauses and waits for one of the specified phrases to be spoken. Returns the phrase that was spoken in lowercase. Will return timeout if no word is detected in the specified timeout length. Example: WaitForSpeech(30, Yes, No) Example: $value = WaitForSpeech(30, Yes, No)

So the 1 Million dollar question: why it works on Windows 7 ?

1) I presume DJ's added the lowercase information to the documentation after finding out the behavior.

2) ARC uses the System.Speech.Recognition API (SAPI) when a sentence is recognized the SpeechRecognized event is fired with a specific arguments SpeechRecognizedEventArgs one of the properties is the Text recognized.

If you read carefully (between the lines) https://msdn.microsoft.com/en-us/library/system.speech.recognition.recognizedphrase.text(v=vs.110).aspx

Quote:

Gets the normalized text generated by a speech recognizer from recognized input.

So what is a normalized text ?

https://msdn.microsoft.com/en-us/library/system.speech.recognition.replacementtext(v=vs.110).aspx

Quote:

Speech normalization is the use of special constructs or symbols to express speech in writing.

For example, suppose that this is recognized text:

july four at twelve thirty one PM, I bought one point six kilograms of fish for fourteen dollars and six cents, at the pike place market in seattle washington nine eight one two two

This is the same text after normalization:

July 4 at 12:31 PM, I bought 1.6 kg of fish for $14.06, at the pike place market in Seattle WA 98122

So what this means ? The Speech engines makes adjustments to the recognized text and the result can be different or slight different e.g. (Lowercase)

I believe windows 7 and windows 10 handle the recognition differently.

Do you feel Lucky ?

#5  

I tried this script out, if you give a wrong answer in Subtraction, Multiplication or Division, then the rest of 5 questions are Addition questions. Is it suppose to do that?

PRO
USA
#6  

fixed script or the original script ?

What you mean wrong answer in Subtraction, Multiplication, Division ? You can only get out saying the operation or timeout.

#7  

I ran the fixed script. I then selected Division questions and it said it would ask me 5 division questions. I gave the wrong answer to one of the questions (just to see what would happen) and the rest of the 5 questions were addition questions not division questions.

PRO
USA
#8  

@Bob,

That is another bug! duplicate loop statements. I'll fix

#9  

@ptp

Thanks ... that did it! Another lesson learned ...:) Grateful for you time and help. By the way, your plugin for the cube is awesome ... fine work.

@ bhouston

No it is not supposed to do that. I have not finished the script yet. If a lot of the code is the same, I have a bad habit of coping and pasting it and then going back and making the proper changes. If that makes sense? The division part is going to give me some problems as I need for it to only ask questions that will come out in even numbers. This is a program for my grandsons (10 & 9), so it must be easy. What fun right?

PRO
USA
#10  

I fixed the last errors (EDIT 3)

#11  

That's working great now, nice script. My grand children will enjoy it.

PRO
USA
#12  

Quote:

The division part is going to give me some problems as I need for it to only ask questions that will come out in even numbers.

Try this version:


SayWait("Oh good, I love to do math")

:AskMathType

$QuestionNumber = 0

SayWait("What would you like to do, addition, subtraction, multiplication or division ?")
$MathTypeResponse = WaitForSpeech(10, "addition", "subtraction", "multiplication", "division")

if ($MathTypeResponse = "timeout")
  SayWait("I did not hear what you said.")
  SayWait("Lets start over.")
  Goto(AskMathType)
endif

SayWait("I heard you say " + $MathTypeResponse)
SayWait("Ok, I will give you 5 " + $MathTypeResponse + " math questions.")
SayWait("Lets begin.")

:AskNewQuestion

# note: returns a number between 0 and 5 (6 is not inclusive)
$FirstNumber = GetRandomUnique(0,6)
$SecondNumber = GetRandomUnique(0,6)

if ($MathTypeResponse = "addition")
  $MathOperation = "plus"
  $MathAnswer = $FirstNumber + $SecondNumber
ELSE if ($MathTypeResponse = "subtraction")
  $MathOperation = "minus"
  # to avoid negative numbers
  $FirstNumber = $FirstNumber + 5
  $MathAnswer = $FirstNumber - $SecondNumber
ELSE if ($MathTypeResponse = "multiplication")
  $MathOperation = "times"
  $MathAnswer = $FirstNumber * $SecondNumber
ELSE
  $MathOperation = "divided by"
  if ($SecondNumber = 0)
    # avoid zero division
    $SecondNumber = 1
  ELSE
    # even number
    $SecondNumber = $SecondNumber * 2
  endif
  $FirstNumber = $SecondNumber * $FirstNumber
  $MathAnswer = $FirstNumber / $SecondNumber
endif

:AskQuestion

SayWait("What is " + $FirstNumber + " " + $MathOperation + " " + $SecondNumber)
Sleep(1000)
$Response = WaitForSpeech(20, "0","1","2","3","4","5","6","7","8","9","10","12","15","16","20","25")
SayWait("You said " + $Response)

if ($Response != $MathAnswer)
  SayWait("Sorry " + $MathAnswer + " is not correct. please try again.")
  Sleep(1000)
  Goto(AskQuestion)
endif

SayWait("Good job! Yes " + $MathAnswer + " is the correct answer")

$QuestionNumber = $QuestionNumber + 1
if ($QuestionNumber < 5)
  Goto(AskNewQuestion)
endif

SayWait("That was 5 " + $MathTypeResponse + " questions.")
SayWait("Would you like to start over again ?")
$StartOverResponse = WaitForSpeech(10, "yes", "okay", "yeah", "affirmative", "no", "negative")

if ($StartOverResponse = "yes" or $StartOverResponse = "affirmative" or $StartOverResponse = "okay" or $StartOverResponse = "yeah")
  Goto(AskMathType)
endif

SayWait("I enjoyed doing math with you.")
SayWait("Maybe we can do it again soon.")


#13  

Antonn says Thanks to All for bringing this script back out.

He will use it during his School visit coming up. The kids will enjoy it.

Ron

PRO
Belgium
#14  

are there any video on this?

#15  

@ptp

I believe there is a bug in your last script (#13). Try running addition and giving the wrong answer. Or is it just me?