Make Pepper know everything using Wikipedia
In this tutorial, I explain the code available on the Github PepperWiki. You can download it for free on Github.
PepperWiki is a simple Pepper/Nao app that uses STT (Speech To Text) and Wikipedia to answer any question the user asks.
At the time of writing, the app supports English and Japanese.
This app demonstrates how to do a few common things when creating Choregraphe projects for Pepper or Nao:
- Using the STT from the Dialog and qiChat
- Using Pypi packages to add new functions to your robot
- One way of communicating between qiChat and Python scripts
Setting up the app
Look at the PepperWiki project page
to see how to make the setup. You will need Python, pypi and a command line tool.
Importing Wikipedia module from Choregraphe box
Once you setup everything, let's open the project, and first look at the "wikipedia search" box. To be able to import the wikipedia module from a Python script box, I add my package's "lib" folder to the Python path:
behaviorPath = ALProxy("ALFrameManager").getBehaviorPath(self.behaviorId)
self.path = os.path.join(behaviorPath, '../lib')
if self.path not in sys.path:
Note that you then have to use "import wikipedia" in all the functions that actually use the module (it also works from any other Python script box of your project once you added the above function was executed).
Using Speech-To-Text (STT) to recognize anything
Note that Nao users don't have access to STT by default. Please contact Aldebaran Sales to learn how to have access to STT with your Nao.
Also a warning:
STT can be used, but the results in 2014 are not always good. Speech Recognition and Dialog performances are much better if you prepare a set of questions that the robot should be able to answer.
Run the app to test it now. The robot doesn't say anything, and waits for you to give him a keyword. For example, try saying "rabbit" to the robot, and see what comes out.
Here the Dialog looks just like this.
To force the use of STT, I use the *
(star) sign. Since I also want to reuse the user input, I use the _
(underscore) sign. Then, from the robot output, I can use $1 to use what the robot understood. Finally, I use $onKeyword=
to trigger the output of the box. See Dialog and Choregraphe Documentations for more details on those patterns.
Because I chose the onKeyword
output "nature" to be "onStopped", the Dialog is actually stopped while the robot queries Wikipedia and talks. Then the Dialog restarts when the robot finished reading the Wikipedia summary.
In the Wikipedia search box, the keyword returned by the Dialog is used for a search (using the wikipedia Python API), and then I send the page summary to be read by the Say Text box. Nothing complicated here once you know how to import your Python packages.
That's it! Now your robot is capable of talking about anything on Wikipedia! You can use this technique with pretty much any webservice (Yahoo weather, stock options, etc...). There are no limits to what Pepper or Nao can talk about!