# SoftBank Robotics documentation What's new in NAOqi 2.8?

# Hello World 2 - using Python in Choregraphe

## Audience

Level | All beginners | Time | 5 min
OS | Linux - Windows - Mac | Preparation | 15 min

Preparation time is given for the case you have to install tools prior the tutorial.

## Before starting

- Make sure you have a robot ready to use. Otherwise, read First steps with NAO or Configuring Pepper for the first time.
- Make sure Choregraphe is installed on your computer. If it is not the case, see Installing Choregraphe suite.

## Let’s do it

Step | Action
--- | ---
| Start Choregraphe.
| Click the Connect to button and connect Choregraphe to your robot. For further details, see How to connect your NAO. Your robot appears in the Robot view.
| Right click the grey area and choose Create a new Box > Python... in the contextual menu.
| Type a name, for example: My hello world, and click the OK button.
| Double click the box. The Script editor appears.
| Add the 2 following lines: After:
    def __init__(self):
       GeneratedClass.__init__(self)
Add:
    self.tts = ALProxy('ALTextToSpeech')
After:
    def onInput_onStart(self):
        #~ self.onStopped() #~ activate output of the box
Add:
    self.tts.say("Hello young Padawan")
The Script should look like this.
| Click the Play button.
| Double click the onStart input of your box.

## Result

Your robot says “Hello, young Padawan”. In the meantime, the Robot view displays the message.

## 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.
For further details about this module, see ALTextToSpeech.

Let’s explain the 2 lines you wrote:

    self.tts = ALProxy('ALTextToSpeech')

This line creates an object, called tts.

- self is there to make sure tts will be available not only locally, but in all the code blocks of the script.
- 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.

    self.tts.say("Hello young Padawan")

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

- self.tts is the object we use.
- say() is the method.
- “Hello young Padawan” is the parameter.

## What you have learned

To make the robot do something, you have to:

1. Create an object giving access to one of the NAOqi modules, then
2. call one of its available methods.

You can manually start the execution of a box by double-clicking on its on Start input.

## To go further

- If you are not familiar with Python language, you should go through the tutorial: http://www.python.org.
- To learn how to create scripts in Choregraphe, see: Scripting Python boxes.
- To discover all the available modules and methods, see: NAOqi APIs.

## Next step

What about creating your first dialog topic?
Try to create Dialog using Choregraphe editor: Hello World 3 - using Dialog topic in Choregraphe.
Glossary Site map Index Support Contact Legal Notices