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 ARI’s unboxing

  • 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 Tts. 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('<node_name>')
25        tts_client = connection()
26        goal = TtsGoal()
27        goal.rawtext.text = '<message>'
28        goal.rawtext.lang_id = '<language>'
29        tts.tts_client.send_goal_and_wait(goal)
30    except rospy.ROSInterruptException:
31        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. Here is an example to say ā€œHelloā€ in English:

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

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

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.

Next steps#