Catch few words — Listen ¶
Prerequisites: Running Actions on Pepper.
Let’s start a new project
- Start a new project, let’s call it ListenPepper.
- Robotify it and make sure it implements the QiSDK & the Robot Life Cycle.
For further details, see: Creating a robot application.
To build a PhraseSet instance, use the
Put the following code in the
Here, we define the Phrases by passing directly each text as a
In this example Pepper will be able to understand positive and negative answers,
like “yes”, “no”, “OK”, etc.
You can call
withTexts multiple times on the same
All the specified texts will be added to the PhraseSet that will
be built. This way, the content of the PhraseSet may evolve.
Let’s see now how we can use these PhraseSets to make Pepper understand the previously specified texts.
To make Pepper listen, use the Listen interface:
create it with a
We used the previously created
PhraseSets to set what phrases Pepper
will listen to.
We can now run the Listen:
If the Listen action succeeds, we will be able to access this
and make Pepper react accordingly.
For a quick test, display the heard phrase and the matched PhraseSet in the Android Logcat:
Or better, display them on Pepper’s tablet!
Let’s try it¶
The sources for this tutorial are available on GitHub.
Install and run the application.
For further details, see: Running an application.
|Choose “Catch few words”.|
Try to say “Yes” or “No”.
You should see the log “Heard phrase: yes” or “Heard phrase: no” .
If you want Pepper to listen again, the Listen must
be re-executed with the
|Choose again “Catch few words”.|
Try to say any non expected word.
When you try to say a phrase that was not contained in the PhraseSet, Pepper will not listen to it. For example, if you say “hey”, nothing will be logged.
You are now able to make Pepper listen and get information about what he heard!