../_images/ari-icon.png

Tutorial: ARI’s “Hello world”#

🏁 Goal of this tutorial

By the end of this tutorial, you will know how to make ARI says a message in the language that you want with it voice.

Pre-requisites#

  • You should first have completed Getting started with your robot.

  • This tutorial requires you to have Python3 installed.

  • This tutorial requires you to have ROS noetic installed, if you don’t have it, use this link. Choose the desktop-full version of ROS, to have access to visual tools like rviz.

  • This tutorial requires you to have pal_msgs package installed to use the TTS functionalities. If you don’t have it, you will have to clone it (here is the GitHub page).

The code#

 1#!/usr/bin/env python
 2# -*- coding: utf-8 -*-
 3
 4# System imports
 5import sys
 6import random
 7
 8# ROS imports
 9import rospy
10
11#actions
12from actionlib import SimpleActionClient
13from pal_interaction_msgs.msg import TtsAction, TtsGoal
14
15
16def connection():
17    tts_client = SimpleActionClient('/tts', TtsAction)
18    tts_client.wait_for_server()
19    return tts_client
20
21
22if __name__ == '__main__':
23    try:
24        rospy.init_node('say_hello')
25        print("Requesting speech action")
26        tts_client = connection()
27        goal = TtsGoal()
28        goal.rawtext.text = 'Hello'
29        goal.rawtext.lang_id = 'en_GB'
30        tts_client.send_goal_and_wait(goal)
31        print("Finished")
32    except rospy.ROSInterruptException:
33        print("Abruptly finished!")

The code explained#

The first method that you created is connection(), here you connect the TtsAction using the SimpleActionClient() function.

Then you wait until the server is connected with the wait_for_server().

Once you have TtsAction connected to the server, in the main function, you need to start the node that you are running, so you use the rospy.init_node() function with the name that you have put on your node.

Next step is to start a TtsGoal with the message and the language that you want the robot to talk. In this example we are saying “Hello” in English:

goal.rawtext.text = 'Hello'
goal.rawtext.lang_id = 'en_GB'

If you want to choose another language you have to put it in RFC 3066 format, here is a link to the reference.

Note

Check that the selected language is installed on PAL’s robots. You can see the available language list from the Default TTS language dropdown in the Webcommander Settings Tab (you do not have to change the default language)

For finishing the tutorial you will have to send the message, you need to do it with the send_goal_and_wait() function. This, sends the message and also waits until ARI has finished saying the message to keep running the script.

Note

Check that the PAL’s robots playback volume is sufficiently loud. You can check it from Settings Tab

Next steps#