you want to really give your robot personality, add your own
routines to perform actions such as moving the eyebrows or
squinting the nose. You will be surprised at the number of
emotions that can be displayed.
Giving your robot the ability to speak can give your
robot personality, but giving it the ability to understand
speech can be even more powerful. With a little training and
a good microphone, Windows can transform dictation into a
Word document with an accuracy better than you might
expect. Microsoft asserts that speech recognition works only
with compatible programs, so most people don’t realize that
the system will work fine with the applications written in
many programming languages.
It is important to realize the above distinction. We are
not saying you can use speech recognition in the IDE for a
computer language because that would require the language
to be written so that verbal commands issued by the user
are trapped and dealt with appropriately. In non-compatible
programs, some commands may work properly (saying FILE,
for example, brings down the File Menu in the RobotBASIC
IDE), but there will be many things that do not work because
the program was not specifically designed to work with
The code in Figure 9 allows the user to draw randomly
sized circles and squares at random places on the screen
simply by saying the word circle or square. The user can also
determine the color to use for future images with the words
red, blue, or green. If you look carefully at the code, you will
see that it is not checking to see if the spoken text is equal
to one of our selected words. Instead, the code checks to
see if the string obtained contains one of the key words. This
is a powerful concept.
It means that you can draw a circle by saying circle, but
you can also draw a circle by saying please draw a circle.
Notice also that each IF statement is independent (there are
no ELSE statements). This means if you say draw a red circle,
then the color will be set to red, because red is contained in
the string. The circle will then be drawn because circle is
contained in the string. Notice that this sequence works
properly because the program checks for the names of the
colors before it checks for the names of the shapes.
Also notice that the program in Figure 8 will terminate
if you say either of the words stop or quit. Notice too that if
MidString had been used for these cases as well, then even
the phrases please stop or quit now would terminate the
program. Providing multiple options like this can make your
programs appear far more intelligent than they are.
The point is that you can use Windows’ speech
recognition with the input commands and functions found in
many languages as long as you take care to not use words
that represent Windows’ commands. For most robotic
applications, this should not be a severe limitation.
As this series comes to an end, we hope we have
convinced you to consider a Windows 8 tablet in your next
project. Small microcontrollers can’t offer the enormous
computing capacity, let alone the versatility or ease of
programming of a tablet PC. Combine this power with
integrated sensors, cameras, and the ability to communicate
verbally, and you will have the foundation for the robot many
hobbyists have always dreamed of building. SV
As long as you do not try to use Microsoft’s reserved
commands, the application programs created with many
languages can easily use Windows’ speech engine as an
input device. To demonstrate this, let’s look at a simple
RobotBASIC example. RobotBASIC can obtain an input string
from a user with a command such as:
When this command is executed, the user is expected to
type in a response and then press the ENTER key to indicate
they are finished. At that point, the variable A will contain
whatever was typed. If Windows’ speech recognition is
turned on before the INPUT command is executed, then
whatever is said will become the data for the variable A just
as if it were typed — even though RobotBASIC is not a
compatible program. The only problem is that the user must
say the word enter (a keyword trapped by Windows) to get
the INPUT command to finish and move on to the next
statement in the program. Notice this is no different from
having to press the ENTER key after you type text in response
to a command.
The need to say the word enter can be eliminated by
using some form of input that does not require pressing the
ENTER key. One option for that in RobotBASIC is to create an
EditBox as demonstrated by the program fragment in Figure
9. The code is commented so if you are using a different
language, just create similar actions utilizing the capabilities
of your language.
SERVO 03.2014 51
// Create a name for the edit box EditBox = "MyEditBox" // Create the box and focus on it AddEdit EditBox,100,100,500 FocusEdit EditBox repeat // create random numbers x=random(600)+100 y=random(400)+100 r=random(200)+ 50 //if the text changes, retrieve it if EditChanged (EditBox) t=ToLower(GetEdit(EditBox)) if InString(t,"blue") then SetColor Blue if InString(t,"red") then SetColor Red if InString(t,"green") then SetColor Green if InString(t,"circle") then Circle(x-r, y-r,x+r,y+r) if t="square" then Rectangle(x-r,y-r,x+r,y+r) endif until t="stop" or t="quit" Figure 9.
A zip file containing all the code from this series can be
obtained from the In the News tab at www.RobotBASIC.org.