def __init__(self, phrase_file): self.sound_client = SoundClient() rospy.sleep(0.5) self.sound_client.stopAll() #self.animation_client = actionlib.SimpleActionClient('/Animation_Server',ExpressionMotionAction) self.viseme_client = actionlib.SimpleActionClient( '/Viseme_Server', VisemeAction) #self.lookat_client = actionlib.SimpleActionClient('/Lookat_Server',LookatAction) rospy.loginfo("Waiting for Cordial Action Servers") #rospy.loginfo(" --- Animation") #self.animation_client.wait_for_server() rospy.loginfo(" --- Visemes") self.viseme_client.wait_for_server() #rospy.loginfo(" --- Lookat") #self.lookat_client.wait_for_server() rospy.loginfo("Action servers connected") rospy.loginfo("Reading Phrase File") with open(phrase_file, 'r') as f: s = f.read() self.phrases = yaml.load(s) self.feedback.viseme = "IDLE" self.feedback.action = "none" rospy.loginfo("Starting server...") self.server = actionlib.SimpleActionServer('SBPlayback_Server', SpeechPlayAction, execute_cb=self.execute_cb) self.server.start() rospy.loginfo("Server started")
def __init__(self): def callback(data): if int(data.data) == 100: self.performedBehaviors = [] return #action behavior processing if int(data.data) == 0 and len(self.performedBehaviors) > 1: self.performedBehaviors = [] if data not in self.performedBehaviors: print("performing behavior") # time.sleep(1.0) case = int(data.data) if case == 0: self.robot.say("demo2", wait=True) elif case == 1: self.robot.say("dance1", wait=True) # time.sleep(4.0) elif case == 2: self.robot.say("compliment1", wait=True) elif case == 3: self.robot.say("encouragement1", wait=True) elif case == 4: self.robot.say("sassy1", wait=True) elif case == 5: self.robot.say("joke1", wait=True) elif case == 6: self.sound.playWave( '/home/saunter/rosbuild_ws/saunter/saunter_interaction/speech/data/DanceSong.wav' ) self.robot.do("shimmy", wait=True) # time.sleep(4.0) self.performedBehaviors += [data] self.robot.do("returnToNeutral", wait=True) rospy.Publisher("kiwi", String, queue_size=2).publish("behavior completed") # In ROS, nodes are uniquely named. If two nodes with the same # node are launched, the previous one is kicked off. The # anonymous=True flag means that rospy will choose a unique # name for our 'listener' node so that multiple listeners can # run simultaneously. rospy.init_node('BehaviorServer', anonymous=True) rospy.Subscriber("behavior_number", String, callback, queue_size=4) self.robot = RobotManager("DB1") self.performedBehaviors = [] self.sound = SoundClient()
import rospy, os, sys from cordial_sound.msg import SoundRequest from cordial_sound.libsoundplay import SoundClient def sleep(t): try: rospy.sleep(t) except: pass if __name__ == '__main__': rospy.init_node('soundplay_test', anonymous=True) soundhandle = SoundClient() rospy.sleep(1) soundhandle.stopAll() print "This script will run continuously until you hit CTRL+C, testing various sound_node sound types." print #print 'Try to play wave files that do not exist.' #soundhandle.playWave('17') #soundhandle.playWave('dummy') #print 'say' #soundhandle.say('Hello world!') #sleep(3)
def __init__(self, phone_face, delay=0.0, phrase_file=None, use_tts=False, voice=None): self._use_tts = use_tts in ['true', 'True', 'TRUE', '1'] if phrase_file and not len(phrase_file) > 0 and not use_tts: rospy.logerr( "CoRDial Player Error: Must specify phrase file or allow tts! Continuing without sound..." ) self._sound = False elif not phrase_file and not use_tts: rospy.logerr( "CoRDial Player Error: Must specify phrase file or allow tts! Continuing without sound..." ) self._sound = False # elif (not phrase_file or len(phrase_file)>0) and use_tts and (not ivona_secret_key or not ivona_access_key): # rospy.logerr("CoRDial Player Error: Must specify ivona keys to allow tts! Continuing without sound...") # self._sound = False # self._use_tts=False else: self._sound = True self._speech_delay_time = delay self._phone_face = phone_face self._phrases = None if phrase_file and len(phrase_file) > 0: self._sound_client = SoundClient() rospy.sleep(0.5) self._sound_client.stopAll() rospy.loginfo( "CoRDial Player reading Phrase File... this could take a while" ) with open(phrase_file, 'r') as f: s = f.read() self._phrases = yaml.load(s) rospy.loginfo("Phrase file read.") if self._use_tts: self._tts = CoRDialTTS(voice) base_topic = "" self._behavior_client = actionlib.SimpleActionClient( base_topic + 'Behavior', BehaviorAction) if self._phone_face: self._face_pub = rospy.Publisher(base_topic + 'face', FaceRequest, queue_size=10) rospy.sleep(0.5) rospy.loginfo("CoRdial Player waiting for behavior server..") self._behavior_client.wait_for_server() rospy.loginfo("CoRDial Player connected to behavior server") self._feedback.behavior = "none" rospy.loginfo("Starting CoRDial Player server...") self._server = actionlib.SimpleActionServer(base_topic + 'Player', PlayerAction, execute_cb=self.execute_cb, auto_start=False) info = "" if self._phone_face: info += ", using CoRDial face" else: info += ", NOT using CoRDial face" if self._use_tts: info += " and using TTS with voice " + voice elif self._phrases: info += " and NOT using TTS" if self._phrases: info += "; phrase file is " + phrase_file if not self._use_tts and not self._phrases: info += " and with NO sound" info += ". Delay time is " + str(self._speech_delay_time) + "s." self._server.start() rospy.loginfo("CoRDial Player server started" + info)