SoftBank Robotics documentation What's new in NAOqi 2.5?

Say Hello World (DEPRECATED)

<< return to C++ examples

The aim of this example is to demonstrate how to use the specialized proxy to ALTextToSpeech. This example will make NAO say “Hello World”.

The complete example is available here sayhelloworld.zip

Source file:

sayhelloworld.cpp

/**
 * Copyright (c) 2011 Aldebaran Robotics. All Rights Reserved
 * \file sayhelloworld.cpp
 * \brief Make NAO say a short phrase.
 *
 * A simple example showing how to make NAO say a short phrase using the
 * specialized proxy ALTextToSpeechProxy.
 */


#include <iostream>
#include <alerror/alerror.h>
#include <alproxies/altexttospeechproxy.h>

int main(int argc, char* argv[])
{
  if(argc != 2)
  {
    std::cerr << "Wrong number of arguments!" << std::endl;
    std::cerr << "Usage: say NAO_IP" << std::endl;
    exit(2);
  }

  /** The desired phrase to be said. */
  const std::string phraseToSay = "Hello world";
  try
  {
    /** Create an ALTextToSpeechProxy so that we can call the say method
    * Arguments for the constructor are:
    *  - IP of the robot
    *  - port on which NAOqi is listening. Default is 9559
    */
    AL::ALTextToSpeechProxy tts(argv[1], 9559);

    /** Call the say method */
    tts.say(phraseToSay);
  }
  catch (const AL::ALError& e)
  {
    std::cerr << "Caught exception: " << e.what() << std::endl;
    exit(1);
  }
  exit(0);
}

CMakeLists.txt:

The corresponding CMakeLists.txt file is the following:

CMakeLists.txt

##
# Copyright (c) 2011 Aldebaran Robotics. All Rights Reserved.

cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR)
# Give a name to the project.
project(sayhelloworld)
# This include enable you to use qibuild framework
find_package(qibuild)

# Create an executable named sayhelloworld,
# with the source file : sayhelloworld.cpp
qi_create_bin(sayhelloworld sayhelloworld.cpp)

# Tell CMake that sayhelloworld depends on ALCOMMON and ALPROXIES
# This will set the libraries to link sayhelloworld with,
# the include paths, and so on
qi_use_lib(sayhelloworld ALCOMMON ALPROXIES)