Hello World - using Python

Modified on Mon, 9 May, 2022 at 10:46 AM

TABLE OF CONTENTS


BEFORE STARTING

  • Make sure you have a robot ready to use. 
  • Make sure Python and Python SDK are installed on your computer. If it is not the case, see: Python SDK - Installation Guide.
FIRST STEP
  • Start your favorite editor, let’s say IDLE, the one automatically installed with Python.
  • Open a new window.
  • Copy and paste the following code:
    from naoqi import ALProxy
    tts = ALProxy("ALTextToSpeech", "<IP of your robot>", 9559)
    tts.say("Hello, world!")
    ../_images/helloworld_py_00.png
  • Replace <IP of your robot>by the IP of your robot.

    If you don’t know its IP address, press its Chest button, NAO will say it.

  • Save the file as a Python file.

    ../_images/helloworld_py_01.png
  • Run it.../_images/helloworld_py_02.png

RESULT

Your robot says “Hello, world!”.

HOW IT WORKS

     This script uses the say method of the ALTextToSpeech module. ALTextToSpeech is the module of NAoqi dedicated to speech. The say method makes the robot pronounce the string given in parameter.

     Let’s explain the 3 lines you wrote:

from naoqi import ALProxy

     This line imports the module ALProxy.

tts = ALProxy("ALTextToSpeech", "<IP of your robot>", 9559)

This line creates an object called tts. This object will send calls to NAOqi.

  • tts is the name we gave to the object instance (could have been myspeechmodule or speakingmodule).
  • ALProxy() is a class of objects, allowing you to have acces to all the methods of a module.
  • ALTextToSpeech is the name of the module of NAOqi we want to use.
  • IP and Port (9559) of the robot are also specified (it was not the case with Choregraphe).
tts.say("Hello, world!")

This line uses the object tts to send an instruction to the NAOqi module.

  • tts is the object we use.
  • say() is the method.
  • “Hello, world!” is the parameter.

WHAT YOU HAVE LEARNED

To make the robot do something, you have to:

  1. Import the module ALProxy.
  2. Create an object giving access to one of the NAOqi modules.
  3. Call one of its available methods.

Outside Choregraphe, IP and Port are mandatory parameters of proxy().


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article