Go to the documentation of this file.00001
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
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107