say.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Copyright (c) 2016 PAL Robotics SL. All Rights Reserved
00004 #
00005 # Permission to use, copy, modify, and/or distribute this software for
00006 # any purpose with or without fee is hereby granted, provided that the
00007 # above copyright notice and this permission notice appear in all
00008 # copies.
00009 #
00010 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00011 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00012 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00013 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00014 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00016 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00017 #
00018 # Author:
00019 #   * Sammy Pfeiffer
00020 
00021 import sys
00022 import rospy
00023 from actionlib import SimpleActionClient
00024 # To get the type of msg we will need if we have the robot running:
00025 #   rostopic type /tts/goal
00026 #   pal_interaction_msgs/TtsActionGoal
00027 # Action servers always have a type XXXXAction
00028 # and the goals are always XXXXGoal
00029 from pal_interaction_msgs.msg import TtsAction, TtsGoal
00030 
00031 # To test your client you can use
00032 # rosrun actionlib axserver.py /tts pal_interaction_msgs/TtsAction
00033 # Which will trigger a little GUI faking the action server
00034 
00035 # The goal is just a topic so you can actually just publish on it
00036 # but it's discouraged, it would look like (remember to press TAB to get autocompletions)
00037 # 
00038 # rostopic pub /tts/goal pal_interaction_msgs/TtsActionGoal "header:
00039 #   seq: 0
00040 #   stamp:
00041 #     secs: 0
00042 #     nsecs: 0
00043 #   frame_id: ''
00044 # goal_id:
00045 #   stamp:
00046 #     secs: 0
00047 #     nsecs: 0
00048 #   id: ''
00049 # goal:
00050 #   text:
00051 #     section: ''
00052 #     key: ''
00053 #     lang_id: ''
00054 #     arguments:
00055 #     - section: ''
00056 #       key: ''
00057 #       expanded: ''
00058 #   rawtext:
00059 #     text: 'I like talking to people'
00060 #     lang_id: 'en_GB'
00061 #   speakerName: ''
00062 #   wait_before_speaking: 0.0"
00063 
00064 if __name__ == '__main__':
00065     rospy.init_node('say_something')
00066     # If the user adds some input, say what he wrote
00067     if len(sys.argv) > 1:
00068         text = ""
00069         for arg in sys.argv[1:]:
00070             text += arg + " "
00071     # If not, just say a sentence
00072     else:
00073         text = "I like talking to people"
00074 
00075     rospy.loginfo("I'll say: " + text)
00076     # Connect to the text-to-speech action server
00077     client = SimpleActionClient('/tts', TtsAction)
00078     client.wait_for_server()
00079     # Create a goal to say our sentence
00080     goal = TtsGoal()
00081     goal.rawtext.text = text
00082     goal.rawtext.lang_id = "en_GB"
00083     # Send the goal and wait
00084     client.send_goal_and_wait(goal)


say_something
Author(s):
autogenerated on Fri Aug 26 2016 13:20:22