All Tutorials / Steve G / Speech recognition tutorial

Speech recognition tutorial

Step 8. Example Script for using Speech Recognition.

There are some Speech Recognition examples that can be found within EZ Builder itself. These show different ways to use the speech recognition control. To find these examples...

1.) Open up EZ-Builder.

2.) With the "File" tab clicked in the menu ribbon, click on "Open".

User-inserted image


3.) Then click on "Examples".

User-inserted image


4.) Double click on "EZ-Script Examples" and search through the projects related to Speech Recognition, and click "Open" to open the project example on EZ Builder.

User-inserted image

User-inserted image


Below, is an example you can use that uses the basics of the speech recognition control, which plays the game "Rock, Paper, Scissors".

1) Add a "Speech Synthesis" control to an EZ-Builder project.Then set the voice you wish to use.


2) Then add a "Speech Recognition" control.


3) In the "Speech Recognition" control, you will need to add 4 new phrases and commands. Open the configuration menu (gear icon) on the speech rec control and type the in four new phrases in the "Phrase" list as follows...

lets play rock paper scissors
rock
paper
scissors


4) In the first phrase line, click on the little pencil icon on the "Command" line to the left of the phrase, add the following script...

Code:

ControlCommand("Speech Recognition", PauseOn)
sleep(1000)
saywait("Okay then. That sounds like fun. You start.")
ControlCommand("Speech Recognition", PauseOff)




5) In the second phrase line, "Rock", click on the "Command" pencil icon and add...

Code:

#rock
ControlCommand("Speech Recognition", PauseOn)


$rock = GetRandom(0,2)

if($rock = 0)
sleep(1000)
Saywait("Rock. That is a tie. Let's try that again.")
elseif($rock = 1)
sleep(1000)
Saywait("Paper. Paper, wraps Rock. So, I win.")
elseif($rock = 2)
sleep(1000)
Saywait("Scissors. Rock, blunts Scissors. Well done. You win.")
endif
sleep(2000)
ControlCommand("Speech Recognition", PauseOff)




6) Then in the "Paper" phrase line...

Code:

#paper
ControlCommand("Speech Recognition", PauseOn)

$paper = GetRandom(0,2)

if($paper = 0)
sleep(1000)
Saywait("Rock. Paper, wraps Rock. You are good at this. Well done.")
elseif($paper = 1)
sleep(1000)
Saywait("I guessed paper too. That makes it a tie. Let's try again.")
elseif($paper = 2)
sleep(1000)
Saywait("Scissors. Scissors, cut Paper, so, I beat you that time. Unlucky.")
endif
sleep(2000)
ControlCommand("Speech Recognition", PauseOff)




7) And finally, the "Scissors" phrase line...

Code:

#scissors
ControlCommand("Speech Recognition", PauseOn)

$scissors = GetRandom(0,2)

if($scissors = 0)
sleep(1000)
Saywait("Rock. Rock, blunts Scissors. I win. You are not very good at this.")
elseif($scissors = 1)
sleep(1000)
Saywait("Paper. Scissors, cut Paper. Nicely played. Let's try again.")
elseif($scissors = 2)
sleep(1000)
Saywait("Scissors. That makes it a tie breaker. Let's see if we can do better.")
endif
sleep(2000)
ControlCommand("Speech Recognition", PauseOff)




8) Now Click "Save" to save the changes made in the speech recognition control.


9) Now plug in your headset or microphone and say to your robot "Lets play rock, Paper, Scissors.", and enjoy the game.

For more information on adding to the scripts above, click the link below for more details.

SpeechRecognition games

Enjoy.