Пример #1
0
 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))
Пример #2
0
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)
Пример #3
0
 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");
Пример #4
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))
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
 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"
         )
Пример #8
0
    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
Пример #9
0
    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
Пример #10
0
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)
Пример #11
0
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)
Пример #12
0
 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))
Пример #13
0
 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()
Пример #14
0
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)
Пример #15
0
    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?");
Пример #16
0
    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)
Пример #17
0
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)
Пример #18
0
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))
Пример #19
0
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))
Пример #20
0
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")
Пример #21
0
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")
Пример #22
0
    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')
Пример #23
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))