Award
Congratulations Rich, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Speech Recon Question?

Assistance Requested

Help Anthony XLRobots.com with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

Anthony XLRobots.com claims to have checked these sources:
 
#1

Loving the speech recognition now that I'm getting the hang of the scripting lingo. My question is this...if i ask the robot a question she will answer what I put under ( Say("") ) how do I set it up for her to have multiple random responses to that one question. Also is there a limit to how many Say commands can be enetred into the voice recognition widget?

I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.


Also, consider reviewing the Learn section for informative lessons and activities. Check it out!


#2

First, I will say to use SayWait rather than Say, this will pause the script until she is finished talking.

To have her answer with one of a few responses is pretty simple, I used something similar in Jarvis with his colour picking script. It's all about IFs and GetRandom...

Note: All ;) should be )

Code:


# Pick a random number from 1 to 10
$response = GetRandom(1,10)

# Use response depending on random number
If($response = 1)
SayWait("response 1")
ElseIf($response = 2)
SayWait("response 2")
ElseIf($response = 3)
SayWait("response 3")
ElseIf($response = 4)
SayWait("response 4")
ElseIf($response = 5)
SayWait("response 5")
ElseIf($response = 6)
SayWait("response 6")
ElseIf($response = 7)
SayWait("response 7")
ElseIf($response = 8)
SayWait("response 8")
ElseIf($response = 9)
SayWait("response 9")
ElseIf($response = 10)
SayWait("response 10")
EndIf



GetRandom(low, high) will get a random number between the low and high numbers provided.
The If/ElseIf commands check if it matches their condition and if so the code in their part of the If tree is run.

My entire Jarvis project is on the cloud, take a look at the colour picking script if you need more examples.

There is no limit to number of speech commands you can use.

Hope that helps.

#3

Another great idea!

#4

I sure thought that was lots of smiley faces!

#5

Rich,
Although this is not my project, I want to thank you for all the good advice you have contributed to us.
Steve S

#6

yes i agree, thank you. this script is fine but what if i want random answers not numbers. ex: LeXI how was your day? response 1 " I had a great day how was yours? 2 " was just sitting here,watching the paint peel." 3 say crap different day. I would like for her to randomly answer that question with 1 of the 3 choices. also I get an error on line 6 when i cut and pasted the script on top in my script widget.

#7

I'll check the script again, I didn't write it in EZ-Builder I did it from memory so that doesn't surprise me too much.

For the random answers not numbers you just need to change the text in the SayWait(""Winky parts. Rather than response 1, response 2 etc. change those to the possible answers.

I'll rewrite the script with 3 choices as you have just mentioned so hopefully it is a little clearer Smile Give me 5 minutes (I don't hang around lol).

#8

OK... The code was fine when I pasted it in, I guess the forum formatting must have threw something off for you.

As asked for, the responses below are set to one of 3 responses. Run the script a few times and you should hear a different response (unless you are really unlucky to have the same random number chosen every time).

Code:


# Pick a random number from 1 to 3
$response = GetRandom(1,3)

# Use response depending on random number
If($response = 1)
SayWait("I had a great day how was yours?")
ElseIf($response = 2)
SayWait("was just sitting here, watching the paint peel")
ElseIf($response = 3)
SayWait("same crap different day")
EndIf




For more responses, increase the GetRandom high number value (3) and add in more ElseIf($response = x) commands.


To save the forum formatting messing things up, the script is on the cloud. Download it, copy & paste or import it in.

#9

Thanks rich, your a gentlemen and a scholar.

#10

I have further code to avoid the same response twice in a row, it's similar to the blink script I have on Melvin (to avoid double blinks too often) and the turn routine on the Ping Roam script (to avoid getting stuck). If it would be of use I will convert it over to this function too.

Don't forget to mark the post as solved when it is Smile