15-494/694 Cognitive Robotics: SpeechNode Assignment
In this assignment you are going to add new functionality to
Tekkotsu's speech node. We will use this functionality when we
develop our Tic-Tac-Toe playing demo.
Understanding the SpeechNode
- You should have already read Tekkotsu
and Software Engineering so you know how to browse the online
documentation.
- Read the online documentation for the SpeechNode class.
- There are three ways to use a SpeechNode. We'll look at the most
common ones here. First, if the text is a constant, you can supply it
in the constructor call when you write your state machine:
SpeechNode("I'm going for a walk") =C=>
WalkForward(0.5) =C=>
SpeechNode("That was fun!")
Second, if you need to dynamically compute the text to be spoken
instead of using a constant, you can make your own subclass of
SpeechNode and write text to the member variable
textstream :
$nodeclass Report : SpeechNode : doStart {
textstream << "I saw " << camShS.allShapes().size()
<< " shapes.";
}
...
$statemachine{
LookForStuff =C=> Report
}
- The SpeechNode listens for an audioEGID event with a specific
source ID to know when the speech it generated has finished playing.
Then it posts a completion event.
- Read the source file
SpeechNode.h to understand how
this class is implemented.
- Note that the SpeechNode constructor takes two string
arguments: the name of the node, and (optionally) the text to be
spoken. When we make instances of SpeechNode in the state machine
language, the name for the node is inserted automatically by the state
machine compiler, so we never supply that first argument
ourselves.
New Functionality
We want to extend the SpeechNode class to provide an option to select
at random from a collection of phrases, in order to give the robot's
responses more variety and spontaneity. To implement this option
we're going to create a new constructor that takes three
arguments:
- Argument 1:
const std::string& nodename
- Argument 2:
const std::string& utterances
- Argument 3:
int repetitions
The utterance argument can take two forms. In the simplest
case it's a list of phrases separated by newline characters. In the
second case it's the name of a file containing a list of phrases
separated by newlines. We will assume that the string is a filename
if it contains no newlines and at least one period.
Each time the SpeechNode is entered it picks a new phrase. The
repetitions argument controls how phrases are selected.
If its value is -1 then the SpeechNode cycles through the
phrases in the order they are listed, wrapping around when it has run
through the entire set.
If the repetitions argument is zero, the SpeechNode picks
a phrase at random from the set provided.
If the repetitions argument is a positive number
N, the SpeechNode picks a phrase at random except that it will
not reuse a phrase that has already been chosen for one of the
previous N utterances. Obviously, N must be less than
the number of phrases supplied. If it's not, the node should give an
error message and set N to zero.
Here is a quick way to test your implementation:
startnode: MySpeechNode("Fine\n Okay\n Good\n Wonderful\n Peachy", 3)
=TM=> startnode
Every time you type "msg" in the Tekkotsu console, that generates a
blank text message event, which will fire the text message transition,
causing the state machine to leave and then immediately reenter the
SpeechNode. Listen for repetitions of each phrase.
Implementation Notes
- Copy
/usr/local/Tekkotsu/Behaviors/Nodes/SpeechNode.h to your ~/project
directory and rename the file (and the class) to MySpeechNode.
- To implement file i/o, make your node inherit from the
LoadSave class. We will not need any of the fancy
serialization features of LoadSave . All we want to do is
have it open the file and load the contents into a buffer that we can
access. You might want to look at the implementation of other classes
that use LoadSave , such as CMPackWalkMC , to
see how they work.
- To learn how to choose randomly from a list, look at the
implementation of the
RandomTrans class.
- Your code should fully adhere to Tekkotsu
coding standards.
- You should use doxygen notation for your comments. See the source file
for examples.
Hand In
This assignment should be done individually, not in teams.
When you've completed the assignment, email your source file to Dave
Touretzky.
Your solution is due on Wednesday, Feb. 3, 2016.
Back to the Cognitive Robotics home page
|