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 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 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 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 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 req.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 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()
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 play_sound(sound, lang='', topic_name='robotsound', volume=1.0, wait=False): """ Plays sound using sound_play server Args: sound: if sound is pathname, plays sound file located at given path if it is number, server plays builtin sound otherwise server plays sound as speech sentence topic-name: namespace of sound_play server wait: wait until sound is played """ msg = SoundRequest(command=SoundRequest.PLAY_ONCE) if isinstance(sound, int): msg.sound = sound elif isinstance(sound, str) and Path(sound).exists(): msg.sound = SoundRequest.PLAY_FILE msg.arg = sound elif isinstance(sound, str): msg.sound = SoundRequest.SAY msg.arg = sound else: raise ValueError if hasattr(msg, 'volume'): msg.volume = volume if topic_name in _sound_play_clients: client = _sound_play_clients[topic_name] else: client = actionlib.SimpleActionClient(topic_name, SoundRequestAction) client.wait_for_server() goal = SoundRequestGoal() if client.get_state() == actionlib_msgs.msg.GoalStatus.ACTIVE: client.cancel_goal() client.wait_for_result(timeout=rospy.Duration(10)) goal.sound_request = msg _sound_play_clients[topic_name] = client client.send_goal(goal) if wait is True: client.wait_for_result(timeout=rospy.Duration(10)) return client
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 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)
#!/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, queue_size=1) rospy.sleep(5) # sleep to wait for connection msg = SoundRequest() msg.sound = SoundRequest.SAY msg.command = SoundRequest.PLAY_ONCE if hasattr(msg, 'volume'): msg.volume = 1.0 msg.arg = "Now I am ready" p.publish(msg)
def do_speak(self, goal): """The action handler. Note that although it responds to client after the audio play is finished, a client can choose not to wait by not calling ``SimpleActionClient.waite_for_result()``. """ self.goal_text = strip_tags(goal.text) self.state_pub.publish(state=TTSState.SYNTHESIZING, text=self.goal_text) res = do_synthesize(goal) rospy.loginfo('synthesizer returns: %s', res) try: res = json.loads(res.result) except ValueError as err: syn = 'Expecting JSON from synthesizer but got {}'.format( res.result) rospy.logerr('%s. Exception: %s', syn, err) self.state_pub.publish(state=TTSState.ERROR, text=syn) self.finish_with_result(syn) return if 'Audio File' in res: audio_file = res['Audio File'] rospy.loginfo('Will play %s', audio_file) mut_d = mutagen.File(audio_file) self.length = mut_d.info.length self.utterance_pub.publish(self.goal_text) msg = SoundRequest() # self.sendMsg(SoundRequest.PLAY_FILE, SoundRequest.PLAY_ONCE, sound, # vol=volume, **kwargs) msg.sound = SoundRequest.PLAY_FILE msg.volume = rospy.get_param("/flo_hum_vol") msg.command = SoundRequest.PLAY_ONCE msg.arg = audio_file msg.arg2 = "" goal = SoundRequestGoal() goal.sound_request = msg self.done = False self.sound_client.send_goal(goal, active_cb=self.sound_received, feedback_cb=self.sound_fb, done_cb=self.sound_done) # self.result = audio_file t_rate = rospy.Rate(10) success = True while not self.done: if self.server.is_preempt_requested(): self.sound_client.cancel_goal() self.server.set_preempted() success = False break t_rate.sleep() self.state_pub.publish(state=TTSState.WAITING) if success: self.finish_with_result('completed sound play in') else: rospy.logerr('No audio file in synthesize voice result') self.state_pub.publish(state=TTSState.ERROR, text='no audio file') self.finish_with_result('no audio file')
def _timer_cb(self, event): larm_enable = self.enable['larm'] if self.prev_enable['larm'] is None: larm_start = False larm_stop = False else: larm_start = larm_enable and not self.prev_enable['larm'] larm_stop = not larm_enable and self.prev_enable['larm'] if self.prev_hand_close['larm'] is None: lhand_open = False lhand_close = False else: lhand_open = (not self.hand_close['larm'] and self.prev_hand_close['larm']) lhand_close = (self.hand_close['larm'] and not self.prev_hand_close['larm']) larm_collision = self.collision['larm'] if larm_enable else False larm_track_error = self.track_error['larm'] if larm_enable else False rarm_enable = self.enable['rarm'] if self.prev_enable['rarm'] is None: rarm_start = False rarm_stop = False else: rarm_start = rarm_enable and not self.prev_enable['rarm'] rarm_stop = not rarm_enable and self.prev_enable['rarm'] if self.prev_hand_close['rarm'] is None: rhand_open = False rhand_close = False else: rhand_open = (not self.hand_close['rarm'] and self.prev_hand_close['rarm']) rhand_close = (self.hand_close['rarm'] and not self.prev_hand_close['rarm']) rarm_collision = self.collision['rarm'] if rarm_enable else False rarm_collision = self.collision['rarm'] if rarm_enable else False rarm_track_error = self.track_error['rarm'] if rarm_enable else False # reset self.collision['larm'] = False self.track_error['larm'] = False self.collision['rarm'] = False self.track_error['rarm'] = False self.prev_hand_close = self.hand_close.copy() self.prev_enable = self.enable.copy() # enable if larm_start or rarm_start: sound_msg = SoundRequest() sound_msg.sound = SoundRequest.PLAY_FILE sound_msg.command = SoundRequest.PLAY_ONCE sound_msg.volume = 0.6 sound_msg.arg = os.path.join(self.rospack.get_path('eus_vive'), 'sounds/start.wav') self.pub.publish(sound_msg) rospy.sleep(1.0) warning_msg = SoundRequest() warning_msg.sound = SoundRequest.SAY warning_msg.command = SoundRequest.PLAY_ONCE warning_msg.volume = 0.6 if larm_start and rarm_start: warning_msg.arg = "both arm starting" elif larm_start: warning_msg.arg = "left arm starting" else: warning_msg.arg = "right arm starting" self.pub.publish(warning_msg) elif larm_stop or rarm_stop: sound_msg = SoundRequest() sound_msg.sound = SoundRequest.PLAY_FILE sound_msg.command = SoundRequest.PLAY_ONCE sound_msg.volume = 0.6 sound_msg.arg = os.path.join(self.rospack.get_path('eus_vive'), 'sounds/stop.wav') self.pub.publish(sound_msg) rospy.sleep(1.0) warning_msg = SoundRequest() warning_msg.sound = SoundRequest.SAY warning_msg.command = SoundRequest.PLAY_ONCE warning_msg.volume = 0.6 if larm_stop and rarm_stop: warning_msg.arg = "both arm stopping" elif larm_stop: warning_msg.arg = "left arm stopping" else: warning_msg.arg = "right arm stopping" self.pub.publish(warning_msg) # gripper opening elif lhand_open or rhand_open: sound_msg = SoundRequest() sound_msg.sound = SoundRequest.PLAY_FILE sound_msg.command = SoundRequest.PLAY_ONCE sound_msg.volume = 0.6 sound_msg.arg = os.path.join(self.rospack.get_path('eus_vive'), 'sounds/gripper.wav') self.pub.publish(sound_msg) rospy.sleep(1.0) warning_msg = SoundRequest() warning_msg.sound = SoundRequest.SAY warning_msg.command = SoundRequest.PLAY_ONCE warning_msg.volume = 0.6 if lhand_open and rhand_open: warning_msg.arg = "both hand opening" elif lhand_open: warning_msg.arg = "left hand opening" else: warning_msg.arg = "right hand opening" self.pub.publish(warning_msg) rospy.sleep(1.0) # gripper closing elif lhand_close or rhand_close: sound_msg = SoundRequest() sound_msg.sound = SoundRequest.PLAY_FILE sound_msg.command = SoundRequest.PLAY_ONCE sound_msg.volume = 0.6 sound_msg.arg = os.path.join(self.rospack.get_path('eus_vive'), 'sounds/gripper.wav') self.pub.publish(sound_msg) rospy.sleep(1.0) warning_msg = SoundRequest() warning_msg.sound = SoundRequest.SAY warning_msg.command = SoundRequest.PLAY_ONCE warning_msg.volume = 0.6 if lhand_close and rhand_close: warning_msg.arg = "both hand closing" elif lhand_close: warning_msg.arg = "left hand closing" else: warning_msg.arg = "right hand closing" self.pub.publish(warning_msg) rospy.sleep(1.0) # collision and tracking error elif larm_collision or rarm_collision: sound_msg = SoundRequest() sound_msg.sound = SoundRequest.PLAY_FILE sound_msg.command = SoundRequest.PLAY_ONCE sound_msg.volume = 0.6 sound_msg.arg = os.path.join(self.rospack.get_path('eus_vive'), 'sounds/alert.wav') self.pub.publish(sound_msg) rospy.sleep(1.0) warning_msg = SoundRequest() warning_msg.sound = SoundRequest.SAY warning_msg.command = SoundRequest.PLAY_ONCE warning_msg.volume = 0.6 if larm_collision and rarm_collision: warning_msg.arg = "both arm collision error" elif larm_collision: warning_msg.arg = "left arm collision error" else: warning_msg.arg = "right arm collision error" self.pub.publish(warning_msg) rospy.sleep(2.0) elif larm_track_error or rarm_track_error: sound_msg = SoundRequest() sound_msg.sound = SoundRequest.PLAY_FILE sound_msg.command = SoundRequest.PLAY_ONCE sound_msg.volume = 0.6 sound_msg.arg = os.path.join(self.rospack.get_path('eus_vive'), 'sounds/warn.wav') self.pub.publish(sound_msg) rospy.sleep(1.0) warning_msg = SoundRequest() warning_msg.sound = SoundRequest.SAY warning_msg.command = SoundRequest.PLAY_ONCE warning_msg.volume = 0.6 if larm_track_error and rarm_track_error: warning_msg.arg = "both arm tracking error" elif larm_track_error: warning_msg.arg = "left arm tracking error" else: warning_msg.arg = "right arm tracking error" self.pub.publish(warning_msg) rospy.sleep(2.0)
# -*- coding: utf-8 -*- import actionlib from collections import defaultdict import os.path as osp import math import rospy import pandas as pd from sound_play.msg import SoundRequestAction from sound_play.msg import SoundRequest, SoundRequestGoal from power_msgs.msg import BatteryState from diagnostic_msgs.msg import DiagnosticArray rospy.init_node("battery_warning") speak_client = actionlib.SimpleActionClient("/robotsound_jp", SoundRequestAction) waitEnough = speak_client.wait_for_server(rospy.Duration(10)) req = SoundRequest() req.command = SoundRequest.PLAY_ONCE req.sound = SoundRequest.SAY req.arg = "おーい。きたがわ" req.arg2 = "ja" req.volume = 1.0 speak_client.send_goal(SoundRequestGoal(sound_request=req)) speak_client.wait_for_result(timeout=rospy.Duration(10))