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 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 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 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 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 __init__(self, *args): super(self.__class__, self).__init__(*args) rospy.init_node(NAME) self.lock_for_msg = threading.Lock() self.msg = SoundRequest() self.action_server = \ actionlib.SimpleActionServer( '/sound_play', SoundRequestAction, execute_cb=self.handler, auto_start=False) self.action_server.start()
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 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 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 _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 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 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 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_result(self, result): if self.sound_action is None: return msg = SoundRequest(command=SoundRequest.PLAY_ONCE, sound=SoundRequest.SAY, volume=1.0, arg=result.fulfillment_text.encode('utf-8'), arg2=self.language) self.sound_action.send_goal_and_wait( SoundRequestGoal(sound_request=msg), rospy.Duration(10.0))
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 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 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 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 execute(self, userdata): if not self.init: self.init = True self.pub = rospy.Publisher('robotsound', SoundRequest) rospy.sleep(1.0) self.pub.publish(SoundRequest(-3, 1, 'Ready to Move')) ui = '' while not (ui == '0' or ui == '1'): print '\'0\' or \'1\' when Ready.' ui = raw_input() return 'succeeded'
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 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 say(self, text, is_using_sounds=False): '''Send a TTS (text to speech) command. This will cause the robot to verbalize text if not is_using_sounds. It will always display text in Rviz. Args: text (str): The speech to say / vizualize. is_using_sounds (bool): Whether the robot is beeping and booping (if True), which determines whether to actually speak the words (only if False). ''' if not is_using_sounds: self.speech_publisher.publish(SoundRequest( command=SoundRequest.SAY, arg=text)) self.say_in_rviz(text)
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)