speak_tool.py
Go to the documentation of this file.
00001 #import roslib; roslib.load_manifest('rcommander_pr2')
00002 import rospy
00003 from PyQt4.QtGui import *
00004 from PyQt4.QtCore import *
00005 import rcommander.tool_utils as tu
00006 
00007 from tts_server.srv import *
00008 import smach
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', SpeakNode)
00016         self.available_voices = rospy.ServiceProxy('available_voices', AvailableVoices)
00017 
00018     def fill_property_box(self, pbox):
00019         formlayout = pbox.layout()
00020         self.text = QPlainTextEdit(pbox)
00021         self.voices_box = QComboBox(pbox)
00022         ret = self.available_voices()
00023         ret.voices.sort()
00024         for v in ret.voices:
00025             self.voices_box.addItem(v)
00026 
00027         self.reset()
00028         formlayout.addRow('&Voice', self.voices_box)
00029         formlayout.addRow('&Say', self.text)
00030 
00031     def new_node(self, name=None):
00032         if name == None:
00033             nname = self.name + str(self.counter)
00034         else:
00035             nname = name
00036         
00037         txt = str(self.text.document().toPlainText())
00038         voice = str(self.voices_box.currentText())
00039         if voice == ' ':
00040             return None
00041         return SpeakNode(nname, txt, voice)
00042 
00043     def set_node_properties(self, my_node):
00044         self.document.setPlainText(my_node.text)
00045 
00046     def reset(self):
00047         self.document = QTextDocument(self.DEFAULT_TEXT)
00048         self.layout = QPlainTextDocumentLayout(self.document)
00049         self.document.setDocumentLayout(self.layout)
00050         self.text.setDocument(self.document)
00051         self.voices_box.setCurrentIndex(0)
00052 
00053 
00054 class SpeakNodeSmach(smach.State): 
00055 
00056     def __init__(self, text, voice):
00057         smach.State.__init__(self, outcomes = ['done'], input_keys = [], output_keys = [])
00058         self.text = text
00059         self.voice = voice
00060 
00061     def execute(self, userdata):
00062         self.say = rospy.ServiceProxy('say', Say)
00063         self.say(self.voice, self.text)
00064         return 'done'
00065 
00066 
00067 class SpeakNode(tu.StateBase):
00068 
00069     def __init__(self, name, text, voice):
00070         tu.StateBase.__init__(self, name)
00071         self.text = text
00072         self.voice = voice
00073 
00074     def get_smach_state(self):
00075         return SpeakNodeSmach(self.text, self.voice)
00076 
00077 
00078 #class SpeakNode(smach.State, tu.StateBase): 
00079 #
00080 #    def __init__(self, name, text, sound_client=None):
00081 #        self.name = name
00082 #        self.text = text
00083 #        self.sound_client = sound_client
00084 #        self.__init_unpicklables__()
00085 #
00086 #    def execute(self, userdata):
00087 #        self.sound_client.say(self.text)#, 'voice_kal_diphone')
00088 #        return 'done'
00089 #
00090 #    def __init_unpicklables__(self):
00091 #        tu.StateBase.__init__(self, self.name)
00092 #        smach.State.__init__(self, outcomes = ['done'], input_keys = [], output_keys = [])
00093 #        if self.sound_client == None:
00094 #            self.sound_client = SoundClient()
00095 #
00096 #    def __getstate__(self):
00097 #        state = tu.StateBase.__getstate__(self)
00098 #        my_state = [self.name, self.text]
00099 #        return {'state_base': state, 'self': my_state}
00100 #
00101 #    def __setstate__(self, state):
00102 #        tu.StateBase.__setstate__(self, state['state_base'])
00103 #        self.name, self.text = state['self']
00104 #        self.__init_unpicklables__()
00105 
00106 
00107 


rcommander_pr2_gui
Author(s): Hai Nguyen
autogenerated on Thu Dec 12 2013 12:09:58