def checkNodeExistence(stat): global nodes, speak_text result = {} have_dead = False for n in nodes: res = ping(n, max_count=1, verbose=False) result[n] = res if not res: have_dead = True if have_dead: stat.summary( diagnostic_msgs.msg.DiagnosticStatus.ERROR, "dead nodes: " + ", ".join([n for (n, res) in result.items() if not res])) if speak: sound = SoundRequest() sound.sound = SoundRequest.SAY sound.command = SoundRequest.PLAY_ONCE if hasattr( SoundRequest, 'volume' ): # volume is added from 0.3.0 https://github.com/ros-drivers/audio_common/commit/da9623414f381642e52f59701c09928c72a54be7#diff-fe2d85580f1ccfed4e23a608df44a7f7 sound.volume = 1.0 if speak_text: sound.arg = speak_text else: sound.arg = " ".join(nodes).replace("/", "").replace( "_", " ") + " is dead" g_robotsound_pub.publish(sound) else: stat.summary(diagnostic_msgs.msg.DiagnosticStatus.OK, "every node is alive") for n, res in result.items(): stat.add(n, res) return stat
def checkNodeExistence(stat): global nodes, speak_text result = {} have_dead = False for n in nodes: res = ping(n, max_count=1, verbose=False) result[n] = res if not res: have_dead = True if have_dead: stat.summary( diagnostic_msgs.msg.DiagnosticStatus.ERROR, "dead nodes: " + ", ".join([n for (n, res) in result.items() if not res])) if speak: sound = SoundRequest() sound.sound = SoundRequest.SAY sound.command = SoundRequest.PLAY_ONCE if speak_text: sound.arg = speak_text else: sound.arg = " ".join(nodes).replace("/", "").replace( "_", " ") + " is dead" g_robotsound_pub.publish(sound) else: stat.summary(diagnostic_msgs.msg.DiagnosticStatus.OK, "every node is alive") for n, res in result.items(): stat.add(n, res) return stat
def checkNodeExistence(stat): global nodes, speak_text result = {} have_dead = False for n in nodes: res = ping(n, max_count=1, verbose=False) result[n] = res if not res: have_dead = True if have_dead: stat.summary( diagnostic_msgs.msg.DiagnosticStatus.ERROR, "dead nodes: " + ", ".join([n for (n, res) in result.items() if not res]), ) if speak: sound = SoundRequest() sound.sound = SoundRequest.SAY sound.command = SoundRequest.PLAY_ONCE if speak_text: sound.arg = speak_text else: sound.arg = " ".join(nodes).replace("/", "").replace("_", " ") + " is dead" g_robotsound_pub.publish(sound) else: stat.summary(diagnostic_msgs.msg.DiagnosticStatus.OK, "every node is alive") for n, res in result.items(): stat.add(n, res) return stat
def say(self, text_msg): msg = SoundRequest() msg.sound = SoundRequest.SAY msg.command = SoundRequest.PLAY_START msg.arg = text_msg self.sound_pub.publish(msg) time.sleep(2)
def speak(string): global speak_pub rospy.logerr(string) msg = SoundRequest() msg.sound = SoundRequest.SAY msg.command = SoundRequest.PLAY_ONCE msg.arg = string speak_pub.publish(msg)
def gui(self, displayType, text, choices, timeout): if self.use_speech: req = SoundRequest() req.sound = SoundRequest.SAY req.command = SoundRequest.PLAY_ONCE req.arg = text self.sound_publisher.publish(req) return self._gui(displayType, text, choices, timeout)
def trig(): g_odom_init_trigger_pub.publish(Empty()) # Say something sound = SoundRequest() sound.sound = SoundRequest.SAY sound.command = SoundRequest.PLAY_ONCE sound.arg = "Robot stans on the ground." g_robotsound_pub.publish(sound)
def speak(self, speak_str): rospy.logerr("[%s] %s", self.__class__.__name__, speak_str) if self.speak_enabled: msg = SoundRequest() msg.sound = SoundRequest.SAY msg.command = SoundRequest.PLAY_ONCE msg.arg = speak_str self.speak_pub.publish(msg)
def play_sound(self, key, timeout=5.0): if self.act_sound is None: return req = SoundRequest() req.sound = SoundRequest.PLAY_FILE req.command = SoundRequest.PLAY_ONCE req.arg = self.signals[key] goal = SoundRequestGoal(sound_request=req) self.act_sound.send_goal_and_wait(goal, rospy.Duration(timeout))
def play_sound(self): req = SoundRequest() req.sound = 3 req.command = 1 req.volume = 1. self.sound_pub.publish(req)
def decir(oracion): voice = SoundRequest() voice.sound = -3 voice.command = 1 voice.volume = 1.0 voice.arg = oracion #voice.arg2='voice_el_diphone' pub_voice.publish(voice)
def main(): global bumper global direction print("Initialisation") rospy.init_node('scenario') rospy.sleep(0.5) rospy.Subscriber("/mobile_base/events/bumper", BumperEvent, bumper) pub1 = rospy.Publisher("/mobile_base/commands/velocity", Twist) pub2 = rospy.Publisher("/robotsound", SoundRequest) pub3 = rospy.Publisher("/mobile_base/commands/sound", Sound) cmd = Twist() sound = SoundRequest() bip = Sound() sound.arg = "/opt/ros/indigo/share/sound_play/sounds/R2D2a.wav" sound.sound = -2 sound.command = 1 bip.value=4 while not rospy.is_shutdown(): duree= 1+random.random()*5 tempsActuel = rospy.get_time() stop = rospy.get_time() + duree while (rospy.get_time() < stop): if bumper==0: cmd.linear.x = 0 cmd.angular.z = 0 pub2.publish(sound) rospy.sleep(0.5) pub1.publish(cmd) rospy.sleep(5) cmd.linear.x = -0.2 cmd.angular.z = -2 cmd.angular.z = -2 pub1.publish(cmd) rospy.sleep(0.5) bumper == 3 elif bumper==1: cmd.linear.x = -0.2 pub1.publish(cmd) pub3.publish(bip) rospy.sleep(0.5) bumper == 3 elif bumper==2: cmd.linear.x = 0 cmd.angular.z = 2 pub1.publish(cmd) rospy.sleep(0.5) bumper== 3 else: cmd.linear.x = 0.2 cmd.angular.z = 0 pub1.publish(cmd) if bumper>2: bumper = math.floor(random.random()*10) print("The End") rospy.spin()
def do_GET(self): global publisher query_string = urlparse.urlparse(self.path).query parameters = urlparse.parse_qs(query_string) if 'type' not in parameters: try: if self.path == "/": self.path = "/index.html" elif self.path == "favicon.ico": return elif self.path == "map.gif": # Draw robot position on map and send image back draw_map() return fname,ext = os.path.splitext(self.path) print "Loading file", self.path with open(os.path.join(os.getcwd(),self.path[1:])) as f: self.send_response(200) self.send_header('Content-type', types_map[ext]) self.end_headers() self.wfile.write(f.read()) return except IOError: self.send_error(404) return command_type = parameters['type'][0] if command_type == 'base': base_x = 0.0 if 'x' in parameters: base_x = float(parameters['x'][0]) base_y = 0.0 if 'y' in parameters: base_y = float(parameters['y'][0]) base_z = 0.0 if 'z' in parameters: base_z = float(parameters['z'][0]) twist_msg = Twist() twist_msg.linear = Vector3(base_x, base_y, 0.0) twist_msg.angular = Vector3(0.0, 0.0, base_z) mobile_base_velocity.publish(twist_msg) elif command_type == 'speak': text = parameters['say'][0] sr = SoundRequest() sr.sound = -3 #Say text sr.command = 1 #Play once sr.arg = text publisher.publish(sr) #os.system("espeak -s 155 -a 200 '" + text + "' ") # response self.send_response(204) return
def main(): global bumper global direction print("Initialisation") rospy.init_node('scenario') rospy.sleep(0.5) rospy.Subscriber("/mobile_base/events/bumper", BumperEvent, bumper) pub1 = rospy.Publisher("/mobile_base/commands/velocity", Twist) pub2 = rospy.Publisher("/robotsound", SoundRequest) pub3 = rospy.Publisher("/mobile_base/commands/sound", Sound) cmd = Twist() sound = SoundRequest() bip = Sound() sound.arg = "/opt/ros/indigo/share/sound_play/sounds/R2D2a.wav" sound.sound = -2 sound.command = 1 bip.value = 4 while not rospy.is_shutdown(): duree = 1 + random.random() * 5 tempsActuel = rospy.get_time() stop = rospy.get_time() + duree while (rospy.get_time() < stop): if bumper == 0: cmd.linear.x = 0 cmd.angular.z = 0 pub2.publish(sound) rospy.sleep(0.5) pub1.publish(cmd) rospy.sleep(5) cmd.linear.x = -0.2 cmd.angular.z = -2 cmd.angular.z = -2 pub1.publish(cmd) rospy.sleep(0.5) bumper == 3 elif bumper == 1: cmd.linear.x = -0.2 pub1.publish(cmd) pub3.publish(bip) rospy.sleep(0.5) bumper == 3 elif bumper == 2: cmd.linear.x = 0 cmd.angular.z = 2 pub1.publish(cmd) rospy.sleep(0.5) bumper == 3 else: cmd.linear.x = 0.2 cmd.angular.z = 0 pub1.publish(cmd) if bumper > 2: bumper = math.floor(random.random() * 10) print("The End") rospy.spin()
def _speak(self, sentence): req = SoundRequest() req.command = SoundRequest.PLAY_ONCE req.sound = SoundRequest.SAY req.arg = sentence req.arg2 = 'ja' req.volume = 0.8 self.speak_client.send_goal(SoundRequestGoal(sound_request=req)) self.speak_client.wait_for_result(timeout=rospy.Duration(10))
def bumper_callback(msg): if msg.data == True: sound_msg = SoundRequest() sound_msg.sound = -2 # play file sound_msg.command = 1 # play once sound_msg.arg = sound_file sound_pub.publish(sound_msg)
def sendMsg(self, snd, cmd, s, arg2=""): msg = SoundRequest() msg.sound = snd msg.command = cmd msg.arg = s msg.arg2 = arg2 self.pub.publish(msg) ## @todo this should be a warn once warns become visible on the console. if self.pub.get_num_connections() < 1: rospy.logerr("Sound command issued, but no node is subscribed to the topic. Perhaps you forgot to run soundplay_node.py");
def beep(self, key, blocking=False, **kwargs): """Play one of the beeps and boops that we know of""" if not key or key.upper() not in self.beeps: return sound = SoundRequest() sound.sound = SoundRequest.PLAY_FILE sound.command = SoundRequest.PLAY_ONCE sound.arg = self.beeps[key.upper()] self._play(sound, blocking=blocking, **kwargs)
def speak_robot(str_speech): #this doesnt work the first time - nobody knows why??? #print str_speech tmp = SoundRequest() tmp.sound = -3 tmp.command = 1 tmp.arg = str_speech tmp.arg2 = '' global voice_pub voice_pub.publish(tmp)
def stop(self): """Stop all sounds""" self.sound_client.cancel_all_goals() # Send a stop request sound = SoundRequest() sound.sound = SoundRequest.ALL sound.command = SoundRequest.PLAY_STOP sound.arg = "" self._play(sound, blocking=True)
def speak(self, sentence): if self.speech_history[sentence] + rospy.Duration(self.warn_repeat_rate) > rospy.Time.now(): return self.speech_history[sentence] = rospy.Time.now() req = SoundRequest() req.command = SoundRequest.PLAY_ONCE req.sound = SoundRequest.SAY req.arg = sentence req.arg2 = "ja" self.speak_client.send_goal(SoundRequestGoal(sound_request=req)) self.speak_client.wait_for_result(timeout=rospy.Duration(10))
def sendMsg(self, snd, cmd, s): msg = SoundRequest() msg.sound = snd msg.command = cmd msg.arg = s self.pub.publish(msg) ## @todo this should be a warn once warns become visible on the console. if self.pub.get_num_connections() < 1: rospy.logerr( "Sound command issued, but no node is subscribed to the topic. Perhaps you forgot to run soundplay_node.py" )
def trig(): global is_servo_on g_odom_init_trigger_pub.publish(Empty()) if is_servo_on is False: return # Say something sound = SoundRequest() sound.sound = SoundRequest.SAY sound.command = SoundRequest.PLAY_ONCE sound.arg = "Robot stands on the ground." g_robotsound_pub.publish(sound)
def main(): pub = rospy.Publisher('robotsound', SoundRequest, queue_size=10) rospy.sleep(0.1) msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg2 = 'voice_kal_diphone' while not rospy.is_shutdown(): msg.arg = raw_input("Enter Command: ") if msg.arg=="exit": return pub.publish(msg)
def main(): pub = rospy.Publisher('robotsound', SoundRequest, queue_size=10) rospy.sleep(0.1) msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg2 = 'voice_kal_diphone' while not rospy.is_shutdown(): msg.arg = raw_input("Enter Command: ") if msg.arg == "exit": return pub.publish(msg)
def main(): global bumper print("Lancement navigation aleatoire") rospy.init_node('navigation_aleatoire') rospy.sleep(0.5) rospy.Subscriber("/mobile_base/events/bumper", BumperEvent, bumper) pub = rospy.Publisher("/mobile_base/commands/velocity", Twist) pub2 = rospy.Publisher("/robotsound", SoundRequest) pub3 = rospy.Publisher("/mobile_base/commands/sound", Sound) cmd = Twist() sound = SoundRequest() sonnerie = Sound() sound.arg = "/opt/ros/indigo/share/sound_play/sounds/R2D2a.wav" sound.sound = -2 sound.command = 1 sonnerie.value= 4 while not rospy.is_shutdown(): duree= 1+random.random()*5 tempsActuel = rospy.get_time() stop = rospy.get_time() + duree while (rospy.get_time() < stop): if bumper==0: cmd.linear.x = 0 cmd.angular.z = -2 pub.publish(cmd) rospy.sleep(0.5) bumper=3 elif bumper==1: cmd.linear.x = -0.2 cmd.angular.z = 0 pub.publish(cmd) pub2.publish(sound) rospy.sleep(0.5) bumper=3 elif bumper==2: cmd.linear.x = 0 cmd.angular.z = 2 pub.publish(cmd) rospy.sleep(0.5) bumper=3 else: cmd.linear.x = 0.2 cmd.angular.z = 0 pub.publish(cmd) if bumper>2: bumper = math.floor(random.random()*10) print(sound) print("fin navigation autonome") rospy.spin() #boucle infinie tant qu'on quitte pas proprement
def main(): global bumper print("Lancement navigation aleatoire") rospy.init_node('navigation_aleatoire') rospy.sleep(0.5) rospy.Subscriber("/mobile_base/events/bumper", BumperEvent, bumper) pub = rospy.Publisher("/mobile_base/commands/velocity", Twist) pub2 = rospy.Publisher("/robotsound", SoundRequest) pub3 = rospy.Publisher("/mobile_base/commands/sound", Sound) cmd = Twist() sound = SoundRequest() sonnerie = Sound() sound.arg = "/opt/ros/indigo/share/sound_play/sounds/R2D2a.wav" sound.sound = -2 sound.command = 1 sonnerie.value = 4 while not rospy.is_shutdown(): duree = 1 + random.random() * 5 tempsActuel = rospy.get_time() stop = rospy.get_time() + duree while (rospy.get_time() < stop): if bumper == 0: cmd.linear.x = 0 cmd.angular.z = -2 pub.publish(cmd) rospy.sleep(0.5) bumper = 3 elif bumper == 1: cmd.linear.x = -0.2 cmd.angular.z = 0 pub.publish(cmd) pub2.publish(sound) rospy.sleep(0.5) bumper = 3 elif bumper == 2: cmd.linear.x = 0 cmd.angular.z = 2 pub.publish(cmd) rospy.sleep(0.5) bumper = 3 else: cmd.linear.x = 0.2 cmd.angular.z = 0 pub.publish(cmd) if bumper > 2: bumper = math.floor(random.random() * 10) print(sound) print("fin navigation autonome") rospy.spin() #boucle infinie tant qu'on quitte pas proprement
def customerLoggedIn(customer): global userId, subCamDepth, userTime, userTimeDelta, pubSound, state rospy.loginfo("user logged in") # TODO: support more than one gender. # Say welcome message soundRequest = SoundRequest() soundRequest.sound = -3 #Say text soundRequest.command = 1 #Play once soundRequest.arg = "Welcome, Mister " + customer + "!" pubSound.publish(soundRequest)
def trig(): global is_servo_on g_odom_init_trigger_pub.publish(Empty()) if is_servo_on is False: return # Say something sound = SoundRequest() sound.sound = SoundRequest.SAY sound.command = SoundRequest.PLAY_ONCE if hasattr(SoundRequest, 'volume'): # volume is added from 0.3.0 https://github.com/ros-drivers/audio_common/commit/da9623414f381642e52f59701c09928c72a54be7#diff-fe2d85580f1ccfed4e23a608df44a7f7 sound.volume = 1.0 sound.arg = "Robot stands on the ground." g_robotsound_pub.publish(sound)
def play_sound(self, path, timeout=5.0): if self.act_sound is None: return req = SoundRequest() req.sound = SoundRequest.PLAY_FILE req.command = SoundRequest.PLAY_ONCE if hasattr( SoundRequest, 'volume' ): # volume is added from 0.3.0 https://github.com/ros-drivers/audio_common/commit/da9623414f381642e52f59701c09928c72a54be7#diff-fe2d85580f1ccfed4e23a608df44a7f7 sound.volume = 1.0 req.arg = path goal = SoundRequestGoal(sound_request=req) self.act_sound.send_goal_and_wait(goal, rospy.Duration(timeout))
def sendMsg(self, snd, cmd, s, arg2="", vol=1.0, prior = 1, **kwargs): """ Internal method that publishes the sound request, either directly as a SoundRequest to the soundplay_node or through the actionlib interface (which blocks until the sound has finished playing). The blocking behavior is nominally the class-wide setting unless it has been explicitly specified in the play call. """ # Use the passed-in argument if it exists, otherwise fall back to the # class-wide setting. blocking = kwargs.get('blocking', self._blocking) msg = SoundRequest() msg.sound = snd # Threshold volume between 0 and 1. msg.volume = max(0, min(1, vol)) msg.command = cmd msg.arg = s msg.arg2 = arg2 msg.priority = prior rospy.logdebug('Sending sound request with volume = {}' ' and blocking = {}'.format(msg.volume, blocking)) # Defensive check for the existence of the correct communicator. if not blocking and not self.pub: rospy.logerr('Publisher for SoundRequest must exist') return if blocking and not self.actionclient: rospy.logerr('Action client for SoundRequest does not exist.') return if not blocking: # Publish message directly and return immediately self.pub.publish(msg) if self.pub.get_num_connections() < 1: rospy.logwarn("Sound command issued, but no node is subscribed" " to the topic. Perhaps you forgot to run" " soundplay_node.py?") else: # Block until result comes back. assert self.actionclient, 'Actionclient must exist' rospy.logdebug('Sending action client sound request [blocking]') self.actionclient.wait_for_server() goal = SoundRequestGoal() goal.sound_request = msg self.actionclient.send_goal(goal) self.actionclient.wait_for_result() rospy.logdebug('sound request response received') return
def sendMsg(self, snd, cmd, s, arg2="", vol=1.0, **kwargs): """ Internal method that publishes the sound request, either directly as a SoundRequest to the soundplay_node or through the actionlib interface (which blocks until the sound has finished playing). The blocking behavior is nominally the class-wide setting unless it has been explicitly specified in the play call. """ # Use the passed-in argument if it exists, otherwise fall back to the # class-wide setting. blocking = kwargs.get('blocking', self._blocking) msg = SoundRequest() msg.sound = snd # Threshold volume between 0 and 1. msg.volume = max(0, min(1, vol)) msg.command = cmd msg.arg = s msg.arg2 = arg2 rospy.logdebug('Sending sound request with volume = {}' ' and blocking = {}'.format(msg.volume, blocking)) # Defensive check for the existence of the correct communicator. if not blocking and not self.pub: rospy.logerr('Publisher for SoundRequest must exist') return if blocking and not self.actionclient: rospy.logerr('Action client for SoundRequest does not exist.') return if not blocking: # Publish message directly and return immediately self.pub.publish(msg) if self.pub.get_num_connections() < 1: rospy.logwarn("Sound command issued, but no node is subscribed" " to the topic. Perhaps you forgot to run" " soundplay_node.py?") else: # Block until result comes back. assert self.actionclient, 'Actionclient must exist' rospy.logdebug('Sending action client sound request [blocking]') self.actionclient.wait_for_server() goal = SoundRequestGoal() goal.sound_request = msg self.actionclient.send_goal(goal) self.actionclient.wait_for_result() rospy.logdebug('sound request response received') return
def say(self, text, affect="", blocking=False, **kwargs): """Perform TTS using SSML""" # Transform the text if the affect argument calls for it if affect and affect.upper() in self.affects.keys(): text = self.affects[affect.upper()](text) # Create the vars for the SSML query text = SoundClient.SSML_TEMPLATE.format(speech=text) query_dict = { 'INPUT_TEXT': text, 'INPUT_TYPE': 'SSML', 'LOCALE': 'en_GB', 'VOICE': 'dfki-prudence-hsmm', 'OUTPUT_TYPE': 'AUDIO', 'AUDIO': 'WAVE', # 'effect_Robot_selected': 'on', # 'effect_Robot_parameters': 'amount:60.0', } # Send a request to MARY and check the response type r = requests.post(SoundClient.MARY_SERVER_URL, params=query_dict, timeout=SoundClient.MARY_SERVER_TIMEOUT) if r.headers['content-type'] != 'audio/x-wav': rospy.logerr("Response Error Code: {}. Content-Type: {}".format( r.status_code, r.headers['content-type'])) raise ValueError("Incorrect Content Type", r.headers['content-type'], r.status_code) # Increase the volume on the temp file speech = AudioSegment(data=r.content) speech = speech + SoundClient.SPEECH_GAIN_DB speech = SoundClient.change_audio_speed(speech, 0.95) speech = speech.set_frame_rate(int(speech.frame_rate * 2.0)) # Write the wav data to a temp file speech_filename = create_temp_filename(prefix='marytts', suffix='.wav') with open(speech_filename, 'wb') as fd: speech.export(speech_filename, format='wav') # Now send the file's name over to sound play sound = SoundRequest() sound.sound = SoundRequest.PLAY_FILE sound.command = SoundRequest.PLAY_ONCE sound.arg = speech_filename self._play(sound, blocking=blocking, **kwargs) # Send the file to the cleanup thread now self._tmp_speech_files.put(speech_filename)
def arm_callback(data): global pub_audio global limbl global limbr global anglesl global anglesr limbr = baxter_interface.Limb('right') limbl = baxter_interface.Limb('left') if data.data == "right_arm_side": #anglesr = {'right_e0': 0.0, 'right_e1': 0.0, 'right_w0': 0.0, 'right_w1': 0.0, 'right_w2': 0.0} msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'Moving my right arm to the side' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) limbr.move_to_joint_positions(anglesr) elif data.data == "left_arm_side": #anglesl = {'right_e0': 0.0, 'right_e1': 0.0, 'right_w0': 0.0, 'right_w1': 0.0, 'right_w2': 0.0} msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'Moving my left arm to the side' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) limbl.move_to_joint_positions(anglesl) elif data.data == "left_arm_side": #anglesr = {'right_e0': 0.0, 'right_e1': 0.0, 'right_w0': 0.0, 'right_w1': 0.0, 'right_w2': 0.0} #anglesl = {'right_e0': 0.0, 'right_e1': 0.0, 'right_w0': 0.0, 'right_w1': 0.0, 'right_w2': 0.0} msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'Moving both of my arms to the side' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) limbr.move_to_joint_positions(anglesr) limbl.move_to_joint_positions(anglesl)
def speak(self, sentence): # Pick first 4 characters as a keyword instead of using whole sentence # because sentence can have variables like 100%, 90%, etc. key = sentence[:4] if self.speech_history[key] + rospy.Duration(self.warn_repeat_rate) > rospy.Time.now(): return self.speech_history[key] = rospy.Time.now() req = SoundRequest() req.command = SoundRequest.PLAY_ONCE req.sound = SoundRequest.SAY req.arg = sentence req.arg2 = "ja" req.volume = 1.0 self.speak_client.send_goal(SoundRequestGoal(sound_request=req)) self.speak_client.wait_for_result(timeout=rospy.Duration(10))
def main(text_to_say): print "INITIALIZING SPEECH SYNTHESIS TEST..." rospy.init_node("speech_syn") pub_speech = rospy.Publisher("robotsound", SoundRequest, queue_size=10) loop = rospy.Rate(2) msg_speech = SoundRequest() msg_speech.sound = -3 msg_speech.command = 1 msg_speech.volume = 1.0 msg_speech.arg2 = "voice_kal_diphone" msg_speech.arg = text_to_say loop.sleep() print "Sending text to say: " + text_to_say pub_speech.publish(msg_speech)
def announcement_worker(self): while not rospy.is_shutdown(): self.announceCV.acquire() if len(self.announcements) > 0: msg = SoundRequest() msg.sound = SoundRequest.SAY msg.command = SoundRequest.PLAY_ONCE msg.arg = self.announcements.pop(0) msg.arg2 = 'voice.select "%s"'%self.voice self.audio_pub.publish(msg) duration = self.speech_delay + self.speech_rate*len(msg.arg) self.announceCV.wait(timeout=duration) self.announceCV.release() else: self.announceCV.wait(timeout=0.1) self.announceCV.release()
def sendMsg(self, snd, cmd, s, arg2="", vol=1.0): msg = SoundRequest() msg.sound = snd if vol < 0: msg.volume = 0 elif vol > 1.0: msg.volume = 1.0 else: msg.volume = vol msg.command = cmd msg.arg = s msg.arg2 = arg2 self.pub.publish(msg) if self.pub.get_num_connections() < 1: rospy.logwarn("Sound command issued, but no node is subscribed to the topic. Perhaps you forgot to run soundplay_node.py?");
def commander(data): print "You said: "+data.data #now do sth with that data! names = ['Peter', 'Harry', 'Tina', 'Scarlet', 'Forest', 'Kim', 'Filip', 'Matthew', 'Ellen'] objects = ['building'] streets = ['street'] colours = ['blue', 'yellow', 'green', 'red'] sentence = data.data tokens = nltk.word_tokenize(sentence) print "Tokens:\n" print tokens #first word is name colour_building = None colour_street = None name = min_distance_one(tokens[0], names) building = min_distance_all(tokens, objects) if building[0] != None: colour_building = min_distance_one(tokens[building[1]-1], colours) street = min_distance_all(tokens, streets) if street[0] != None: colour_street = min_distance_one(tokens[street[1]-1], colours) print "Mission Impossible: %s %s %s %s %s"%(name, colour_building, building[0], colour_street, street[0]) #send robot to the right street rospy.Subscriber('move_base/status', GoalStatusArray, self.callback) #this doesnt work the first time - nobody knows why??? str_speech = name + ", where would you like to go?" print str_speech tmp = SoundRequest() tmp.sound = -3 tmp.command = 1 tmp.arg = str_speech tmp.arg2 = '' pub = rospy.Publisher('/robotsound', SoundRequest, queue_size=1) pub.publish(tmp)
def run_deliver(room: Room): move_base = actionlib.SimpleActionClient("move_base", MoveBaseAction) move_base.wait_for_server() goal = MoveBaseGoal() goal.target_pose.header.frame_id = "map" goal.target_pose.header.stamp = rospy.Time.now() goal.target_pose.pose.position.x = room.roomIdx_x goal.target_pose.pose.position.y = room.roomIdx_y goal.target_pose.pose.orientation.w = 1.0 move_base.send_goal(goal) move_base.wait_for_result() sp = SoundRequest() sp.sound = SoundRequest.SAY sp.command = SoundRequest.PLAY_ONCE sp.volume = 1.0 sp.arg = 'Hello, custom of room {:s}, there\'s a package for you.'.format( room.roomNo) pub.publish(sp)
def point_callback(data): global pub_audio global limbr global liml limbr = baxter_interface.Limb('right') limbl = baxter_interface.Limb('left') if data.x == 0 and data.y == 0 and data.z == 0: rospy.loginfo("Point: got a stop command (all zeros)") elif check_range([data.x, data.y, data.z]): rospy.loginfo("Point: setting target to" + str(data)) limbr.move_to_joint_positions(point_joint_angles([data.x, data.y, data.z]), threshold = 0.05) rospy.sleep(5) limbr.move_to_joint_positions(anglesr, threshold = 0.05) #limb.move_to_joint_positions(angles) #blocking else: msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'Quad is out of pointing range' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) rospy.loginfo("Point: target out of pointing range " + str(data))
def callback_global_goal(msg): voice = SoundRequest() print "Calculatin path from robot pose to " + str( [msg.pose.position.x, msg.pose.position.y]) clt_plan_path = rospy.ServiceProxy( '/navigation/path_planning/a_star_search', GetPlan) [robot_x, robot_y, robot_a] = get_robot_pose(listener) req = GetPlanRequest() req.start.pose.position.x = robot_x req.start.pose.position.y = robot_y req.goal.pose.position.x = msg.pose.position.x req.goal.pose.position.y = msg.pose.position.y path = clt_plan_path(req).plan print "Following path with " + str(len(path.poses)) + " points..." path = [[p.pose.position.x, p.pose.position.y] for p in path.poses] follow_path(path) print "Global goal point reached" voice.sound = -3 voice.command = 1 voice.volume = 1.0 voice.arg = 'Ya llegue' voice.arg2 = 'voice_el_diphone' pub_voice.publish(voice)
def main(self): self.last_relative_capacity = 100 self.last_AC_present = 16 self.low_counter = 0 rospy.init_node('pr2_battery_alert') rospy.Subscriber("power_state", PowerState, self.callback) pub = rospy.Publisher('robotsound', SoundRequest, queue_size=1) sound_request = SoundRequest() sound_request.command = 1 sound_request.sound = 3 rate = rospy.Rate(0.2) # every 5 second while not rospy.is_shutdown(): if self.last_AC_present == 0: if self.last_relative_capacity <= CRITICAL_LEVEL: rospy.logdebug("Battery critically low, level %d", self.last_relative_capacity) sound_request.volume = 1.0 self.low_counter = 0 pub.publish(sound_request) elif self.last_relative_capacity <= LOW_LEVEL: if self.low_counter % 6 == 0: rospy.logdebug("Battery low, level %d", self.last_relative_capacity) sound_request.volume = 0.1 pub.publish(sound_request) self.low_counter += 1 else: rospy.logdebug("Battery OK, level %d", self.last_relative_capacity) self.low_counter = 0 else: self.low_counter = 0 rate.sleep()
#!/usr/bin/env python import rospy from sound_play.msg import SoundRequest # topic --> /robotsound or /robotsound_jp rospy.init_node("finish_launch_sound") p = rospy.Publisher("/robotsound", SoundRequest) rospy.sleep(5) # sleep to wait for connection msg = SoundRequest() msg.sound = SoundRequest.SAY msg.command = SoundRequest.PLAY_START msg.arg = "Launching" p.publish(msg)
def speak(self, text): soundRequest = SoundRequest() soundRequest.sound = -3 #Say text soundRequest.command = 1 #Play once soundRequest.arg = text ServerData.pubSound.publish(soundRequest)
#!/usr/bin/env python import rospy from sound_play.msg import SoundRequest # topic --> /robotsound or /robotsound_jp rospy.init_node("finish_launch_sound") p = rospy.Publisher("/robotsound", SoundRequest) rospy.sleep(5) # sleep to wait for connection msg = SoundRequest() msg.sound = SoundRequest.SAY msg.command = SoundRequest.PLAY_ONCE msg.arg = "Launching" p.publish(msg)
def cmd_callback(data): global juliaPos rospy.loginfo("got " + data.data) cmd = str(data.data).strip() if cmd == "hello baxter": rospy.loginfo("hello commander") msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'Hello Human' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) #os.system("espeak -v en 'hello commander'") #speaker? elif cmd == "point to the quad": ''' if the quadrotor's positon is being published, its last known position should be stored in quadPos. If quadPos is None, no position has been reported. ''' if quadPos: t = rospy.get_rostime() rospy.loginfo(str(t) + "," + str(lastPosTime)) if lastPosTime != 0 and t - lastPosTime < currentPositionMaxDuration: msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I see the quad and am pointing to the quad' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) pub_cmd.publish(quadPos) rospy.loginfo("Speech command: I see the quad and am pointing - sending command to point to " + pos_str(quadPos)) else: msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I no longer can see the quad' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) rospy.loginfo("Speech command: I no longer can see the quad - last quad position is outdated: recorded at " + pos_str(quadPos) + str(round((t - lastPosTime).to_sec(), 2)) + " seconds ago") else: msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I do not see the quad' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) rospy.loginfo("No known quad location") elif cmd == "turn on the quad": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I do not know how to do that' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) rospy.loginfo("Speech command: I do not know how to start quad") elif cmd == "move your right arm to the side": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'moving my right arm to the side' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) amsg = String() amsg.data = "right_arm_side" pub_arm.publish(amsg) rospy.loginfo("Speech command: moving your right arm to the side") elif cmd == "move your left arm to the side": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'moving my left arm to the side' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) amsg = String() amsg.data = "left_arm_side" pub_arm.publish(amsg) rospy.loginfo("Speech command: moving my left arm to the side") elif cmd == "move both of your arms to the side": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'moving my arms to the side' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) amsg = String() amsg.data = "both_arms_side" pub_arm.publish(amsg) rospy.loginfo("Speech command: moving both of my arms to the side") elif cmd == "tuck your arms": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'tucking my arms' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) amsg = String() amsg.data = "True" pub_tuck.publish(amsg) rospy.loginfo("Speech command: tucking arms") elif cmd == "untuck your arms": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'untucking my arms' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) amsg = String() amsg.data = "False" pub_tuck.publish(amsg) rospy.loginfo("Speech command:untucking arms") elif cmd == "raise the quad": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I do not know how to do that' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) rospy.loginfo("I do not know how to raise quad") elif cmd == "lower the quad": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I do not know how to do that' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) rospy.loginfo("Speech command: I do not know how to lower quad") elif cmd == "land the quad": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I do not know how to do that' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) rospy.loginfo("Speech command: I do not know how to land quad") elif cmd == "turn off the quad": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I do not know how to do that' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) rospy.loginfo("Speech command: I do not know how to turn off quad") elif cmd == "how are you": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I am fine' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) rospy.loginfo("Speech command: I am fine") elif cmd == "how are you doing": msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I am fine' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) rospy.loginfo("Speech command: I am fine") elif "julia" in cmd: t = rospy.get_rostime() if havejulia and lastJuliaTime != 0 and t - lastJuliaTime < juliaPositionMaxDuration: msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'Julia is over there' msg.arg2 = 'voice_kal_diphone' pub_cmd.publish(juliaPos) pub_audio.publish(msg) rospy.sleep(2) msg.arg = 'I am pointing at her' pub_audio.publish(msg) rospy.loginfo("Speech command: Julia is over there, pointing to her") else: msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I am having trouble with my vision and am not sure that I see Julia' msg.arg2 = 'voice_kal_diphone' pub_audio.publish(msg) rospy.loginfo("Speech command: Not sure I see Julia") else: msg = SoundRequest() msg.sound = -3 msg.command = 1 msg.arg = 'I did not understand that command' msg.arg2 = 'voice_kal_diphone' rospy.loginfo("command " + cmd + " not understood")
rospy.loginfo(rospy.get_caller_id() + "A parle...") rospy.sleep(2) # On s'inscrit au topic rospy.Subscriber("/robotsound", SoundRequest, callback) if mode == modeTest: sh = soundhandle.say("Ready!") messageSon = SoundRequest() topicSon = rospy.Publisher("/robotsound", SoundRequest, queue_size=10) while True: print "Spike va dire (s pour son) " entree = raw_input(">") if entree != "s": rospy.loginfo("Spike dit: " + entree) messageSon.command = SAY messageSon.arg = entree topicSon.publish(messageSon) print messageSon.command #soundhandle.say(entree) else: rospy.loginfo("Joue un son.") messageSon.command = WAV messageSon.arg = nomWav topicSon.publish(messageSon) print messageSon.command #soundhandle.playWave(soundAssets + nomWav) # Puisqu'on attend un signal, il ne faut pas quitter # L'instruction suivante permet de rester dans le programme
def __init__(self): """ The main control loop for searching and recording victim locations """ # States for the state machine self.state = enum(SEARCHING=1, INVESTIGATING=2, GO_HOME=3) rospy.init_node('random_nav') # setup publishers and subscribers self.ac = actionlib.SimpleActionClient("move_base", MoveBaseAction) rospy.Subscriber('/visualization_marker', Marker, self.marker_callback) rospy.Subscriber('/amcl_pose', PoseWithCovarianceStamped, self.position_callback) rospy.Subscriber('/camera/rgb/image_raw', Image, self.image_callback) self.marker_pub = rospy.Publisher('victim_marker', Marker, queue_size=10) self._talk_pub = rospy.Publisher('/robotsound', SoundRequest, queue_size=10) rospy.Subscriber('map', OccupancyGrid, self.map_callback) self.tf_listener = tf.TransformListener() self.current_goal = (1000,1000) # current nav goal self.TIME = 450 # search time for robot self.old_goals = [] # list of previous nav goals self.cv_bridge = CvBridge() # for image conversion self.image = None # raw rgb image self.map_msg = None # sets up map self.victims = [] # list of found victims self.start_time = rospy.get_time() # start time of the robot self.home = False # signals when to go home self.position = None # robot's current position self.cur_state = self.state.SEARCHING # current state of the robot self.cur_marker = Point() # ar marker currently seen self.first_goal = True # signals if it is the 1st goal self.goals = 0 # diagnostic count of old goals old_state = None # previous state of the robot # Set up a SoundRequest message: sound_request = SoundRequest() sound_request.sound = sound_request.SAY sound_request.command = sound_request.PLAY_ONCE sound_request.arg = "Report is Ready!" while self.map_msg is None and not rospy.is_shutdown(): rospy.loginfo("Waiting for map...") rospy.sleep(.1) self.map = map_utils.Map(self.map_msg) while (self.position is None and not rospy.is_shutdown()): rospy.loginfo("Waiting for position...") rospy.sleep(.1) # sets the home postion home_pos = self.position # generate the first random goal x_goal = 100000 y_goal = 100000 while self.map.get_cell(x_goal, y_goal) != 0: x_goal = random.random() * 20.0 - 10.0 y_goal = random.random() * 20.0 - 10.0 rospy.loginfo("Random goal found: ({}, {})".format(x_goal, y_goal)) # main execution loop while not rospy.is_shutdown(): local_marker = self.cur_marker local_state = self.cur_state # Go back to start after certain time limit local_state = self.go_home(local_state) # Set the goal to a random point if local_state is self.state.SEARCHING: goals = self.search(x_goal, y_goal, old_state) x_goal = goals[0] y_goal = goals[1] # Set the goal to the starting position elif local_state is self.state.GO_HOME: x_goal = home_pos.position.x y_goal = home_pos.position.y # Set the goal to the victim's position elif local_state is self.state.INVESTIGATING: local_state = self.investigate(local_state, local_marker) # Only set a new goal if the state has changed if (old_state is not local_state): goal = self.goal_message(x_goal, y_goal, 0) self.go_to_point(goal) self.old_goals.append((x_goal, y_goal)) self.current_goal = (x_goal,y_goal) old_state = local_state self.cur_state = local_state # if going home, wait to reach goal then break out of loop if self.home: self.ac.wait_for_result() self._talk_pub.publish(sound_request) rospy.sleep(3) break