speak_tool.py
Go to the documentation of this file.
00001 import roslib; roslib.load_manifest('rcommander')
00002 import rospy
00003 from PyQt4.QtGui import *
00004 from PyQt4.QtCore import *
00005 import tool_utils as tu
00006 from sound_play.libsoundplay import SoundClient
00007 import smach
00008 
00009 
00010 class SpeakTool(tu.ToolBase):
00011 
00012     DEFAULT_TEXT = 'hello world'
00013 
00014     def __init__(self, rcommander):
00015         tu.ToolBase.__init__(self, rcommander, 'speak', 'Speak')
00016         self.sound_client = SoundClient()
00017 
00018     def fill_property_box(self, pbox):
00019         formlayout = pbox.layout()
00020         self.text = QLineEdit(pbox)
00021         self.text.setText(SpeakTool.DEFAULT_TEXT)
00022         formlayout.addRow('&Say', self.text)
00023         
00024 
00025     def _create_node(self, name=None):
00026         if name == None:
00027             nname = self.name + str(self.counter)
00028         else:
00029             nname = name
00030         return SpeakNode(nname, str(self.text.text()), sound_client=self.sound_client)
00031 
00032     def _node_selected(self, my_node):
00033         self.text.setText(my_node.text)
00034 
00035     def reset(self):
00036         self.text.setText(SpeakTool.DEFAULT_TEXT)
00037 
00038 
00039     def get_smach_class(self):
00040         return SpeakNode
00041 
00042 
00043 class SpeakNode(smach.State, tu.StateBase): 
00044 
00045     def __init__(self, name, text, sound_client=None):
00046         self.name = name
00047         self.text = text
00048         self.sound_client = sound_client
00049         self.__init_unpicklables__()
00050 
00051     def execute(self, userdata):
00052         self.sound_client.say(self.text, 'voice_kal_diphone')
00053         return 'done'
00054 
00055     def __init_unpicklables__(self):
00056         tu.StateBase.__init__(self, self.name)
00057         smach.State.__init__(self, outcomes = ['done'], input_keys = [], output_keys = [])
00058         if self.sound_client == None:
00059             self.sound_client = SoundClient()
00060 
00061     def __getstate__(self):
00062         state = tu.StateBase.__getstate__(self)
00063         my_state = [self.name, self.text]
00064         return {'state_base': state, 'self': my_state}
00065 
00066     def __setstate__(self, state):
00067         tu.StateBase.__setstate__(self, state['state_base'])
00068         self.name, self.text = state['self']
00069         self.__init_unpicklables__()
00070 
00071 
00072 


rcommander
Author(s): Hai Nguyen (haidai@gmail.com)
autogenerated on Thu Nov 28 2013 11:46:34