Make Pepper know everything using Wikipedia

by Sebastien
(About-Robots)

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:


import os
import sys
behaviorPath = ALProxy("ALFrameManager").getBehaviorPath(self.behaviorId)
self.path = os.path.join(behaviorPath, '../lib')
if self.path not in sys.path:
sys.path.insert(0, self.path)
import wikipedia


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.

u:(_*) $onKeyword=$1

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.

Wikipedia queries


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!

Comments for Make Pepper know everything using Wikipedia

Average Rating starstarstarstarstar

Click here to add your own comments

Mar 30, 2017
Rating
starstarstarstarstar
SSL in simulator vs robot NEW
by: Andy

It seems to me that the version of Python within the Choregraphe robot simulator has no SSL support, while I can make SSL requests from the actual robot.

Is there a way to enable SSL in the simulator?

Mar 09, 2017
Rating
starstarstarstarstar
ImportError: No module named wikipedia NEW
by: Pete

Hello Sebastien,

First and foremost, great app and thank you for sharing it!

I have followed your instructions, but I'm facing the same problem as (it seems) many before me that the 'wikipeadia search' box gives an import error "No module named wikipedia". Could you or someone else who has solved this problem offer some direction on how to overcome it? It seems that modules installed through virtualenv (and pip in there) are just not visible for the Choregraphe project...

Thanks for your help,
Pete

Jan 25, 2017
Rating
starstarstarstarstar
ImportError: No module named wikipedia NEW
by: André

don't act, I finally succed in debugging

Jan 24, 2017
Rating
starstarstarstarstar
ImportError: No module named wikipedia NEW
by: André

Dear Sebastien,
I have carefully followed the installation process but still have the module error.
I have checked, the wikipedia module is well listed when in python window I ask to list the complete modules list. Any idea ?? thx
André

Nov 10, 2016
Rating
starstarstarstarstar
Advice for the even better NEW
by: Anonymous

Prefer the documented way to access the behavior's local filesystem: http://doc.aldebaran.com/2-5/software/choregraphe/objects/python_script.html#script-filesystem
It says to use: self.behaviorAbsolutePath()

Beware that if have several behaviors import different versions of the same Python module, only the version of the first one to be imported will be available.

Aug 31, 2016
Rating
starstarstar
As written, this did not work for me. NEW
by: Anonymous

Using the code as is I kept getting package wikipedia not found. Although I can see in the package of the application that the lib directory does exist.

I changed the onload method to this:

def onLoad(self):
#put initialization code here
import os
import sys
behaviorPath = self.session().service("ALFrameManager").getBehaviorPath(self.behaviorId)
head, tail = os.path.split(behaviorPath)
self.path = head + '/lib'
if self.path not in sys.path:
sys.path.append(self.path)

which allowed the example to work.

Aug 26, 2016
Rating
starstarstarstar
head soccer NEW
by: head soccer

http://www.head-soccer.com
http://www.head-soccer2.com
http://www.big-headsoccer.com
http://www.big-headfootball.com/
http://www.big-headbasketball.com/


Jan 08, 2016
Rating
starstarstarstarstar
script change for wolframalpha NEW
by:

Hi,

I want to use wolframalpha package (pypi.python.org/pypi/wolframalpha) for NAO robot.
Could you please help me with this?

how should I change the following script:

import os
import sys
behaviorPath = ALProxy("ALFrameManager").getBehaviorPath(self.behaviorId)
self.path = os.path.join(behaviorPath, '../lib')
if self.path not in sys.path:
sys.path.insert(0, self.path)
import wikipedia

Oct 27, 2015
Rating
starstarstarstarstar
Thanks NEW
by: Adrienc

Hi Sébastien,
sorry for my message, because maybe one week later, I resolve my problems.
Your code run perfectly and show me the way to parse any website with BS4.
Thanks a lot.

Oct 27, 2015
Rating
starstarstarstarstar
re: SSLError NEW
by: Sebastien

Hello Adrien,

It works on my PC's virtual robot.

It shouldn't depend on your PC's setting because the Virtual Robot uses it's own Python executable.

Aug 04, 2015
Rating
starstarstarstarstar
Python version NEW
by: Adrienc

Hi Sebastien,
I have install Pepperwiki all has you say but I finally have an SSLError on Choregraphe :

File "C:\Users\adrien\AppData\Roaming\choregraphe\VirtualRobot-25347f\data\PackageManager\apps\.lastUploadedChoregrapheBehavior\behavior_1\../lib\requests\adapters.py", line 431, in send
raise SSLError(e, request=request)
SSLError: Can't connect to HTTPS URL because the SSL module is not available.

Maybe it's because of the Python 2.7.X version.
Can you tell me your version or which SSL module you use?

Anyway, your project is very useful for me. Thx

Have a good day
adriencerbelaud@hotmail.com

Click here to add your own comments

Join in and write your own page! It's easy to do. How? Simply click here to return to Pepper Robot Programming Tutorials.

Search The site