def button_cb(self): self.textFeedback.clear() value = self.textSend.toPlainText() goal = TtsGoal() goal.rawtext.text = str(value) goal.rawtext.lang_id = "EN" goal.wait_before_speaking = float(self.interval_slider.value()) / 10 self.client.send_goal(goal, feedback_cb=self.feedbackCb) self.client.wait_for_result() result = self.client.get_result() self.textResult.setPlainText(str(result))
def button_cb(self): self.textFeedback.clear() value = self.textSend.toPlainText() goal = TtsGoal() goal.rawtext.text = str(value) goal.rawtext.lang_id = "EN" goal.wait_before_speaking = float(self.interval_slider.value())/10 self.client.send_goal(goal, feedback_cb = self.feedbackCb) self.client.wait_for_result() result = self.client.get_result() self.textResult.setPlainText(str(result))
def __init__(self, blackboard, _): super(AbstractSay, self).__init__(blackboard) self.blackboard = blackboard self.first_iteration = True text = random.choice(self.text()) self.goal = TtsGoal() self.goal.rawtext.text = text self.goal.rawtext.lang_id = "en_GB"
def talk(self, speech_in): # Create the TTS goal and send it print('\033[1;36mTIAGO: ' + speech_in + '\033[0m') tts_goal = TtsGoal() tts_goal.rawtext.lang_id = 'en_GB' tts_goal.rawtext.text = speech_in self.speech_client.send_goal(tts_goal) self.speech_client.wait_for_result()
def say(self, text): rospy.loginfo("Creating goal with text: " + text) goal = TtsGoal() goal.rawtext.text = text goal.rawtext.lang_id = 'en_GB' rospy.loginfo("Sending goal!") self.tts_ac.send_goal_and_wait(goal) rospy.loginfo("We are done!")
def talk(self, speech_in): # Create the TTS goal and send it print('\033[1;36mTIAGO: ' + speech_in + '\033[0m') speech_engine = pyttsx.init() speech_engine.say(speech_in) speech_engine.runAndWait() tts_goal = TtsGoal() tts_goal.rawtext.lang_id = 'en_GB' tts_goal.rawtext.text = speech_in self.tts_client.send_goal(tts_goal)
def tts_callback(self, msg): # Connect to the text-to-speech action server client = SimpleActionClient('/tts', TtsAction) rospy.loginfo("SPEECH TTS NODE: Waiting for the server") if client.wait_for_server(timeout = rospy.Duration(2)): # Create a goal to say our sentence goal = TtsGoal() goal.rawtext.text = msg.data goal.rawtext.lang_id = "en_GB" # Send the goal and wait client.send_goal_and_wait(goal)
def tts_with_state_callback(self, msg): if self.states == {}: self.read_states() # Connect to the text-to-speech action server client = SimpleActionClient('/tts', TtsAction) rospy.loginfo("SPEECH TTS NODE: Waiting for the server") if client.wait_for_server(timeout = rospy.Duration(2)): # Create a goal to say our sentence goal = TtsGoal() goal.rawtext.text = self.states[msg.state] goal.rawtext.lang_id = self.language # Send the goal and wait client.send_goal_and_wait(goal)
def process_word(req): text = req.x rospy.loginfo("I'll say: " + text) # Connect to the text-to-speech action server client = SimpleActionClient('/tts', TtsAction) client.wait_for_server() # Create a goal to say our sentence goal = TtsGoal() goal.rawtext.text = text goal.rawtext.lang_id = "en_GB" # Send the goal and wait client.send_goal_and_wait(goal) return 1
128: 'TTS_EVENT_FINISHED_PLAYING_SENTENCE' }[event] def feedbackCb(feedback): print("event type: " + event(feedback.event_type)) print("timestamp: " + str(feedback.timestamp)) print("current word: " + feedback.text_said) print("next word: " + feedback.next_word) print("-") if __name__ == '__main__': rospy.init_node('tts_client') client = actionlib.SimpleActionClient('tts_to_soundplay', TtsAction) rospy.loginfo("Waiting for Server") client.wait_for_server() rospy.loginfo("Reached Server") goal = TtsGoal() while not rospy.is_shutdown(): text = raw_input("Enter sentence: ") print("---") goal.rawtext.text = text goal.rawtext.lang_id = "NL" client.send_goal(goal, feedback_cb=feedbackCb) client.wait_for_result() res = client.get_result() print("text: " + res.text) print("warning/error msgs: " + res.msg) print("---")
def identifyStatus(self, table_index): # TODO: move to individual action file rospy.loginfo('Identifying the status of: %s' % self.locations_order[int(table_index)]) # Step 1: Look down to see the table # Wait for the play motion server to come up and send goal self.play_motion_client.wait_for_server(rospy.Duration(15.0)) pose_goal = PlayMotionGoal() pose_goal.motion_name = "look_down" pose_goal.skip_planning = True self.play_motion_client.send_goal(pose_goal) rospy.loginfo('Looking down goal sent') rospy.sleep(4) # Step 2: Take a picture of the table surface # Wait for recognition action server to come up and send goal self.object_recognition_client.wait_for_server(rospy.Duration(15.0)) recognition_goal = count_objectsGoal() recognition_goal.image_topic = "/xtion/rgb/image_raw" recognition_goal.confidence = 0.3 recognition_goal.nms = 0.3 self.object_recognition_client.send_goal(recognition_goal) rospy.loginfo('Recognition goal sent') # Waits for the server to finish performing the action. rospy.loginfo('Waiting for the detection result...') self.object_recognition_client.wait_for_result() # Prints out the result of executing the action surfaceObjects_result = self.object_recognition_client.get_result() print('{0} cups {1} bowls'.format(surfaceObjects_result.cup, surfaceObjects_result.bowl)) # Step 3: Check the table surface for items # Wait for the table status action server to come up and send goal self.table_status_client.wait_for_server(rospy.Duration(15.0)) status_goal = TableStatusGoal() status_goal.num_of_reads = 5 self.table_status_client.send_goal(status_goal) rospy.loginfo('Check table status goal sent') # Waits for the server to finish performing the action. rospy.loginfo('Waiting for the status result...') self.table_status_client.wait_for_result() # Print the table status status_result = self.table_status_client.get_result() rospy.loginfo( 'PclCheck result of %s is %s' % (self.locations_order[int(table_index)], status_result.status)) # Step 4: Get head and torso back to default pose_goal.motion_name = "back_to_default" self.play_motion_client.send_goal(pose_goal) rospy.loginfo('Default head position goal sent') rospy.sleep(4) # Step 4: Decide on table status and publish it to the sound server # Create a tts goal tts_goal = TtsGoal() tts_goal.rawtext.lang_id = 'en_GB' foundConsumable = False clean = False if surfaceObjects_result.cup or surfaceObjects_result.bowl > 0: foundConsumable = True if status_result.status == "clean": clean = True if not foundConsumable and clean: result = 'The status of the {0} is Clean'.format( self.locations_order[int(table_index)]) else: result = 'The status of the {0} is Dirty'.format( self.locations_order[int(table_index)]) rospy.loginfo(result) tts_goal.rawtext.text = result self.speech_client.send_goal(tts_goal) rospy.sleep(1) self.running = False
def talk_to_me(words): #creates the ts goal and sends it off to be spoken ttg = TtsGoal() ttg.rawtext.text = words.data ttg.rawtext.lang_id = "en_GB" client.send_goal_and_wait(ttg)
def talk(self, speech_in): print('\033[1;36mTIAGO: ' + speech_in + '\033[0m') tts_goal = TtsGoal() tts_goal.rawtext.lang_id = 'en_GB' tts_goal.rawtext.text = speech_in self.speech_client.send_goal(tts_goal)
def run_pres(loc_name, level): gsender = GestureSender() ssender = SoundClient() rospy.sleep(1) if (loc_name == "secret"): play_bonus(ssender, level) return #how will this whole process deal with no internet? Need to look into the return from Watson if there's no connection #make_wavs will abort early if it can't make the files, thus find_pres_files will return None...or just get the old files! make_wavs(loc_name, level) files = find_pres_files(loc_name, level) #need to fork here, based on whether all files are found if len( files ) == 0: #missing speech: new location with no speech written yet, perhaps files = find_pres_files("default", level) if len(files) == 4: #do we start with a gesture? If the first entry of the gestures file has a time of 0.0, yes! gestures = [] with open(files[3].name, 'r') as gfile: gestures = ast.literal_eval(gfile.read()) if len(gestures) > 0: doinggest = gestures[0][1] == 0.0 else: doinggest = None ssender.stopAll() gests = len(gestures) gestures.reverse() if doinggest: #print("Firing opening gesture") curgest = gestures.pop() gsender.send_motion_free(curgest[0]) gests -= 1 ssender.playWave(files[2].name) #while presentation lists are not empty if doinggest is not None: while gests > 0: curgest = gestures.pop() rospy.sleep((curgest[1] / 1000) - 0.2) #need to account for the sleep in quitIt() if gsender.running(): gsender.quitIt() #gsender.send_motion_timeout(gestures.pop(), wavlist.pop()[1]/1000) gsender.send_motion_free(curgest[0]) gests -= 1 elif len(files) == 3: #script and gesture timings with open(files[1].name, 'r') as script: speech_srv = actionlib.SimpleActionClient("/tts", TtsAction) with open(files[3].name, 'r') as gfile: gestures = ast.literal_eval(gfile.read()) wholetext = script.read() splittext = re.split(r'[{}]', wholetext) doinggest = 1 for i in range(1, -1, 2): if (doinggest < len(gestures)): mstime = int(gestures[i][1] * 1000) else: mstime = 0 gesttag = "<mark name=\"doTrick trickName=" + splittext[ i] + " checkSafety=0\"/><break time'\"" + str( mstime) + "\">" splittext[i] = gesttag speechgoal = TtsGoal() speechgoal.rawtext.lang_id = "en_US" speechgoal.rawtext.text = reduce(lambda x, y: x + y, splittext) speech_srv.wait_for_server() speech_srv.send_goal(goal) elif len(files) == 2: with open(files[1].name, 'r') as script: #translate gesture tags in {} into <mark name="doTrick trickName=gesture checkSafety=0"/><break time="???"/> #<mark name="doTrick trickName=wave checkSafety=0"/> <break time="300ms"/> hello, my name is CHIP speech_srv = actionlib.SimpleActionClient("/tts", TtsAction) wholetext = script.read() splittext = re.split(r'[{}]', wholetext) doinggest = False for i in range(1, -1, 2): gesttag = "<mark name=\"doTrick trickName=" + splittext[ i] + " checkSafety=0\"/>" splittext[i] = gesttag speechgoal = TtsGoal() speechgoal.rawtext.lang_id = "en_US" speechgoal.rawtext.text = reduce(lambda x, y: x + y, splittext) speech_srv.wait_for_server() speech_srv.send_goal(goal) elif len(files) == 0: #nothing found! rospy.loginfo("No speech found for that location/level combination.") return else: #unknown combination; define some error maybe #play_bonus(ssender, "cantdo") return #print("Gestures complete, is the sound still going? %s"%(str(_sound_running))) while _sound_running: rospy.sleep(0.2) pass
TTS_AS = "/tts" if __name__ == '__main__': rospy.init_node('test_play_motion_from_tts_feedback_node') ac = SimpleActionClient(TTS_AS, TtsAction) rospy.loginfo("Trying to connect to: " + TTS_AS) connecting_tries = 0 while not ac.wait_for_server(rospy.Duration(2.0)) and connecting_tries < 5: rospy.logwarn("Retrying connecting to " + TTS_AS) connecting_tries += 1 if connecting_tries >= 5: rospy.logerr("Couldn't connect to " + TTS_AS) exit(0) tg = TtsGoal() tg.rawtext.text = 'I say yes <mark name="doTrick trickName=yes"/> and move my head' tg.rawtext.lang_id = "en_US" rospy.loginfo("Sending goal: " + str(tg)) ac.send_goal_and_wait(tg) rospy.loginfo("Goal sent!") # text: # section: '' # key: '' # lang_id: '' # arguments: [] # rawtext: # text: 'I say yes <mark name="doTrick trickName=yes"/> and move my head' # lang_id: 'en_US' # speakerName: ''