def play_nonblocking():
    """
    Play the same sounds with manual pauses between them.
    """
    rospy.loginfo('Example: Playing sounds in *non-blocking* mode.')
    # NOTE: you must sleep at the beginning to let the SoundClient publisher
    # establish a connection to the soundplay_node.
    soundhandle = SoundClient(blocking=False)
    rospy.sleep(1)

    # In the non-blocking version you need to sleep between calls.
    rospy.loginfo('Playing say-beep at full volume.')
    soundhandle.playWave('say-beep.wav')
    rospy.sleep(1)

    rospy.loginfo('Playing say-beep at volume 0.3.')
    soundhandle.playWave('say-beep.wav', volume=0.3)
    rospy.sleep(1)

    rospy.loginfo('Playing sound for NEEDS_PLUGGING.')
    soundhandle.play(SoundRequest.NEEDS_PLUGGING)
    rospy.sleep(1)

    rospy.loginfo('Speaking some long string.')
    soundhandle.say('It was the best of times, it was the worst of times.')
Beispiel #2
0
 def callback(self, msg):
     if msg.min_distance < 2.0:
         soundhandle = SoundClient()
         rospy.sleep(rospy.Duration(1))
         soundhandle.playWave(self.sound)
         rospy.sleep(rospy.Duration(2))
         soundhandle.stopAll()
Beispiel #3
0
class TalkBack:
    def __init__(self, script_path):
        rospy.init_node('talkback')

        rospy.on_shutdown(self.cleanup)
        self.voice = rospy.get_param("~voice", "voice_don_diphone")
        self.wavepath = rospy.get_param("~wavepath", script_path + "/../sounds")
        self.soundhandle = SoundClient()
        rospy.sleep(1)
        self.soundhandle.stopAll()
        self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
        rospy.sleep(1)
        self.soundhandle.say("Ready", self.voice)
        rospy.loginfo("Say one of the navigation commands...")
        rospy.Subscriber('/recognizer/output', String, self.talkback)
        
    def talkback(self, msg):
	palabra = msg.data
        rospy.loginfo(palabra)
	if (palabra == "cancel"):
		rospy.loginfo("The number is one")
        self.soundhandle.say(msg.data, self.voice)

    def cleanup(self):
        self.soundhandle.stopAll()
        rospy.loginfo("Shutting down talkback node...")
Beispiel #4
0
class Voice:
    def __init__(self, sound_db):
        self._sound_client = SoundClient()
        rospy.loginfo('Will wait for a second for sound_pay node.')
        rospy.sleep(1)
        self._sound_db = sound_db
        self.play_sound('sound10')

    def play_sound(self, sound_name):
        '''Plays the requested sound.

        Args:
            requested_sound (str): Unique name of the sound in the sound database.
        '''
        sound_filename = self._sound_db.get(sound_name)
        self._sound_client.playWave(sound_filename)

        # TODO: Make sure this returns when it is done playing the sound.

    def say(self, text):
        '''Send a TTS (text to speech) command.
        Args:
            text (str): The speech to say.
        '''
        self._sound_client.say(text)
Beispiel #5
0
class voice_play:

    def __init__(self):
        self.voice = rospy.get_param("~voice", "voice_cmu_us_clb_arctic_clunits")
        self.sound_files_dir = rospy.get_param("~sound_dir", "")

        self.sound_handle = SoundClient()

        rospy.sleep(1)
        rospy.loginfo("Ready to speak...")

        rospy.Subscriber('/speech', String, self.talkback)
        rospy.Subscriber('/sounds', String, self.play_sound)
        # self.sound_handle.say('Greetings, I am Judith.', self.voice)

    def talkback(self, msg):
        rospy.loginfo(msg.data)
        self.sound_handle.stopAll()
        self.sound_handle.say(msg.data, self.voice)
        rospy.sleep(2)

    def play_sound(self, msg):
        rospy.loginfo(msg.data)
        self.sound_handle.stopAll()
        self.sound_handle.playWave(self.sound_files_dir + msg.data)
        rospy.sleep(2)
Beispiel #6
0
class ChatbotSpeaker:
  def __init__(self):
    rospy.init_node('chatbot_speaker')
    self._client = SoundClient()
    rospy.Subscriber('chatbot_responses', String, self._response_callback)
    rospy.spin()

  def _response_callback(self, data):
    query = urllib.quote(data.data)
    os.system(tts_cmd.format(query))
    os.system(sox_cmd)
    self._client.playWave('/tmp/speech.wav')
Beispiel #7
0
def main():
    rospy.init_node('eys_move', anonymous = True)
    soundhandle = SoundClient()
    close_eye_publisher = rospy.Publisher("close_eye", Int32, queue_size=10)
    rospy.sleep(1)
    soundhandle.stopAll()

    close_eye_publisher.publish(Int32(data=2))

    wave_path = os.path.dirname(os.path.abspath(__file__)) + "/../sounds/camera.wav"
    soundhandle.playWave(wave_path)
    sleep(2)
Beispiel #8
0
class Speech_Interact:
    def __init__(self):
        rospy.on_shutdown(self.cleanup)

        self.rate = rospy.get_param("~rate", 5)
        r = rospy.Rate(self.rate)
          
        self.voice = rospy.get_param("~voice", "voice_don_diphone")
        self.wavepath = rospy.get_param("~wavepath", "")
        
        # Create the sound client object
        self.soundhandle = SoundClient()
        
        rospy.sleep(1)
        self.soundhandle.stopAll()
        
        # Announce that we are ready for input
        self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
        rospy.sleep(1)
        self.soundhandle.say("Ready", self.voice)

        # Subscribe to the recognizer output
        rospy.Subscriber('/recognizer/output', String, self.identify)


	while not rospy.is_shutdown():
    		r.sleep()                       



    def identify(self, msg):

    	if msg.data == 'hello':
        	rospy.loginfo(msg.data)
        	self.soundhandle.say("hello", self.voice)
        	rospy.sleep(1)

    	elif msg.data == 'how are you'
        	rospy.loginfo(msg.data)
        	self.soundhandle.say("I am fine", self.voice)
        	rospy.sleep(1)

    	elif msg.data == 'who are you'
        	rospy.loginfo(msg.data)
        	self.soundhandle.say("I am turtle", self.voice)
        	rospy.sleep(1)


    def cleanup(self):
        rospy.loginfo("Shutting down voice interaction...")
        twist = Twist()
        self.cmd_vel_pub.publish(twist)
Beispiel #9
0
class TalkBack:
    def __init__(self, script_path):
        rospy.init_node('talkback')

        rospy.on_shutdown(self.cleanup)
        
        # Set the default TTS voice to use
        self.voice = rospy.get_param("~voice", "voice_don_diphone")
        
        # Set the wave file path if used
        self.wavepath = rospy.get_param("~wavepath", script_path + "/../sounds")
        
        # Create the sound client object
        self.soundhandle = SoundClient()
        
        # Wait a moment to let the client connect to the
        # sound_play server
        rospy.sleep(1)
        
        # Make sure any lingering sound_play processes are stopped.
        self.soundhandle.stopAll()
        
        # Announce that we are ready for input
        self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
        rospy.sleep(1)
        self.soundhandle.say("Ready", self.voice)
        
        rospy.loginfo("Say one of the navigation commands...")

        # Subscribe to the recognizer output and set the callback function
        rospy.Subscriber('/recognizer/output', String, self.talkback)
        
    def talkback(self, msg):
        # Print the recognized words on the screen
        rospy.loginfo(msg.data)
        
        # Speak the recognized words in the selected voice
        self.soundhandle.say(msg.data, self.voice)
        
        # Uncomment to play one of the built-in sounds
        #rospy.sleep(2)
        #self.soundhandle.play(5)
        
        # Uncomment to play a wave file
        #rospy.sleep(2)
        #self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")

    def cleanup(self):
        self.soundhandle.stopAll()
        rospy.loginfo("Shutting down talkback node...")
Beispiel #10
0
    def execute(self, userdata):

        sound_path = Mp3ToWavConverter(userdata.sound_file_path)
        frequency = BpmToFreq(userdata.bpm)
        soundhandle = SoundClient()

        rospy.sleep(1)

        r = rospy.Rate(frequency)
        rospy.loginfo("Playing the sound in this path ==> " + sound_path)
        while not rospy.is_shutdown():
            soundhandle.playWave(sound_path)
            r.sleep()

        return succeeded
Beispiel #11
0
def generate_sound(note_number):
    #Since it was called in move_arm_wrist. A nodes called arm_signal_node has already been called, no need to initiate a    new node at here
    #rospy.init_node('play', anonymous = True)

    #the sounds dictionary for coorelating notes with wav file
    sounds_dict = []
    sounds_dict.append('/home/cl3295/robot-test/src/sound_play/sounds/note_1.wav')
    sounds_dict.append('/home/cl3295/robot-test/src/sound_play/sounds/note_2.wav')
    sounds_dict.append('/home/cl3295/robot-test/src/sound_play/sounds/note_3.wav')
    sounds_dict.append('/home/cl3295/robot-test/src/sound_play/sounds/note_4.wav')
    sounds_dict.append('/home/cl3295/robot-test/src/sound_play/sounds/note_5.wav')
    sounds_dict.append('/home/cl3295/robot-test/src/sound_play/sounds/note_6.wav')
    sounds_dict.append('/home/cl3295/robot-test/src/sound_play/sounds/note_7.wav')
    sounds_dict.append('/home/cl3295/robot-test/src/sound_play/sounds/note_1.wav')

    soundhandle = SoundClient()
    soundhandle.playWave(sounds_dict[note_number-1])
Beispiel #12
0
    def execute(self, userdata):

        if SoundFileIsMp3(userdata.sound_file_path):
            print "CONVERTING MP3 TO WAV"
            sound_path = Mp3ToWavConverter(input_mp3_absolute_path=userdata.sound_file_path, output_wav_absolute_path=self._to_execute_sound_file_path)
        else:
            print "ALREADY WAV, NO CONVERSION NEEDED"
            sound_path = self._to_execute_sound_file_path
        print "@@@11"
        soundhandle = SoundClient()
        print "@@@11"
        rospy.sleep(1)
        print "@@@11"
        soundhandle.playWave(sound_path)
        print "@@@11"
        rospy.sleep(1)

        return succeeded
def play_blocking():
    """
    Play various sounds, blocking until each is completed before going to the
    next.
    """
    rospy.loginfo('Example: Playing sounds in *blocking* mode.')
    soundhandle = SoundClient(blocking=True)

    rospy.loginfo('Playing say-beep at full volume.')
    soundhandle.playWave('say-beep.wav')

    rospy.loginfo('Playing say-beep at volume 0.3.')
    soundhandle.playWave('say-beep.wav', volume=0.3)

    rospy.loginfo('Playing sound for NEEDS_PLUGGING.')
    soundhandle.play(SoundRequest.NEEDS_PLUGGING)

    rospy.loginfo('Speaking some long string.')
    soundhandle.say('It was the best of times, it was the worst of times.')
Beispiel #14
0
class Say():
    
    
    def __init__( self ):
        """ Node Constructor """
        
        rospy.loginfo( 'Start %s node...', NODE )
        rospy.on_shutdown( self.__on_shutdown )
        
        self.soundhandle = SoundClient()
        rospy.sleep( 1 )
        
        rospy.loginfo( 'Start Topics (publishers/subscribers)...' )
        self.sub = rospy.Subscriber( SUB_DISPLAY, Command, self.__say )
        
        rospy.loginfo( 'Start main loop...' )
        rospy.spin()
    
    def __say( self, data ):
        rospy.logdebug( '%s say : %s', data.context.who, data.subject )
        
        # remove old file
        self.silentremove( TMP_FILE )
        
        # Generate TTS
        cmd = 'pico2wave -l %s -w /tmp/test.wav "%s " > /dev/null' % ( voice, data.subject, )
        #rospy.loginfo(cmd)
        execute( cmd )
        
        # Play by robotout
        self.soundhandle.playWave( TMP_FILE )
    
    def __on_shutdown( self ):
        rospy.sleep( 1 )
    
    def silentremove( self, filename ):
        try:
            os.remove( filename )
        except OSError as e: # this would be "except OSError, e:" before Python 2.6
            if e.errno != errno.ENOENT: # errno.ENOENT = no such file or directory
                raise # re-raise exception if a different error occured
Beispiel #15
0
    def dance(self):
	max_time = 25
    	sound_client = SoundClient(blocking=False)
    	# In the non-blocking version you need to sleep between calls.
        rospy.sleep(1)
	#PLAY THE SONG HERE
        rospy.loginfo('Playing the song, getting ready to dance')
	sound_client.playWave('/home/turtlebot/wavFiles/dancesong.wav')
    	rospy.sleep(1)
	#for some random number of times
	times = randint(4,7)
	count = 0
	start_time = time.time()  # remember when we started
	while (time.time() - start_time) < max_time:
	    #while (count < times):
	    count = count + 1
	    #generate random angle for dance
	    rad = randint(30, 120)		
	    self.turn('right', rad)
	    rangeDist = randint(3, 5)
	    self.goForward(rangeDist, 0.3)
Beispiel #16
0
class ShucSoundPlayer():
    NODE_NAME = "shuc_sound_player"

    def __init__(self):
        rospy.init_node(self.NODE_NAME)
        # directory with sound assets - change as needed
        self.soundAssets = '/home/dan/Desktop/audio/catkin_ws/src/shuc_audio/audio/'  #change
        # duration of yak throttle
        self.throttle = 3  # seconds
        self.soundhandle = SoundClient()
        rospy.Subscriber('/shuc_sound_selector/sound', String,
                         self.sound_translator)
        self.allow_yak = rospy.Time.now()

    def sound_translator(self, data):
        if rospy.Time.now() <= self.allow_yak:  # Throttles yak to avoid
            print("Sound throttled")  # SoundClient segfault
            return
        self.allow_yak = rospy.Time.now() + rospy.Duration.from_sec(
            self.throttle)
        self.soundhandle.playWave(self.soundAssets + data.data)
Beispiel #17
0
class play_silent:
    def __init__(self):
        rospy.init_node('a2dr_silentplay_node')
        self.sound_path = '/home/ohm/a2dr_ws/src/a2dr_voice/voice/excuse_me.wav'
        self.sound_cycleTime = 4
        self.listener()

    def listener(self):
        rospy.Subscriber('silent', String, self.play)
        rospy.spin()

    def play(self, data):
        print("play")
        self.soundhandle = SoundClient()
        self.sound_volume = rospy.get_param("~sound_volume", 1.0)
        self.sound_to_play = rospy.get_param("~sound_to_play", self.sound_path)
        self.sound_cycle_time = rospy.get_param("~sound_cycle_time",
                                                self.sound_cycleTime)
        rospy.sleep(1)
        self.soundhandle.playWave(self.sound_to_play, self.sound_volume)
        rospy.sleep(self.sound_cycle_time)
def goal_status():
    global state
    global state_info
    sub = rospy.Subscriber('move_base/status', GoalStatusArray, status_cb)
    soundhandle = SoundClient()
    last_state = -1

    snd_failed = rospy.get_param("~snd_failed", "")
    snd_accepted = rospy.get_param("~snd_accepted", "")
    snd_success = rospy.get_param("~snd_success", "")

    while not rospy.is_shutdown():

        # print "s: %d, l: %d" % (state, last_state)

        if state != last_state and last_state != -1:
            # Failed
            if state == 4:
                soundhandle.playWave(snd_failed)
            # Accepted
            if state == 1:
                soundhandle.playWave(snd_accepted)
            # Success
            if state == 3:
                soundhandle.playWave(snd_success)

            rospy.loginfo("State changed to: [%d] %s" % (state, state_info))

        last_state = state
        rospy.sleep(2)
Beispiel #19
0
class TalkBack:
    def __init__(self):
        rospy.on_shutdown(self.cleanup)
          
        self.voice = rospy.get_param("~voice", "voice_don_diphone")
        self.wavepath = rospy.get_param("~wavepath", "")
        
        # Create the sound client object
        self.soundhandle = SoundClient()
        
        rospy.sleep(1)
        self.soundhandle.stopAll()
        
        # Announce that we are ready for input
        self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
        rospy.sleep(1)
        self.soundhandle.say("Ready", self.voice)
        
        rospy.loginfo("Say one of the navigation commands...")

        # Subscribe to the recognizer output
        rospy.Subscriber('/recognizer/output', String, self.talkback)
        
    def talkback(self, msg):
        # Print the recognized words on the screen
        rospy.loginfo(msg.data)
        
        # Speak the recognized words in the selected voice
        self.soundhandle.say(msg.data, self.voice)
        
        # Uncomment to play one of the built-in sounds
        #rospy.sleep(2)
        #self.soundhandle.play(5)
        
        # Uncomment to play a wave file
        #rospy.sleep(2)
        #self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")

    def cleanup(self):
        rospy.loginfo("Shutting down talkback node...")
Beispiel #20
0
class play_touch:

	# Initial state
	def __init__(self):
		rospy.init_node('eddie2sim_touchplay_node')
		self.touchhandle = SoundClient()
		self.touch_volume = 1.0
		self.listener()

	# Call play function when subscribe to 'touch_sound' topic in string type
	def listener(self):
		rospy.Subscriber('touch_sound', String, self.play)
		rospy.spin()
	
	# Play desired sound to the user depend on which button have pushed by user
	def play(self, user_input):
		print(user_input.data)
		if user_input.data == "engage_process":
			self.touchhandle.playWave("{}/eddie2sim_ws/src/eddie2sim_sound/sound/engage_pressed.wav".format(home), self.touch_volume)
			rospy.sleep(5.0)
		elif user_input.data == "finish_process":
			self.touchhandle.playWave("{}/eddie2sim_ws/src/eddie2sim_sound/sound/finish_pressed.wav".format(home), self.touch_volume)
			rospy.sleep(2.0)
		elif user_input.data == "wrong_process":
			self.touchhandle.playWave("{}/eddie2sim_ws/src/eddie2sim_sound/sound/wrong_clicked.wav".format(home), self.touch_volume)
			rospy.sleep(4.0)
Beispiel #21
0
class TalkBack:
    def __init__(self):
        rospy.on_shutdown(self.cleanup)
          
        self.voice = rospy.get_param("~voice", "voice_don_diphone")
        self.wavepath = rospy.get_param("~wavepath", "")
        
        # Create the sound client object
        self.soundhandle = SoundClient()
        
        rospy.sleep(1)
        self.soundhandle.stopAll()
        
        # Announce that we are ready for input
        self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
        rospy.sleep(1)
        self.soundhandle.say("Ready", self.voice)
        
        rospy.loginfo("Say one of the navigation commands...")

        # Subscribe to the recognizer output
        rospy.Subscriber('/recognizer/output', String, self.talkback)
        
    def talkback(self, msg):
        # Print the recognized words on the screen
        rospy.loginfo(msg.data)
        
        # Speak the recognized words in the selected voice
        self.soundhandle.say(msg.data, self.voice)
        
        # Uncomment to play one of the built-in sounds
        #rospy.sleep(2)
        #self.soundhandle.play(5)
        
        # Uncomment to play a wave file
        #rospy.sleep(2)
        #self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")

    def cleanup(self):
        rospy.loginfo("Shutting down talkback node...")
Beispiel #22
0
class GoogleTTS:
    def __init__(self, caller_id):
        rospy.init_node('google_tts_node', anonymous = True, log_level=rospy.DEBUG)
        rospy.loginfo('{0} Create Google TTS node complete...'.format(caller_id))

        params = rospy.get_param("~", {})
        tts_params = params.pop("tts", {})
        self._topic_from = tts_params.pop('TOPIC_FROM', 'tts_speak')
        self._subscriber = rospy.Subscriber(self._topic_from, TTS, self._callback)
        self._soundhandle = SoundClient()
        self._caller_id = caller_id
        self._tmp_file_location = tts_params.pop('TMP_FILE_LOCATION', '/tmp/voice.wav')
        self._volume = tts_params.pop('VOLUME', '1.0')
        rospy.sleep(1)

    def _callback(self, msg):
        try:
            text, lang, sink = (msg.text, msg.lang, msg.sink)
        except Exception:
            raise ROSInterruptException('Error occur while parsing argument')
        if not text or not lang or not sink:
            raise ROSInterruptException('Argument can not be empty')

        rospy.loginfo('{0} Text = {1}, Lang = {2}, Sink = {3}'.format(
            self._caller_id, text, lang, sink
        ))

        if sink == 'google':
            tts = gTTS(text=text, lang=lang, slow=False)
            tts.save(self._tmp_file_location)
            self._soundhandle.playWave(self._tmp_file_location, self._volume)
        elif sink == 'festival':
            voice = 'voice_cmu_us_ahw_cg'
            self._soundhandle.say(text, voice, self._volume)      
        else:
            raise ROSInterruptException('Unknown sink {0}'.format(sink))

    def on_shutdown(self):
        rospy.loginfo('{0} Shutdown Google TTS node complete...'.format(self._caller_id))
        self._subscriber.unsubscribe(self._topic_from)
Beispiel #23
0
class WheelchairTalk:
    def __init__(self):
        rospy.on_shutdown(self.cleanup)

        self.voice = rospy.get_param("~voice", "voice_kal_diphone")#voice_don_diphone, voice_kal_diphone
        self.wavepath = rospy.get_param("~wavepath", "")
        self.command_to_phrase = COMMAND_TO_PHRASE  # this is deffined in wheelchairint/keywords_tocommand.py
        # Create the sound client object
        self.soundhandle = SoundClient()
        # Announce that we are ready for input
        rospy.sleep(2)
        self.soundhandle.stopAll()
        rospy.sleep(1)
        self.soundhandle.playWave(self.wavepath + "/R2D2.wav")
        rospy.sleep(2)
        self.soundhandle.say("I am ready", self.voice)
        rospy.sleep(1.5)
        self.soundhandle.say("Give me an order", self.voice)
        rospy.sleep(2)
        rospy.loginfo("Say one a commands...")

        # Subscribe to the recognizer output
        rospy.Subscriber('recognizer/output', String, self.rec_out_callback)
        r = rospy.Rate(0.5)
        while not rospy.is_shutdown():
#            rospy.loginfo("wheelchair talk is running correctly.")
            r.sleep()

    def rec_out_callback(self, msg):
        # Print the recognized words on the screen
        self.current_command = msg.data
        # Speak-out the recognized words.
        try:  # If the command was recognized
            self.soundhandle.say(self.command_to_phrase[self.current_command], self.voice)
        except:
            self.soundhandle.say("repeat", self.voice)


    def cleanup(self):
        self.soundhandle.say("Good bye", self.voice)
def goal_status():
    global state
    global state_info
    sub  = rospy.Subscriber('move_base/status', GoalStatusArray, status_cb)
    soundhandle = SoundClient()
    last_state = -1

    snd_failed = rospy.get_param("~snd_failed", "")
    snd_accepted = rospy.get_param("~snd_accepted", "")
    snd_success = rospy.get_param("~snd_success", "")

    while not rospy.is_shutdown():
        
       # print "s: %d, l: %d" % (state, last_state)
        
        if state != last_state and last_state != -1:
            # Failed
            if state == 4:
                soundhandle.playWave(snd_failed)
            # Accepted
            if state == 1:
                soundhandle.playWave(snd_accepted)
            # Success
            if state == 3:
                soundhandle.playWave(snd_success)
            
            rospy.loginfo("State changed to: [%d] %s" % (state, state_info))
                
        last_state = state
        rospy.sleep(2)
Beispiel #25
0
    def __init__(self):

        sc = SoundClient()
        path_to_sounds = os.path.dirname(__file__) + "/../../sounds/"

        # declare the coordinates of interest
        self.destinations = destinations
        self.goalReached = False
        # initiliaze
        rospy.init_node('map_navigation', anonymous=False)
        choice = self.choose()
        if (choice in range(len(self.destinations))):

            self.goalReached = self.moveToGoal(
                self.destinations[choice - 1].x_location,
                self.destinations[choice - 1].y_location)

        if (choice != 'q'):

            if (self.goalReached):
                rospy.loginfo("Congratulations!")
                #rospy.spin()

                sc.playWave(path_to_sounds + "ship_bell.wav")

                #rospy.spin()

            else:
                rospy.loginfo("Hard Luck!")
                sc.playWave(path_to_sounds + "short_buzzer.wav")

        while choice != 'q':
            choice = self.choose()
            if (choice in range(len(self.destinations))):

                self.goalReached = self.moveToGoal(
                    self.destinations[choice - 1].x_location,
                    self.destinations[choice - 1].y_location)

            if (choice != 'q'):

                if (self.goalReached):
                    rospy.loginfo("Congratulations!")
                    #rospy.spin()

                    sc.playWave(path_to_sounds + "ship_bell.wav")

                else:
                    rospy.loginfo("Hard Luck!")
                    sc.playWave(path_to_sounds + "short_buzzer.wav")
Beispiel #26
0
class play_sound:

    # Initial state
    def __init__(self):
        rospy.init_node('eddie2sim_soundplay_node', disable_signals=True)
        self.soundhandle = SoundClient()
        self.sound_volume = rospy.get_param("~sound_volume", 1.0)
        self.sound_to_play = rospy.get_param(
            "~sound_to_play",
            "{}/eddie2sim_ws/src/eddie2sim_sound/sound/base_station.wav".
            format(home))
        self.sound_cycle_time = rospy.get_param("~sound_cycle_time", 5.0)
        self.play()

    # Play desired sound to verify state of the robot
    def play(self):
        if self.sound_to_play == None or self.sound_cycle_time == 0:
            rospy.signal_shutdown("Quit")
        else:
            rospy.sleep(1)
            self.soundhandle.playWave(self.sound_to_play, self.sound_volume)
            rospy.sleep(self.sound_cycle_time)
class play_silent:

    # Initial state
    def __init__(self):
        rospy.init_node('eddie2sim_silentplay_node')
        self.silenthandle = SoundClient()
        self.silent_volume = 1.0
        self.silent_to_play = '{}/eddie2sim_ws/src/eddie2sim_sound/sound/obstacle.wav'.format(
            home)
        self.silent_cycle_time = 7.0
        self.listener()

    # Call play function when subscribe to 'silent' topic in string type
    def listener(self):
        rospy.Subscriber('silent', String, self.play)
        rospy.spin()

    # Alert the alarm sound to the user for give way to robot
    def play(self, data):
        rospy.sleep(1)
        self.silenthandle.playWave(self.silent_to_play, self.silent_volume)
        rospy.sleep(self.silent_cycle_time)
class play_alert:

    # Initial state
    def __init__(self):
        rospy.init_node('coconut_alert_node')
        self.alerthandle = SoundClient()
        self.alert_to_play = '{}/coconut_ws/src/coconut_sound/sound/obstacle.wav'.format(
            home)
        self.alert_cycle_time = 7.0
        self.listener()

    # Call play function when subscribe to 'alert' topic in string type
    def listener(self):
        rospy.Subscriber('alert', String, self.play)
        rospy.spin()

    # Alert the alarm sound to the user for give way to robot
    def play(self, data):
        rospy.sleep(1)
        self.alert_volume = rospy.get_param("/coconut_gui_node/alert_volume",
                                            1.0)
        self.alerthandle.playWave(self.alert_to_play, self.alert_volume)
        rospy.sleep(self.alert_cycle_time)
Beispiel #29
0
def callback(data):
	# To be sure it will bark only once, a StopBarking message was added
	if str(data) == "data: STOPBark":
		soundhandle = SoundClient()
		soundhandle.stopAll()
	# The first bark sound is played if the human approaches the robot a little further than the stopDistance 
	elif str(data) == "data: Bark":
		# Creates an instance of SoundClient
		soundhandle = SoundClient()
		#soundhandle.play(1) (DEBUG)
		soundhandle.playWave('/home/turtlebot/catkin_ws/src/maximum_bot/scripts/bark.wav')
		pubshoot = rospy.Publisher('bark', String) # (DEBUG)
		# Introduce a delay to be sure the whole sound will be played
		rospy.sleep(2)
	# The second bark sound is played if the human approaches the robot a a lot further than the stopDistance 
	elif str(data) == "data: Bark2":
		# Creates an instance of SoundClient
		soundhandle = SoundClient()
		#soundhandle.play(1) (DEBUG)
		soundhandle.playWave('/home/turtlebot/catkin_ws/src/maximum_bot/scripts/scream.wav')
		pubshoot = rospy.Publisher('bark', String) # (DEBUG)
		# Introduce a delay to be sure the whole sound will be played
		rospy.sleep(2)
class LetsDance(smach.State):
    def __init__(self, launch_follow_me_activation, launch_face_detection):
        smach.State.__init__(self, outcomes=['succeeded', 'failed'])
        self._launch_follow_me_activation = launch_follow_me_activation
        self._launch_face_detection = launch_face_detection

        # play music
        self._play_music_client = SoundClient()

        self._speech_pub = rospy.Publisher("/movo/voice/text",
                                           String,
                                           queue_size=1,
                                           latch=True)
        self._speech_text = String()

    def execute(self, userdata):
        rospy.loginfo('Executing state LETS_DANCE')
        try:
            self._play_music_client.playWave(
                '/home/movo/movo_ws/src/movo_demos/launch/voice_control/we_are_robots.wav'
            )
            self._launch_follow_me_activation.start()
        except:
            rospy.logwarn('failed to enable dance')
            return 'failed'

        music_duration = 20
        rospy.sleep(music_duration)

        self._speech_text.data = "You dance much better than Long fei. Thank you very much. I will take a rest now, good bye."
        self._speech_pub.publish(self._speech_text)
        rospy.sleep(5)
        self._launch_face_detection.shutdown()
        rospy.sleep(3)
        self._launch_follow_me_activation.shutdown()
        rospy.sleep(3)
        return 'succeeded'
Beispiel #31
0
class AudioController:
    def __init__(self, rospy, enable, play_stop, next, global_path, audiolist):
        self.rospy = rospy
        self.enable_button = Button(enable)
        self.play_stop = Button(play_stop)
        self.next = Button(next)
        self.sound_client = SoundClient()
        ac = actionlib.SimpleActionClient('sound_play', SoundRequestAction)
        ac.wait_for_server()
        self.global_path = global_path
        self.audiolist = audiolist
        self.selected = 0
        self.enable = False
        self.song_init = ''
        self.song_exit = ''
        # Load configuration audio
        if self.rospy.has_param('~audio/song/init'):
            self.song_init = self.rospy.get_param("~audio/song/init")
        if self.rospy.has_param('~audio/song/exit'):
            self.song_exit = self.rospy.get_param("~audio/song/exit")
        self.rospy.loginfo("Init:%s - Exit:%s" %
                           (self.song_init, self.song_exit))

    def startAudio(self):
        self.rospy.loginfo("Play %s" % self.audiolist[self.selected])
        self.sound_client.playWave(self.global_path + "/" +
                                   self.audiolist[self.selected])

    def init(self):
        #self.rospy.loginfo("Sound controller status[%d]"%self.enable)
        if self.enable:
            if self.song_init != '':
                # Start Hello robot
                self.sound_client.playWave(self.global_path + "/" +
                                           self.song_init)
        else:
            if self.song_exit != '':
                # Start Exit robot
                self.sound_client.playWave(self.global_path + "/" +
                                           self.song_exit)

    def update(self, buttons):
        if self.enable:
            if self.play_stop.update(buttons):
                self.startAudio()
            if self.next.update(buttons):
                # Increase counter
                self.selected += 1
                if self.selected >= len(self.audiolist):
                    self.selected = 0
                # Start new audio
                self.startAudio()
        if self.enable_button.update(buttons):
            # update status
            self.enable = not self.enable
            # Launch audio start/stop
            self.init()
Beispiel #32
0
class speech_control():
    def __init__(self):
        self.musicPath = '/home/keaixin/catkin_ws/src/homework/sounds/youbelongwithme.mp3'
        self.question_start_signal = "~/home/keaixin/catkin_ws/src/homework/sounds/question_start_signal.wav"
        # Initialize sound client
        self.sh = SoundClient(blocking=True)
        #self.voice = rospy.get_param("~voice", "voice_don_diphone")
        self.voice = rospy.get_param("~voice", "voice_kal_diphone")
        rospy.sleep(1)
        self.sh.stopAll()
        rospy.sleep(1)
        self.tuling_res = None
        self.baiducallback_string = None
        self.is_answer_question = False
        # Publisher topics
        self.pub_to_tuling_topic_name = rospy.get_param(
            "pub_to_tuling_topic_name ", "/tuling_topic")
        self.tuling_pub = rospy.Publisher(self.pub_to_tuling_topic_name,
                                          String,
                                          queue_size=1)
        self.pub_to_tur_control = rospy.get_param("pub_to_tur_control",
                                                  "voiceWords")
        self.tur_control_pub = rospy.Publisher(self.pub_to_tur_control,
                                               String,
                                               queue_size=1)

        # Subscriber topics
        self.sub_baidu_back_topic_name = rospy.get_param(
            "sub_baidu_back_topic_name", "/my_voice")
        rospy.Subscriber(self.sub_baidu_back_topic_name, String,
                         self.baiduCallback)
        self.sub_tuling_response_topic_name = rospy.get_param(
            "sub_tuling_response_topic_name", "/tuling_translate_result")
        rospy.Subscriber(self.sub_tuling_response_topic_name, String,
                         self.tulingCallback)

    def tulingCallback(self, msg):
        self.tuling_res = msg.data

    def baiduCallback(self, msg):
        self.baiducallback_string = msg.data
        if msg.data.strip() == '':
            print 111111
            self.sh.say("sorry I did not clearly hear you", self.voice)
            self.sh.say("could you say it again, please", self.voice)
            self.is_answer_question = False
        else:
            string = msg.data
            print("[your question]:", string)
            symbols = ["!", "?", ".", ",", ";", ":"]
            output = []
            if string[-1] in symbols:
                string = string[:-1]
            for part in string.lstrip().split(","):
                for word in part.split():
                    for symbol in symbols:
                        if symbol in word:
                            word = word[:-1]
                    output.append(word)
            output = [item.lower() for item in output]
            #print (output)

            if "failed" in output:
                self.sh.say("sorry I did not clearly hear you", self.voice)
                self.sh.say("could you say it again, please", self.voice)
                os.system('rostopic pub -1 /kws_data std_msgs/String "jack" ')
                self.is_answer_question = False

            elif "hi" in output or "hello" in output or "hey" in output:
                if "time" in output:
                    self.sh.say("Are you asking me the time now", self.voice)
                    self.tuling_pub.publish("现在几点了")
                    rospy.sleep(2)
                    print("[jack's answer]:", self.tuling_res)
                    self.sh.say(str(self.tuling_res), self.voice)
                elif "weather" in output:
                    self.sh.say("Are you asking me about the weather today",
                                self.voice)
                    self.tuling_pub.publish("今天天津天气")
                    rospy.sleep(1)
                    print("[jack's answer]:", self.tuling_res)
                    self.sh.say(str(self.tuling_res), self.voice)
                elif "joke" in output:
                    self.sh.say("ok I will tell you a joke", self.voice)
                    self.tuling_pub.publish("讲一个笑话吧")
                    rospy.sleep(1)
                    print("[jack's answer]:", self.tuling_res)
                    self.sh.say(str(self.tuling_res), self.voice)
                elif "story" in output or "sorry" in output:
                    self.sh.say("ok I will tell you a story", self.voice)
                    self.tuling_pub.publish("讲一个故事吧")
                    rospy.sleep(1)
                    print("[jack's ansewer]:", self.tuling_res)
                    self.sh.say(str(self.tuling_res), self.voice)
                elif "milk" in output or "music" in output:
                    self.sh.say("ok I will put a short piece of music for you",
                                self.voice)
                    print(
                        "[jack's answer]:ok I will put a short piece of music for you"
                    )
                    print('playing music...')
                    self.sh.playWave(self.musicPath)
                    self.sh.say("that's all, do you like it", self.voice)
                    print("[jack's answer]:that's all, do you like it")
                    rospy.sleep(5)
                    os.system(
                        'rostopic pub -1 /voiceWakeup std_msgs/String "ok" ')

            elif self.is_answer_question is False:
                if ("dog" in output or "photo" in output or "go" in output
                        or "out" in output or "back" in output):
                    if "want" in output or "i" in output or "to" in output or "i'll" in output or string == "i want to go":
                        self.sh.say(
                            "i heard that you want to go, all right, i'm ready",
                            self.voice)
                        self.tur_control_pub.publish("go")
                        print(
                            "[jack's answer]: i heard that you want to go, all right, i'm ready"
                        )
                        rospy.sleep(5)
                        os.system(
                            'rostopic pub -1 /voiceWakeup std_msgs/String "ok" '
                        )
                        self.is_answer_question = False
                    elif "out" in output or "let's" in output or "door" in output or "dog" in output or string == "let's go out":
                        self.sh.say("ok let's go to the taxi", self.voice)
                        self.tur_control_pub.publish("out")
                        print("[jack's answer]: ok let's go to the taxi")
                        rospy.sleep(5)
                        os.system(
                            'rostopic pub -1 /voiceWakeup std_msgs/String "ok" '
                        )
                        self.is_answer_question = False
                    elif "back" in output or "you" in output or string == "you can go back":
                        self.sh.say("ok, wish you a good trip, goodbye",
                                    self.voice)
                        self.tur_control_pub.publish("back")
                        print(
                            "[jack's answer]: ok, wish you a good trip, goodbye"
                        )
                        rospy.sleep(5)
                        os.system(
                            'rostopic pub -1 /voiceWakeup std_msgs/String "ok" '
                        )
                        self.is_answer_question = False
                else:
                    self.sh.say("sorry I did not clearly hear you", self.voice)
                    self.sh.say("could you say it again, please", self.voice)
                    os.system(
                        'rostopic pub -1 /kws_data std_msgs/String "jack" ')

            self.answer_question(output)

    def answer_question(self, output):
        self.sh.stopAll()
        if self.is_answer_question == True:
            if "time" in output:
                self.sh.say("Are you asking me the time now", self.voice)
                self.tuling_pub.publish("现在几点了")
                rospy.sleep(1)
                print self.tuling_res
                self.sh.say(str(self.tuling_res), self.voice)
            elif "weather" in output:
                self.sh.say("Are you asking me about the weather today",
                            self.voice)
                self.tuling_pub.publish("今天天津天气")
                rospy.sleep(1)
                print self.tuling_res
                self.sh.say(str(self.tuling_res), self.voice)
            elif "joke" in output:
                self.sh.say("ok I will tell you a joke", self.voice)
                self.tuling_pub.publish("讲一个笑话吧")
                rospy.sleep(1)
                print self.tuling_res
                self.sh.say(str(self.tuling_res), self.voice)
            elif "story" in output or "sorry" in output:
                self.sh.say("ok I will tell you a story", self.voice)
                self.tuling_pub.publish("讲一个故事吧")
                rospy.sleep(1)
                print self.tuling_res
                self.sh.say(str(self.tuling_res), self.voice)
            elif "milk" in output or "music" in output:
                self.sh.say("ok I will put a short piece of music for you",
                            self.voice)
                print('playing music')
                self.sh.playWave(self.musicPath)
                self.sh.say("that's all, do you like it", self.voice)
Beispiel #33
0
#!/usr/bin/env python


import roslib
import rospy
from sound_play.libsoundplay import SoundClient

rospy.init_node('play_sound')
#Create a sound client instance
sound_client = SoundClient()
#wait for sound_play node to connect to publishers (otherwise it will miss first published msg)
rospy.sleep(2)
#Method 1: Play Wave file directly from Client
sound_client.playWave('/home/asimov/robo_ws/src/saya_hospitality-ros-pkg/saya_hospitality_communication/saya_hospitality_audio/sound_snippets/speech6.wav')
class follow_person:
	def __init__(self):
		self.bridge = CvBridge()
		
		image_sub = message_filters.Subscriber("camera/rgb/image_color", Image)
		dist_sub = message_filters.Subscriber("distance_person", Distance)
		sonar_sub = message_filters.Subscriber("/sonar", SonarArray)
		rospy.Subscriber('node_initializer', String, self.init_node)
		
		self.ts = message_filters.ApproximateTimeSynchronizer([image_sub, dist_sub, sonar_sub], 10, 0.5)
		#self.ts = message_filters.ApproximateTimeSynchronizer([image_sub, dist_sub], 10, 0.5)
		self.ts.registerCallback(self.callback)

		# initialize the soundplay service
		self.soundhandle = SoundClient()
		self.voice = rospy.get_param("~voice", "voice_cmu_us_clb_arctic_clunits")
		self.wavepath = rospy.get_param("~wavepath", "")
		
		self.cmd_vel_pub = rospy.Publisher("/cmd_vel", Twist, queue_size=10)
		self.motor_state_pub = rospy.Publisher("/cmd_motor_state", MotorState, queue_size=10)
		self.speech_pub = rospy.Publisher("/speech", String, queue_size=10)
		self.crt = False
		self.fala = 1
		self.alo = ''

	def init_node(self, alo):
		self.alo = alo.data
		if self.alo == 'followme':
			self.crt = True
			print 'Received \'go\' message.'
		elif self.alo in ['right', 'left']:
			self.crt = False
			print 'Received \'stop\' message.'

		
	def callback(self, rgb_data, dist_data, sonar_data):
	#def callback(self, rgb_data, dist_data):
		# self.crt = True
		# print self.crt

		vel = Twist()
		state = MotorState()
		state.state = 4
		self.motor_state_pub.publish(state)

		vel.linear.x = 0.0
		vel.angular.z = 0.0

		if self.alo == 'right':
			vel.linear.x = 0.0
			vel.angular.z = -0.2
			self.cmd_vel_pub.publish(vel)
			rospy.sleep(4)
			self.alo = ''
			self.crt = False

		elif self.alo == 'left':
			vel.linear.x = 0.0
			vel.angular.z = 0.2
			self.cmd_vel_pub.publish(vel)
			rospy.sleep(2)
			vel.linear.x = 0.0
			vel.angular.z = 0.0
			self.cmd_vel_pub.publish(vel)
			rospy.sleep(2)
			self.alo = ''
			self.crt = False			
			self.soundhandle.playWave(self.wavepath + "Final01.wav")
			rospy.sleep(20)
			self.soundhandle.playWave(self.wavepath + "Final02.wav")
			rospy.sleep(22)
			self.soundhandle.playWave(self.wavepath + "Final03.wav")
			rospy.sleep(23)
			self.soundhandle.playWave(self.wavepath + "Final04.wav")
			rospy.sleep(14)
			self.soundhandle.playWave(self.wavepath + "Final05.wav")
			rospy.sleep(14)
			self.soundhandle.playWave(self.wavepath + "Final06.wav")
			rospy.sleep(20)
			self.soundhandle.playWave(self.wavepath + "Final07.wav")
			rospy.sleep(30)

		elif self.crt:
			try:
				image = self.bridge.imgmsg_to_cv2(rgb_data, "bgr8")
			except CvBridgeError, e:
				print e

			(rows, cols, channels) = image.shape
			hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
			px = cols/2
			py = rows/2

			h_high = 179
			h_low = 160
			s_high = 255
			s_low = 130
			v_high = 255
			v_low = 0

			lower = np.array([h_low, s_low, v_low])
			upper = np.array([h_high, s_high, v_high])
			
			# Threshold the HSV image to get only orange colors
			mask = cv2.inRange(hsv, lower, upper)
			
			#erosion
			kernel = np.ones((5,5),np.uint8)
			erosion = cv2.erode(mask,kernel,iterations=3)
			
			#dilation
			dilation = cv2.dilate(erosion,kernel,iterations=3)

			img = cv2.medianBlur(dilation,21)
			moment = cv2.moments(img)
			try:
				px = int(moment['m10']/moment['m00'])
				py = int(moment['m01']/moment['m00'])
				area = moment['m00']

			except ZeroDivisionError:
				pass

			cv2.circle(img, (px, py), 3, (171,110,0), 2)
			cv2.circle(img, (px, py), 3, (171,110,0), 2)

			#cv2.imshow('Color Segmentation', img)

			sonar_array = list(sonar_data.ranges)
			
			# if min(sonar_array[1:3]) < 0.3:
			# 	vel.linear.x = 0.0
			# 	vel.angular.z = -0.5
			# 	self.fala = 1
			# 	self.cmd_vel_pub.publish(vel)
			# elif min(sonar_array[3:5]) < 0.3:
			# 	vel.linear.x = 0.0
			# 	vel.angular.z = 0.0
			# 	self.fala = 1
			# 	self.cmd_vel_pub.publish(vel)
			# elif min(sonar_array[5:7]) < 0.3:
			# 	vel.linear.x = 0.0
			# 	vel.angular.z = 0.5
			# 	self.fala = 1
			# 	self.cmd_vel_pub.publish(vel)
			# elif min(sonar_array[10:14]) < 0.5:
			# 	vel.linear.x = 0.0
			# 	vel.angular.z = 0.0
			# 	self.fala = 1
			# 	self.cmd_vel_pub.publish(vel)
			# else:
				#print "ok"
			if dist_data.distance > 0.8 and dist_data.distance < 1.5: 
				self.motor_state_pub.publish(state)
				#rospy.loginfo('lim-left: {0} < px: {1} < lim-right: {2}'.format((cols/3), px, (cols - (cols/3))))
				if ((cols/3) > px and px > 0) or (dist_data.y > 0.2):# or max(sonar_array[0:3]) > 0.4:
					# Goes to the left
					# rospy.loginfo('left <<<<<<<<')
					vel.linear.x = 0.0
					vel.angular.z = 0.3
				elif ((cols - (cols/3)) < px and px < cols) or (dist_data.y < -0.2):# or max(sonar_array[5:8]) > 0.4:
					# Goes to the right
					# rospy.loginfo('right >>>>>>>>')
					vel.linear.x = 0.0
					vel.angular.z = -0.3
				# elif max(sonar_array[8:15]) < 0.4:
				#  	vel.linear.x = 0.0
				#  	vel.angular.z = 0.0
				else:
					# rospy.loginfo('Distancia: %.4f' % dist_data.distance)
					# Foward
					self.fala = 0
					vel.linear.x = 0.2
					#vel.linear.x =  0.25 * math.sqrt(dist_data.x**2 + dist_data.y**2)
					vel.angular.z = 0.0
				
				self.cmd_vel_pub.publish(vel)

			else:
				if dist_data.distance < 0.8 and self.fala == 0:
					#self.crt = False
					self.speech_pub.publish("I am close to you.")
					self.fala = 1
				elif dist_data.distance > 1.5 and self.fala == 0:
					# self.speech_pub.publish("You are very fast. Please, step back and wait for me.")
					self.speech_pub.publish("You are very fast. Please, wait for me.")
					self.fala = 1
				else:
					pass
				vel.linear.x = 0.0
				vel.angular.z = 0.0


		self.cmd_vel_pub.publish(vel)

		cv2.waitKey(3)
class Supervisor:
    """ the state machine of the turtlebot """
    def __init__(self):
        rospy.init_node('turtlebot_supervisor', anonymous=True)

        self.soundhandle = SoundClient()

        # current pose
        self.x = 0
        self.y = 0
        self.theta = 0

        # pose goal
        self.x_g = 0
        self.y_g = 0
        self.theta_g = 0
        self.pose_goal_backlog = []

        # init flag used for running init function for each state
        self.init_flag = 0

        # Landmark lists
        self.stop_signs = landmarks.StopSigns(
            dist_thresh=STOP_SIGN_DIST_THRESH
        )  # List of coordinates for all stop signs
        self.animal_waypoints = landmarks.AnimalWaypoints(
            dist_thresh=ANIMAL_DIST_THRESH)
        self.explore_waypoints = landmarks.ExploreWaypoints()

        # flag that determines if the rescue can be initiated
        self.rescue_on = False
        #flag to keep sound from repeating
        self.play_rescue_sound = True
        self.victory_sound = True

        # flag that determines if the robot has found a bicycle and should honk
        #self.bicycles = []
        self.honk = False
        self.playsound = True

        # string for target animal
        self.target_animal = None

        # status flag for traveling salesman circuit received
        self.tsales_circuit_received = 1

        # status flag for amcl init received
        self.amcl_init_received = False

        # status flag for whether exploration has started
        self.explore_started = False

        # lock waypoints
        self.lock_animal_waypoints = 0

        # status flag for whether navigating to animal while exploring
        self.nav_to_animal_CCW = False
        self.nav_to_animal_CW = False

        # time of starting to spin to animal
        self.time_of_spin = 0.0

        # status flag to check if current theta is smaller than goal theta
        self.prev_th_less_than_g = False

        # current mode
        self.mode = Mode.IDLE
        self.modeafterstop = Mode.IDLE
        self.modeafterhonk = Mode.IDLE
        self.last_mode_printed = None

        self.nav_goal_publisher = rospy.Publisher('/cmd_nav',
                                                  Pose2D,
                                                  queue_size=10)
        self.cmd_vel_publisher = rospy.Publisher('/cmd_vel',
                                                 Twist,
                                                 queue_size=10)
        self.rescue_ready_publisher = rospy.Publisher('/ready_to_rescue',
                                                      Bool,
                                                      queue_size=10)
        self.tsales_request_publisher = rospy.Publisher('/tsales_request',
                                                        TSalesRequest,
                                                        queue_size=10)

        rospy.Subscriber('/detector/stop_sign', DetectedObject,
                         self.stop_sign_detected_callback)
        rospy.Subscriber('/move_base_simple/goal', PoseStamped,
                         self.rviz_goal_callback)
        # rospy.Subscriber('/detector/bird', DetectedObject, self.animal_detected_callback)
        rospy.Subscriber('/detector/cat', DetectedObject,
                         self.animal_detected_callback)
        rospy.Subscriber('/detector/dog', DetectedObject,
                         self.animal_detected_callback)
        # rospy.Subscriber('/detector/horse', DetectedObject, self.animal_detected_callback)
        # rospy.Subscriber('/detector/sheep', DetectedObject, self.animal_detected_callback)
        # rospy.Subscriber('/detector/cow', DetectedObject, self.animal_detected_callback)
        rospy.Subscriber('/detector/elephant', DetectedObject,
                         self.animal_detected_callback)
        # rospy.Subscriber('/detector/bear', DetectedObject, self.animal_detected_callback)
        # rospy.Subscriber('/detector/zebra', DetectedObject, self.animal_detected_callback)
        # rospy.Subscriber('/detector/giraffe', DetectedObject, self.animal_detected_callback)
        rospy.Subscriber('/detector/bicycle', DetectedObject,
                         self.bicycle_detected_callback)
        rospy.Subscriber('/rescue_on', Bool, self.rescue_on_callback)
        rospy.Subscriber('/cmd_state', Int8, self.cmd_state_callback)
        rospy.Subscriber('/tsales_circuit', TSalesCircuit,
                         self.tsales_circuit_callback)
        rospy.Subscriber('/initialpose', PoseWithCovarianceStamped,
                         self.amcl_init_callback)

        self.trans_listener = tf.TransformListener()

    def cmd_state_callback(self, msg):
        self.mode = Mode(msg.data)

    def rviz_goal_callback(self, msg):
        """ callback for a pose goal sent through rviz """

        self.x_g = msg.pose.position.x
        self.y_g = msg.pose.position.y
        rotation = [
            msg.pose.orientation.x, msg.pose.orientation.y,
            msg.pose.orientation.z, msg.pose.orientation.w
        ]
        euler = tf.transformations.euler_from_quaternion(rotation)
        self.theta_g = euler[2]

    def stop_sign_detected_callback(self, msg):
        """ callback for when the detector has found a stop sign. Note that
        a distance of 0 can mean that the lidar did not pickup the stop sign at all """

        # Check the location is valid i.e. 3rd element is non-zero
        if msg.location_W[2] == 1.0:
            observation = msg.location_W[:2]
            self.stop_signs.add_observation(observation)

    def stop_check(self):
        """ checks if within stopping threshold """
        current_pose = [self.x, self.y]
        dist2stop = []
        for i in range(self.stop_signs.locations.shape[0]):
            dist2stop.append(
                np.linalg.norm(current_pose - self.stop_signs.locations[i, :])
            )  # Creates list of distances to all stop signs
        return any(dist < STOP_MIN_DIST for dist in dist2stop)

    def animal_detected_callback(self, msg):
        """ callback for when the detector has found an animal """

        # Check the location is valid i.e. 3rd element is non-zero
        if msg.location_W[2] == 1.0:
            pose = np.array([self.x, self.y, self.theta])
            bbox_height = msg.corners[3] - msg.corners[1]

            observation = msg.location_W[:2]

            animal_type = msg.name

            # only add animals in the exploration states
            if not self.lock_animal_waypoints:
                idx = self.animal_waypoints.add_observation(
                    observation, pose, bbox_height, animal_type,
                    msg.location_W[3])

                # Finds number of observations of this existing detection
                n = self.animal_waypoints.observations_count[idx]
                # If first detection, stop bacon and pinpoint
                if n == 1:
                    # Stop Bacon in its tracks and pinpoint
                    # self.x_g = self.x
                    # self.y_g = self.y

                    # Set the attitude to "center" detected box in image frame
                    # self.theta_g = self.animal_waypoints.animal_theta_g[idx]
                    # self.theta_g = self.theta

                    if self.animal_waypoints.animal_theta_g[idx] < self.theta:
                        self.nav_to_animal_CW = True

                    elif self.animal_waypoints.animal_theta_g[idx] > self.theta:
                        self.nav_to_animal_CCW = True

                    t_first = rospy.get_rostime().to_sec()
                    self.time_of_spin = t_first
                    self.animal_waypoints.first_detection(t_first)

                    # self.nav_to_animal = True

                elif self.close_to(self.x, self.y,
                                   self.animal_waypoints.animal_theta_g[idx]):
                    self.nav_to_animal_CW = False
                    self.nav_to_animal_CCW = False
                    self.x_g = self.pose_goal_backlog[0]
                    self.y_g = self.pose_goal_backlog[1]
                    self.theta_g = self.pose_goal_backlog[2]

                    # self.nav_to_animal = False

                # Once the nominal number of animal measurements is achieved, reset to prior goal pose
                elif n > ANIMAL_NOM_OBSERVATIONS:
                    self.nav_to_animal_CW = False
                    self.nav_to_animal_CCW = False
                    self.x_g = self.pose_goal_backlog[0]
                    self.y_g = self.pose_goal_backlog[1]
                    self.theta_g = self.pose_goal_backlog[2]

                # In case the nominal number of measurements never occurs (likely from spurious objection detected initially),
                # wait a fixed amount of time before moving on to prior goal pose
                elif rospy.get_rostime().to_sec(
                ) > self.animal_waypoints.time_first_detection[
                        idx] + MAX_PINPOINT_TIME:
                    self.nav_to_animal_CW = False
                    self.nav_to_animal_CCW = False
                    self.x_g = self.pose_goal_backlog[0]
                    self.y_g = self.pose_goal_backlog[1]
                    self.theta_g = self.pose_goal_backlog[2]

                    # self.nav_to_animal = False

                    print 'timed out on animal'

    def bicycle_detected_callback(self, msg):
        """callback for when the detector has found a bicycle"""
        self.honk = True
        self.bike_detected_start = rospy.get_rostime()

    def rescue_on_callback(self, msg):
        """callback for when the rescue is ready"""
        self.rescue_on = msg.data

    def nav_to_pose(self):
        """ sends the current desired pose to the navigator """
        nav_g_msg = Pose2D()
        nav_g_msg.x = self.x_g
        nav_g_msg.y = self.y_g
        nav_g_msg.theta = self.theta_g

        self.nav_goal_publisher.publish(nav_g_msg)

    def stay_idle(self):
        """ sends zero velocity to stay put """
        vel_g_msg = Twist()
        self.cmd_vel_publisher.publish(vel_g_msg)

    def turn_CCW(self):
        """turns the robot left when detecting animal"""
        twist = Twist()
        twist.linear.x = 0
        twist.linear.y = 0
        twist.linear.z = 0
        twist.angular.x = 0
        twist.angular.y = 0
        twist.angular.z = 0.1
        self.cmd_vel_publisher.publish(twist)

    def turn_CW(self):
        """turns the robot CW when detecting animal"""
        twist = Twist()
        twist.linear.x = 0
        twist.linear.y = 0
        twist.linear.z = 0
        twist.angular.x = 0
        twist.angular.y = 0
        twist.angular.z = -0.1
        self.cmd_vel_publisher.publish(twist)

    def close_to(self, x, y, theta):
        """ checks if the robot is at a pose within some threshold """
        # if (abs(x-self.x)<POS_EPS) and (abs(y-self.y)<POS_EPS):
        #     # check if angle is within threshold
        #     if abs(theta-self.theta)<THETA_EPS:
        #         return True
        #     # check if angle occured during rotation (between current and previous angle)
        #     elif (self.theta > theta) and self.prev_th_less_than_g:
        #         return True
        #     elif (self.theta < theta) and not self.prev_th_less_than_g:
        #         return True

        # return False

        return (abs(x - self.x) < POS_EPS and abs(y - self.y) < POS_EPS
                and abs(theta - self.theta) < THETA_EPS)

    def init_stop_sign(self):
        """ initiates a stop sign maneuver """

        self.stop_sign_start = rospy.get_rostime()

    def has_stopped(self):
        """ checks if stop sign maneuver is over """

        return (self.mode == Mode.STOP
                and (rospy.get_rostime() - self.stop_sign_start) >
                rospy.Duration.from_sec(STOP_TIME))

    def has_crossed(self):
        """ checks if crossing maneuver is over """
        current_pose = [self.x, self.y]
        dist2stop = []
        for i in range(self.stop_signs.locations.shape[0]):
            dist2stop.append(
                np.linalg.norm(current_pose - self.stop_signs.locations[i, :])
            )  # Creates list of distances to all stop signs
        return (
            self.mode == Mode.CROSS and all(dist > CROSS_MIN_DIST
                                            for dist in dist2stop)
        )  # (rospy.get_rostime()-self.cross_start)>rospy.Duration.from_sec(CROSSING_TIME))

    def pop_animal(self):
        # remove the animal from the rescue queue
        waypoint, animal_type = self.animal_waypoints.pop()
        print waypoint, animal_type

        if np.any(waypoint == None):
            pass
        else:
            self.x_g = waypoint[0]
            self.y_g = waypoint[1]
            self.theta_g = waypoint[2]
            self.target_animal = animal_type

    def init_rescue_animal(self):
        """ initiates an animal rescue """

        self.rescue_start = rospy.get_rostime()
        self.mode = Mode.RESCUE_ANIMAL

    def has_rescued(self):
        """checks if animal has been rescued"""

        return (self.mode == Mode.RESCUE_ANIMAL
                and (rospy.get_rostime() - self.rescue_start) >
                rospy.Duration.from_sec(RESCUE_TIME))

    def init_plan_rescue(self):
        print('init plan rescue')
        self.tsales_circuit_received = 0
        self.lock_animal_waypoints = 1

        print(self.animal_waypoints.poses)
        print(self.animal_waypoints.observations_count)
        self.animal_waypoints.cull(ANIMAL_MIN_OBSERVATIONS)
        print(self.animal_waypoints.poses)
        print(self.animal_waypoints.observations_count)

        if self.animal_waypoints.poses.shape[0] > 0:
            tsales_request = TSalesRequest()
            tsales_request.goal_x = self.animal_waypoints.poses[:, 0].tolist()
            tsales_request.goal_y = self.animal_waypoints.poses[:, 1].tolist()
            tsales_request.do_fast = 0
            print('publish tsales request')
            self.tsales_request_publisher.publish(tsales_request)
        else:
            self.tsales_circuit_received = 1

    def tsales_circuit_callback(self, msg):
        print('tsales circuit callback')
        try:
            circuit = np.array(map(int, msg.circuit))
        except:
            rospy.loginfo('Traveling salesman failed')
            self.tsales_circuit_received = 1
            return

        if circuit.shape[0] == self.animal_waypoints.poses.shape[0]:
            self.animal_waypoints.reorder(circuit)
        else:
            rospy.loginfo('Traveling salesman failed')

        self.tsales_circuit_received = 1

    def amcl_init_callback(self, msg):
        print('amcl init callback')
        # update pose
        self.x = msg.pose.pose.position.x
        self.y = msg.pose.pose.position.y
        rotation = [
            msg.pose.pose.orientation.x, msg.pose.pose.orientation.y,
            msg.pose.pose.orientation.z, msg.pose.pose.orientation.w
        ]
        euler = tf.transformations.euler_from_quaternion(rotation)
        self.theta = euler[2]

        self.amcl_init_received = True

    def init_explore(self):
        print('init explore')
        self.explore_started = True

        # use the following for real robot
        exploration_target_waypoints = np.array([
            [10.604, 9.454, -0.996],  # exit parking lot
            [10.098, 8.857, -2.633],  # first stop sign on right
            [10.505, 7.226, -0.948],  # end of one-way on right side
            [9.862, 6.676, -2.880],  # look towards curved forest
            [8.724, 7.894, 2.169],  # move down next to main intersection
            [9.584, 8.309, 0.387],  # move next to angled stop sign
            [10.505, 7.226, -0.948],  # end of one-way on right side
            [11.125, 6.987,
             0.550],  # natural turn left from one-way to side street
            [11.139, 8.821, 2.178],  # move down next to main intersection
            [10.098, 8.857, -2.633],  # back to stop sign on right
            [8.875, 8.163, -2.567],  # move across main intersection
            [8.399, 8.897, 0.586]  # move towards parking lot
            # [8.756, 9.288, -0.996] # park

            # Position(10.447, 7.391, 0.000), Orientation(0.000, 0.000, -0.478, 0.879) = Angle: -0.996
            # [9.798, 8.728, -2.544],
            # [10.702, 7.249, -0.936],
            # [9.874, 6.624, 2.508],
            # [8.726, 7.992,  2.057],
            # [10.449, 9.007, 0.483],
            # [11.586, 7.830, -1.044],
            # [10.491, 6.584, -3.071],
            # [8.680, 8.073, 2.155]

            # [0.4, 0.3, np.pi/2],
        ])

        # use the following for simulation
        # exploration_target_waypoints = np.array([
        #     [3.4, 2.8, np.pi/2],
        #     [2.5, 1.5, np.pi],
        #     [0.5, 1.6, np.pi],
        #     [0.3, 0.3, 0],
        #     [3.3, 0.3, np.pi/2]
        #     ])

        for i in range(len(exploration_target_waypoints)):
            self.explore_waypoints.add_exploration_waypoint(
                exploration_target_waypoints[i, :])

    def pop_explore_waypoint(self):
        # remove the exploration waypoint from the exploration queue
        waypoint = self.explore_waypoints.pop()
        print waypoint

        if np.any(waypoint == None):
            pass
        else:
            self.x_g = waypoint[0]
            self.y_g = waypoint[1]
            self.theta_g = waypoint[2]

            # Save prior goal pose for animal detection
            self.pose_goal_backlog = [self.x_g, self.y_g, self.theta_g]

    def loop(self):
        """ the main loop of the robot. At each iteration, depending on its
        mode (i.e. the finite state machine's state), if takes appropriate
        actions. This function shouldn't return anything """

        try:
            (translation, rotation) = self.trans_listener.lookupTransform(
                '/map', '/base_footprint', rospy.Time(0))
            self.x = translation[0]
            self.y = translation[1]
            euler = tf.transformations.euler_from_quaternion(rotation)
            self.theta = euler[2]

            if self.theta < self.theta_g:
                self.prev_th_less_than_g = True

        except (tf.LookupException, tf.ConnectivityException,
                tf.ExtrapolationException):
            pass

        #self.bicycles.publish_all()
        self.stop_signs.publish_all()
        self.animal_waypoints.publish_all()

        # logs the current mode
        if not (self.last_mode_printed == self.mode):
            rospy.loginfo("Current Mode: %s", self.mode)
            self.last_mode_printed = self.mode
            self.init_flag = 0

        # checks wich mode it is in and acts accordingly
        if self.mode == Mode.IDLE:
            if self.amcl_init_received == True:
                self.amcl_init_received = False
                self.mode = Mode.EXPLORE
                # self.mode = Mode.NAV

            else:
                # send zero velocity
                self.stay_idle()

        elif self.mode == Mode.BIKE_STOP:
            if self.honk:

                if (self.playsound):
                    self.soundhandle.playWave(
                        '/home/aa274/catkin_ws/src/asl_turtlebot/BICYCLE.wav',
                        1.0)
                    self.playsound = False
                    print("Playing the sound")

            if (rospy.get_rostime() - self.bike_detected_start >
                    rospy.Duration.from_sec(BIKE_STOP_TIME)):
                self.honk = False
                self.playsound = True
                print("I'm stopping the honking")
                self.mode = self.modeafterhonk
            else:
                self.stay_idle()

        elif self.mode == Mode.STOP:
            # at a stop sign

            if not self.init_flag:
                self.init_flag = 1
                self.init_stop_sign()

            if self.has_stopped():
                self.mode = Mode.CROSS
            else:
                self.stay_idle()

        elif self.mode == Mode.CROSS:
            # crossing an intersection

            if self.has_crossed():
                self.mode = self.modeafterstop
            else:
                self.nav_to_pose()

            if self.close_to(self.x_g, self.y_g, self.theta_g):
                if self.modeafterstop == Mode.NAV:
                    self.mode = Mode.IDLE
                elif self.modeafterstop == Mode.GO_TO_ANIMAL:
                    self.mode = Mode.RESCUE_ANIMAL

            if self.honk:
                self.mode = Mode.BIKE_STOP
                self.modeafterhonk = Mode.CROSS

        elif self.mode == Mode.NAV:
            self.lock_animal_waypoints = 0

            if self.close_to(self.x_g, self.y_g, self.theta_g):
                self.mode = Mode.GO_TO_EXPLORE_WAYPOINT
            else:
                if self.stop_check():  # Returns True if within STOP_MIN_DIST
                    self.mode = Mode.STOP
                    self.modeafterstop = Mode.NAV
                else:
                    self.nav_to_pose()

            if self.honk:
                self.mode = Mode.BIKE_STOP
                self.modeafterhonk = Mode.NAV

        elif self.mode == Mode.PLAN_RESCUE:
            self.stay_idle()

            if not self.init_flag:
                self.init_plan_rescue()
                self.init_flag = 1

            if self.tsales_circuit_received:
                self.mode = Mode.REQUEST_RESCUE

        elif self.mode == Mode.REQUEST_RESCUE:
            # publish message that rescue is ready
            rescue_ready_msg = True
            self.rescue_ready_publisher.publish(rescue_ready_msg)

            if (self.play_rescue_sound):
                "plY SONG"
                self.soundhandle.playWave(
                    '/home/aa274/catkin_ws/src/asl_turtlebot/finalcount.wav',
                    1.0)
                self.play_rescue_sound = False

            # when rescue on message is received, tranisition to rescue
            if self.rescue_on:
                if self.animal_waypoints.length() > 0:
                    self.pop_animal()
                    self.mode = Mode.GO_TO_ANIMAL
                else:
                    self.mode = Mode.IDLE

        elif self.mode == Mode.GO_TO_ANIMAL:
            # navigate to the animal
            if self.close_to(self.x_g, self.y_g, self.theta_g):
                self.mode = Mode.RESCUE_ANIMAL
            else:
                if self.stop_check():  # Returns True if within STOP_MIN_DIST
                    self.mode = Mode.STOP
                    self.modeafterstop = Mode.GO_TO_ANIMAL
                else:
                    self.nav_to_pose()

            if self.honk:
                self.mode = Mode.BIKE_STOP
                self.modeafterhonk = Mode.GO_TO_ANIMAL

        elif self.mode == Mode.RESCUE_ANIMAL:
            if not self.init_flag:
                self.init_flag = 1
                self.init_rescue_animal()

            if self.has_rescued():
                rospy.loginfo("Rescued a: %s", self.target_animal)
                if self.animal_waypoints.length() > 0:
                    self.pop_animal()
                    self.mode = Mode.GO_TO_ANIMAL
                else:
                    self.mode = Mode.VICTORY

        elif self.mode == Mode.EXPLORE:
            if self.explore_started == False:
                self.init_explore()

            if self.explore_waypoints.length() > 0:
                self.pop_explore_waypoint()
                self.mode = Mode.GO_TO_EXPLORE_WAYPOINT

            else:
                self.mode = Mode.PLAN_RESCUE

        elif self.mode == Mode.GO_TO_EXPLORE_WAYPOINT:
            # check if rotating to animal or normal exploration
            if not rospy.get_rostime().to_sec(
            ) > self.time_of_spin + MAX_PINPOINT_TIME:
                if self.nav_to_animal_CW:
                    self.turn_CW()
                elif self.nav_to_animal_CCW:
                    self.turn_CCW()
            else:
                # navigate to the exploration waypoint
                if self.close_to(self.x_g, self.y_g, self.theta_g):
                    # if self.nav_to_animal:
                    #     self.mode = Mode.GO_TO_EXPLORE_WAYPOINT
                    self.mode = Mode.EXPLORE
                else:
                    if self.stop_check(
                    ):  # Returns True if within STOP_MIN_DIST
                        self.mode = Mode.STOP
                        self.modeafterstop = Mode.GO_TO_EXPLORE_WAYPOINT
                    else:
                        # print self.x_g, self.y_g, self.theta_g
                        self.nav_to_pose()

            if self.honk:
                self.mode = Mode.BIKE_STOP
                self.modeafterhonk = Mode.GO_TO_EXPLORE_WAYPOINT

        elif self.mode == Mode.VICTORY:
            # self.stay_idle()

            if (self.victory_sound):
                self.soundhandle.playWave(
                    '/home/aa274/catkin_ws/src/asl_turtlebot/victory.wav', 1.0)
                self.victory_sound = False

            twist = Twist()
            twist.linear.x = 0
            twist.linear.y = 0
            twist.linear.z = 0
            twist.angular.x = 0
            twist.angular.y = 0
            twist.angular.z = 10.0
            self.cmd_vel_publisher.publish(twist)

        else:
            raise Exception('This mode is not supported: %s' % str(self.mode))

    def run(self):
        rate = rospy.Rate(10)  # 10 Hz
        while not rospy.is_shutdown():
            self.loop()
            rate.sleep()
Beispiel #36
0
class spr:
	def __init__(self):

		rospy.on_shutdown(self.cleanup)
		self.voice = rospy.get_param("~voice", "voice_cmu_us_rms_cg_clunits")
		self.question_start_signal = rospy.get_param("~question_start_signal", "")



		self.if_say=0
		#for crowd question
		self.appl=['children','adults','elders']
		self.gppl=['females','males','women','men','boys','girls']
		self.people=self.appl+self.gppl
		self.posprs=['standing','sitting','lying']
		self.posppl=['standing','sitting','lying','standing or sitting','standing or lying','sitting or lying']
		self.gesture=['waving','rising left arm','rising right arm','pointing left','pointing right']
		self.gprsng=['male or female','man or woman','boy or girl']
		self.gprsn=['female','male','woman','man','boy','girl']
		self.w=0



		#for object question
		#read object.xml
		self.adja=['heaviest','smallest','biggest','lightest']
		self.adjr=['heavier','smaller','bigger','lighter']
		self.size_order = (
			'mixed-nuts', 'food', 'fork', 'cutlery', 'spoon', 'cutlery',
			'knife', 'cutlery','canned-fish', 'food', 'cup', 'container', 
			'orange-juice', 'drink', 'pringles', 'snack', 'cereal', 'food', 
			'apple-juice', 'drink','milk-tea', 'drink','jelly', 'snack', 
			'milk-biscuit', 'snack', 'root-beer', 'drink', 'potato-chip', 'snack',
			'instant-noodle', 'food', 'green-tea', 'drink','disk','container',
			'cereal-bowl','container','tray','container','shopping-bag','container')
		self.weight_order1= (
            'cup','container',               'cereal-bowl','container',
            'disk','container',           'tray','container',
	    'mixed nuts','food',
	    'potato-chip', 'snack',    'shopping-bag','container',
            'cereal','food',          'instant-noodle','food',
            'milk-biscuit', 'snack',          'pringles','snack',
            'fork', 'cutlery',          'spoon', 'cutlery',
            'knife','cutlery',         'canned-fish','food',
            'apple-juice','drink',   'orange-juice', 'drink',
            'milk-tea', 'drink',          'root-bear','drink',
            'jelly', 'snack',    'green-tea', 'drink')		


		self.weight_order= (
            'cup','the top of the shelf',               'cereal-bowl','the top of the shelf',
            'disk','the top of the shelf',           'tray','the top of the shelf',
	    'mixed nuts','kitchen-table',
	    'potato-chip', 'coffee-table',    'shopping-bag','the top of the shelf',
            'cereal','kitchen-table',          'instant-noodle','kitchen-table',
            'milk-biscuit', 'coffee-table',          'pringles','coffee-table',
            'fork', 'the top of the shelf',          'spoon', 'the top of the shelf',
            'knife','the top of the shelf',         'canned-fish','kitchen-table',
            'apple-juice','bar-table',   'orange-juice', 'bar-table',
            'milk-tea', 'bar-table',          'root-bear','bar-table',
            'jelly', 'coffee-table',    'green-tea', 'bar-table','cutlery','the top of the shelf', 'container','the top of the shelf','food','kitchen-table','snack','bar-table','drink','bar-table')
		self.category = ('container', '5', 'cutlery', '3', 'drink', '5', 'food', '4', 'snack', '4')
		

		self.object_colour = ( 'cup','green red and orange',               'cereal-bowl','red',
		'mixed-nuts','white',
            'disk','blue',         'tray','purple',
	    'potato-chip', 'yellow',    'shopping-bag','red and white',
            'cereal','red and blue',          'instant-noodle','yellow',
            'milk-biscuit', 'blue and red',          'pringles','green and red',
            'fork', 'silver',          'spoon', 'silver',
            'knife','silver',         'canned-fish','red and white',
            'apple-juice','red',   'orange-juice', 'white and greed',
            'milk-tea', 'blue and black',          'root-bear','brown',
            'jelly', 'red and pink',    'green-tea', 'greed')
		









		self.location=('small shelf','living-room','sofa','living-room','coffee-table','living-room',
					   'arm-chair-a','living-room','arm-chair-b','living-room','kitchen-rack','kitchen','kitchen-table','kitchen',
					   'kitchen shelf','kitchen','kitchen-counter','kitchen','fridge','kitchen',
					   'chair','dining-room','dining-table-a','dining-room','little table','dining-room',
					   'right planks','balcony','balcony-shelf','balcony','entrance-shelf','entrance',
					   'bar-table','dining-room','dining-table-b','dining-room','shelf','dining-room')
		self.doornum=('living-room','2','kitchen','1','dining-room','1','hallway','1')
		self.thingnum=('2','arm-chair','living-room','6','chair','dining-room','2','dining-table','dining-room',
				'1','kitchen tack','kitchen','1','kitchen-table','kitchen',
				'1','small shelf','living-room','1','sofa','living-room','1','coffee-table','living-room',
				'1','little table','dining-room','1','bar-table','dining-room','1','shelf','dining-room')


		# Create the sound client object
		self.soundhandle = SoundClient() 
		rospy.sleep(1)
		self.riddle_turn = rospy.Publisher('turn_signal', String, queue_size=15)
		self.soundhandle.stopAll()
		self.soundhandle.say('hello I want to play riddles',self.voice)
		rospy.sleep(3)
		self.soundhandle.say('I will turn back after ten seconds',self.voice)
		rospy.sleep(3)
		self.soundhandle.say('ten',self.voice)
		rospy.sleep(1)
		self.soundhandle.say('nine',self.voice)
		self.riddle_turn.publish("turn_robot")#publish msg to nav
		rospy.sleep(1)
		self.soundhandle.say('eight',self.voice)
		rospy.sleep(1)
		self.soundhandle.say('seven',self.voice)
		rospy.sleep(1)
		self.soundhandle.say('six',self.voice)
		rospy.sleep(1)
		self.soundhandle.say('five',self.voice)
		rospy.sleep(1)
		self.soundhandle.say('four',self.voice)
		rospy.sleep(1)
		self.soundhandle.say('three',self.voice)
		rospy.sleep(1)
		self.soundhandle.say('two',self.voice)
		rospy.sleep(1)
		self.soundhandle.say('one',self.voice)
		rospy.sleep(1)
		self.soundhandle.say('here I come',self.voice)
		rospy.sleep(1)
		rospy.Subscriber('human_num', String, self.h_num)
		rospy.Subscriber('female_num', String, self.f_num)
		rospy.Subscriber('male_num', String, self.m_num)
		rospy.Subscriber('taking_photo_signal', String, self.remind_people)
		if self.if_say==0:
			rospy.Subscriber('recognizer_output', String, self.talk_back)

	def h_num(self,msg):
		msg.data=msg.data.lower()
		self.soundhandle.say('I have already taken the photo',self.voice)
		rospy.sleep(3)
		self.soundhandle.say('please wait for a moment',self.voice)
		rospy.sleep(3)
		self.crowd_num=msg.data
		print "human number is " + msg.data
		self.soundhandle.say('human number is  '+msg.data,self.voice)
		rospy.sleep(4)

	def f_num(self,msg):
		msg.data=msg.data.lower()
		print "female number is " + msg.data
		self.female_num=msg.data
		self.soundhandle.say('female number is  '+msg.data,self.voice)
		rospy.sleep(4)

	def m_num(self,msg):
		msg.data=msg.data.lower()
		print "male number is " + msg.data
		self.male_num=msg.data
		self.soundhandle.say('male number is ' +msg.data,self.voice)
		rospy.sleep(4)
		self.soundhandle.say('who wants to play riddles with me',self.voice)
		rospy.sleep(3.5)
		self.soundhandle.say('please stand in front of me and wait for five seconds',self.voice)
		rospy.sleep(8.5)
		self.soundhandle.say('please ask me after you hear',self.voice)
		rospy.sleep(2.5)
		self.soundhandle.playWave(self.question_start_signal+"/question_start_signal.wav")
		rospy.sleep(1.3)
		self.soundhandle.say('Im ready',self.voice)
		rospy.sleep(1.3)
		self.soundhandle.playWave(self.question_start_signal+"/question_start_signal.wav")
		rospy.sleep(1.3)
		self.w=1

	def answer_How_many_people_are_in_the_crowd(self,msg):
		msg.data=msg.data.lower()
		self.soundhandle.say('the answer is there are '+msg.data+' in the crowd',self.voice)
		rospy.sleep(3.5)
		self.soundhandle.say('OK I am ready for next question', self.voice)
		rospy.sleep(2)
		self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
		rospy.sleep(1.2)

	def remind_people(self, msg):
		msg.data = msg.data.lower()
		if msg.data=='start':
			self.soundhandle.say('Im going to take a photo',self.voice)
			rospy.sleep(3)
			self.soundhandle.say('please look at me and smile',self.voice)
			rospy.sleep(3)
			self.soundhandle.say('three',self.voice)
			rospy.sleep(1)
			self.soundhandle.say('two',self.voice)
			rospy.sleep(1)
			self.soundhandle.say('one',self.voice)
			rospy.sleep(1)

	def talk_back(self, msg):
		msg.data = msg.data.lower()
		print msg.data
		if self.w==1 :
			self.sentence_as_array=msg.data.split('-')
			self.sentence=msg.data.replace('-',' ')
			print self.sentence
			#object
			if msg.data.find('which-city-are-we-in')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared which city are we in ', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is Nagoya', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('Nagoya')
			elif msg.data.find('what-is-the-name-of-your-team')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared what is the name of your team', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is our team name is kamerider ', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('our team name is kamerider')
			elif msg.data.find('how-many-teams-participate-in-robocup-at-home-this-year')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared how many teams participate in robocup at home this year', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is thirty one', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('31')
			elif msg.data.find('who-won-the-popular-vote-in-the-us-election')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared who won the popular vote in the us election', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is Hillary Clinton ', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('Hillary Clinton')
			elif msg.data.find('what-is-the-highest-mountain-in-japan')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared what is the highest mountain in japan', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is Mount Fuji', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('Mount Fuji')
			elif msg.data.find('platforms')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared name the two robocup at home standard platforms', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer Pepper and HSR', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('Pepper and HSR')
			elif msg.data.find('what-does-dspl-stand-for')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared what does dspl stand for', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is Domestic Standard Platform League', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('Domestic Standard Platform League')
			elif msg.data.find('what-does-sspl-stand-for')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared what does sspl stand for', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is Social Standard Platform League', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('Social Standard Platform League')
			elif msg.data.find('who-did-alphabet-sell-boston-dynamics-to')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared who did alphabet sell boston dynamics to', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is SoftBank', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('SoftBank')
			elif msg.data.find('nagoya-has-one-of-the-largest-train-stations-in-the-world-how-large-is-it')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared nagoya has one of the largest train stations in the world how large is it', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is over 410000 square metres ', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('over 410000 square metres')
			elif msg.data.find('whats-your-teams-home-city')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared whats your teams home city', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is tianjin', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('tianjin')
			elif msg.data.find('who-created-star-wars')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared who created star wars', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is George Lucas ', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('George Lucas')
			elif msg.data.find('who-lives-in-a-pineapple-under-the-sea')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared who lives in a pineapple under the sea', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is Sponge Bob Squarepants ', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('Sponge Bob Squarepants')
			elif msg.data.find('what-did-grace-hopper-invent')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared what did grace hopper invent', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is the inventor of the first compiler ', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(4)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
				rospy.sleep(4)
				print('the inventor of the first compiler')
			elif msg.data.find('which-country-is-the-host-of-robocup-ap')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared which-country-is-the-host-of-robocup-ap', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is thailand', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")

			elif msg.data.find('what-is-the-name-of-your-team')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared what is the name of your team', self.voice)
				rospy.sleep(4)
				 
				self.soundhandle.say('the answer is our team name is kamerider ', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('wonder')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				 
				self.soundhandle.say('I heared who-is-the-lead-actress-of-wonder-women', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is gal gadot', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('which-operating-system-are-you-using')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				 	
				self.soundhandle.say('I heared which-operating-system-are-you-using', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is linux', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('who-is-the-richest-man-in-the-world')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared who-is-the-richest-man-in-the-world', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is jeff bezos', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('name-one-of-the-famous-thai-food')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared name-one-of-the-famous-thai-food', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is tom yum goong', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('where-are-you-from')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared where-are-you-from', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('I come from China', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('current')>-1 or msg.data.find('president')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared who-is-current-United-state-president', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is donald trump', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('stations')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared how-many-stations-are-there-in-BTS-skytrains', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is thrity-five', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('next-world')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared where-will-next-world-robocup-be-held', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is Montresl canada ', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('singer')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared Who-is-the-singer-of-the-song-grenade', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is Bruno mars', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('which-robot-platfrorm-is-used-for-educaational=league')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared which-robot-platfrorm-is-used-for-educaational=league', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is turtle bot', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('tell-me-the-name-of-this-venue')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared tell-me-the-name-of-this-venue', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is bangkok international trade and exhibition center ', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('iphone')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared how-much-doex-iphone-x-cost-in usa', self.voice)
				rospy.sleep(5)
				self.soundhandle.say('the answer is 999 us dollars ', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('what-is-the-batman-super-power')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared what-is-the-batman-super-power', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is rich ', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('how-many-team-in-at-home-league')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared how-many-team-in-at-home-league', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is 7 teams ', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('what-is-the-biggest-airport-in-thailand')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared what-is-the-biggest-airport-in-thailand', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is suvarnabhumi airport', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('what-is-the-tallest-building-in-the-world')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared what-is-the-tallest-building-in-the-world', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is burj khalifa', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('what-is-a-name-of-our-galaxy')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared what-is-the-name-of-our-galaxy', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is milky way', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('what-is-the-symbolic-animal-of-thailand')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared what-is-the-symbolic-animal-of-thailand', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is elephant', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			elif msg.data.find('how-many-time-robocup-held-in-thailand')>-1:
				os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
				self.soundhandle.say('I heared how-many-time-robocup-held-in-thailand', self.voice)
				rospy.sleep(4)
				self.soundhandle.say('the answer is one time', self.voice)
				rospy.sleep(3)
				self.soundhandle.say('OK I am ready for next question', self.voice)
				rospy.sleep(2.5)
				os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
				self.soundhandle.playWave(self.question_start_signal + "/question_start_signal.wav")
			else:
				print 2	

		
		
	def cleanup(self):
		rospy.loginfo("Shutting down spr node...")
Beispiel #37
0
class Battery:

    def __init__(self):
        # open serial port
        self.device = rospy.get_param('~device', '/dev/ttyUSB3')
        self.baud = rospy.get_param('~baud', 9600)
        self.ser = serial.Serial(self.device, self.baud, timeout=0.3)
        
        self.diag_pub = rospy.Publisher('/diagnostics', diagnostic_msgs.msg.DiagnosticArray)
        
        self.adc_factor = 9.34 / 307
        self.last_voltage = 0.0
        
        self.last_beep = rospy.Time.now()
        self.lvl_low = 21
        self.lvl_crit = 19.5
        
        self.play_music = rospy.get_param('~play_music', False)
        
        if (self.play_music):
            self.soundhandle = SoundClient()
            self.snd_low = rospy.get_param('~snd_low', '')
            self.snd_crit = rospy.get_param('~snd_critical', '')
            self.snd_plugin = rospy.get_param('~snd_plugin', '')
            self.snd_plugout = rospy.get_param('~snd_plugout', '')

    def spin(self):

        self.ser.flushInput()

        while not rospy.is_shutdown():

            # get data
            s = self.ser.read(2)
            
            #Main header
            diag = diagnostic_msgs.msg.DiagnosticArray()
            diag.header.stamp = rospy.Time.now()
    
            
            #battery info                                                                                                                              
            stat = diagnostic_msgs.msg.DiagnosticStatus()
            stat.name = "Main Battery"
            stat.level = diagnostic_msgs.msg.DiagnosticStatus.OK
            stat.message = "OK"

            # check, if it was correct line
            if (len(s) < 2):
                continue
            
            hi = ord(s[0])
            lo = ord(s[1])
            voltage = (hi*256 + lo) * self.adc_factor
            
            if (voltage < self.lvl_crit) and (rospy.Time.now() - self.last_beep > rospy.Duration(30)):
                rospy.logwarn("Critical power level.")
                self.last_beep = rospy.Time.now()
                if (self.play_music):
                    self.soundhandle.playWave(self.snd_crit)
            else:
                if (voltage < self.lvl_low) and (rospy.Time.now() - self.last_beep > rospy.Duration(120)):
                    rospy.logwarn("Low power level.")
                    self.last_beep = rospy.Time.now()
                    if (self.play_music):
                        self.soundhandle.playWave(self.snd_low)
                        
            # Just plugged in
            if (self.last_voltage < 26) and (voltage > 28):
                rospy.loginfo("Power charger plugged in.")
                if (self.play_music):
                    self.soundhandle.playWave(self.snd_plugin)
            
            # Just plugged out
            if (self.last_voltage > 28) and (voltage < 26):
                rospy.loginfo("Power charger plugged out.")
                if (self.play_music):
                    self.soundhandle.playWave(self.snd_plugout)
            
            self.last_voltage = voltage
            stat.values.append(diagnostic_msgs.msg.KeyValue("Voltage", str(voltage)))

            #append
            diag.status.append(stat)
            
            #publish
            self.diag_pub.publish(diag)
Beispiel #38
0
class TalkBack:
    def __init__(self):
        rospy.on_shutdown(self.cleanup)
          
        self.voice = rospy.get_param("~voice", "voice_kal_diphone")
        self.wavepath = rospy.get_param("~wavepath", "")
        
        # Create the sound client object
        self.soundhandle = SoundClient()
        
        rospy.sleep(1)
        self.soundhandle.stopAll()
        
        # Announce that we are ready for input
        self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
        rospy.sleep(1)
        self.soundhandle.say("How can I help U Sir", self.voice)
        
        rospy.loginfo("Say one of the navigation commands...")
	
        # Subscribe to the recognizer output
        rospy.Subscriber('/recognizer/output', String, self.talkback)

    
	
    def talkback(self, msg):
        # Print the recognized words on the screen
        rospy.loginfo(msg.data)
	twist =Twist()
	
        if msg.data ==  "move left":
         self.soundhandle.say("turning left", self.voice)
	 twist.linear.x = 0; twist.linear.y = 0; twist.linear.z = 0
         twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = 1	
	 pub.publish(twist)
	
        if msg.data == "move right" :
         self.soundhandle.say("turning right", self.voice)
	 twist.linear.x = 0; twist.linear.y = 0; twist.linear.z = 0
         twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = -1	
	 pub.publish(twist)

	if msg.data == "stop" :
         self.soundhandle.say("brakes applied", self.voice)
	 twist.linear.x = 0; twist.linear.y = 0; twist.linear.z = 0
         twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = 0	
	 pub.publish(twist)

	if msg.data == "move back":
         self.soundhandle.say("going back", self.voice)
	 twist.linear.x = -1; twist.linear.y = 0; twist.linear.z = 0
         twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = 0
	 pub.publish(twist)

	if msg.data == "move straight" :
         self.soundhandle.say("going straight", self.voice)
	 twist.linear.x = 1; twist.linear.y = 0; twist.linear.z = 0
         twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = 0	
	 pub.publish(twist)

        if msg.data == "lights on" :
         self.soundhandle.say("lights are on", self.voice)
	 pin =13
         value = True
	 arduino_digi_write(pin,value)

	if msg.data == "lights off" :
         self.soundhandle.say("lights are off", self.voice)
	 pin =13
         value = False
	 arduino_digi_write(pin,value)
         	
        elif msg.data == "bring me the glass" :
         self.soundhandle.say("ther are no glasses here", self.voice)
       
       
        
        # Uncomment to play one of the built-in sounds
        #rospy.sleep(2)
        #self.soundhandle.play(5)
        
        # Uncomment to play a wave file
        #rospy.sleep(2)
        #self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
    def cleanup(self):
        rospy.loginfo("Shutting down talkback node...")
Beispiel #39
0
class spr:
    def __init__(self):

        rospy.on_shutdown(self.cleanup)
        self.voice = rospy.get_param("~voice", "voice_cmu_us_rms_cg_clunits")
        self.question_start_signal = rospy.get_param("~question_start_signal",
                                                     "")

        self.if_say = 0
        #for crowd question
        self.appl = ['children', 'adults', 'elders']
        self.gppl = ['females', 'males', 'women', 'men', 'boys', 'girls']
        self.people = self.appl + self.gppl
        self.posprs = ['standing', 'sitting', 'lying']
        self.posppl = [
            'standing', 'sitting', 'lying', 'standing or sitting',
            'standing or lying', 'sitting or lying'
        ]
        self.gesture = [
            'waving', 'rising left arm', 'rising right arm', 'pointing left',
            'pointing right'
        ]
        self.gprsng = ['male or female', 'man or woman', 'boy or girl']
        self.gprsn = ['female', 'male', 'woman', 'man', 'boy', 'girl']
        self.w = 0

        self.female_num = 0
        self.male_num = 0
        self.crowd_num = 0
        self.sit_num = 0
        self.stand_num = 0
        self.sit_man_num = 0
        self.sit_female_num = 0
        self.stand_man_num = 0
        self.stand_female_num = 0

        #for object question
        #read object.xml
        self.adja = ['heaviest', 'smallest', 'biggest', 'lightest']
        self.adjr = ['heavier', 'smaller', 'bigger', 'lighter']
        self.size_order = ('mixed-nuts', 'food', 'fork', 'cutlery', 'spoon',
                           'cutlery', 'knife', 'cutlery', 'canned-fish',
                           'food', 'cup', 'container', 'orange-juice', 'drink',
                           'pringles', 'snack', 'cereal', 'food',
                           'apple-juice', 'drink', 'milk-tea', 'drink',
                           'jelly', 'snack', 'milk-biscuit', 'snack',
                           'root-beer', 'drink', 'potato-chip', 'snack',
                           'instant-noodle', 'food', 'green-tea', 'drink',
                           'disk', 'container', 'cereal-bowl', 'container',
                           'tray', 'container', 'shopping-bag', 'container')
        self.weight_order1 = ('cup', 'container', 'cereal-bowl', 'container',
                              'disk', 'container', 'tray', 'container',
                              'mixed nuts', 'food', 'potato-chip', 'snack',
                              'shopping-bag', 'container', 'cereal', 'food',
                              'instant-noodle', 'food', 'milk-biscuit',
                              'snack', 'pringles', 'snack', 'fork', 'cutlery',
                              'spoon', 'cutlery', 'knife', 'cutlery',
                              'canned-fish', 'food', 'apple-juice', 'drink',
                              'orange-juice', 'drink', 'milk-tea', 'drink',
                              'root-bear', 'drink', 'jelly', 'snack',
                              'green-tea', 'drink')

        self.weight_order = (
            'cup', 'the top of the shelf', 'cereal-bowl',
            'the top of the shelf', 'disk', 'the top of the shelf', 'tray',
            'the top of the shelf', 'mixed nuts', 'kitchen-table',
            'potato-chip', 'coffee-table', 'shopping-bag',
            'the top of the shelf', 'cereal', 'kitchen-table',
            'instant-noodle', 'kitchen-table', 'milk-biscuit', 'coffee-table',
            'pringles', 'coffee-table', 'fork', 'the top of the shelf',
            'spoon', 'the top of the shelf', 'knife', 'the top of the shelf',
            'canned-fish', 'kitchen-table', 'apple-juice', 'bar-table',
            'orange-juice', 'bar-table', 'milk-tea', 'bar-table', 'root-bear',
            'bar-table', 'jelly', 'coffee-table', 'green-tea', 'bar-table',
            'cutlery', 'the top of the shelf', 'container',
            'the top of the shelf', 'food', 'kitchen-table', 'snack',
            'bar-table', 'drink', 'bar-table')
        self.category = ('container', '5', 'cutlery', '3', 'drink', '5',
                         'food', '4', 'snack', '4')

        self.object_colour = ('cup', 'green red and orange', 'cereal-bowl',
                              'red', 'mixed-nuts', 'white', 'disk', 'blue',
                              'tray', 'purple', 'potato-chip', 'yellow',
                              'shopping-bag', 'red and white', 'cereal',
                              'red and blue', 'instant-noodle', 'yellow',
                              'milk-biscuit', 'blue and red', 'pringles',
                              'green and red', 'fork', 'silver', 'spoon',
                              'silver', 'knife', 'silver', 'canned-fish',
                              'red and white', 'apple-juice', 'red',
                              'orange-juice', 'white and greed', 'milk-tea',
                              'blue and black', 'root-bear', 'brown', 'jelly',
                              'red and pink', 'green-tea', 'greed')

        self.location = ('small shelf', 'living-room', 'sofa', 'living-room',
                         'coffee-table', 'living-room', 'arm-chair-a',
                         'living-room', 'arm-chair-b', 'living-room',
                         'kitchen-rack', 'kitchen', 'kitchen-table', 'kitchen',
                         'kitchen shelf', 'kitchen', 'kitchen-counter',
                         'kitchen', 'fridge', 'kitchen', 'chair',
                         'dining-room', 'dining-table-a', 'dining-room',
                         'little table', 'dining-room', 'right planks',
                         'balcony', 'balcony-shelf', 'balcony',
                         'entrance-shelf', 'entrance', 'bar-table',
                         'dining-room', 'dining-table-b', 'dining-room',
                         'shelf', 'dining-room')
        self.doornum = ('living-room', '2', 'kitchen', '1', 'dining-room', '1',
                        'hallway', '1')
        self.thingnum = ('2', 'arm-chair', 'living-room', '6', 'chair',
                         'dining-room', '2', 'dining-table', 'dining-room',
                         '1', 'kitchen tack', 'kitchen', '1', 'kitchen-table',
                         'kitchen', '1', 'small shelf', 'living-room', '1',
                         'sofa', 'living-room', '1', 'coffee-table',
                         'living-room', '1', 'little table', 'dining-room',
                         '1', 'bar-table', 'dining-room', '1', 'shelf',
                         'dining-room')

        # Create the sound client object
        self.soundhandle = SoundClient()
        rospy.sleep(1)
        self.riddle_turn = rospy.Publisher('turn_signal',
                                           String,
                                           queue_size=15)
        self.soundhandle.stopAll()
        self.soundhandle.say('hello I want to play riddles', self.voice)
        rospy.sleep(3)
        self.soundhandle.say('I will turn back after ten seconds', self.voice)
        rospy.sleep(3)
        self.soundhandle.say('ten', self.voice)
        rospy.sleep(1)
        self.soundhandle.say('nine', self.voice)
        self.riddle_turn.publish("turn_robot")  #publish msg to nav
        rospy.sleep(1)
        self.soundhandle.say('eight', self.voice)
        rospy.sleep(1)
        self.soundhandle.say('seven', self.voice)
        rospy.sleep(1)
        self.soundhandle.say('six', self.voice)
        rospy.sleep(1)
        self.soundhandle.say('five', self.voice)
        rospy.sleep(1)
        self.soundhandle.say('four', self.voice)
        rospy.sleep(1)
        self.soundhandle.say('three', self.voice)
        rospy.sleep(1)
        self.soundhandle.say('two', self.voice)
        rospy.sleep(1)
        self.soundhandle.say('one', self.voice)
        rospy.sleep(1)
        self.soundhandle.say('here I come', self.voice)
        rospy.sleep(1)
        rospy.Subscriber('human_num', String, self.h_num)
        rospy.Subscriber('female_num', String, self.f_num)
        rospy.Subscriber('male_num', String, self.m_num)
        rospy.Subscriber('sit_num', String, self.sit_num)
        rospy.Subscriber('stand_num', String, self.stand_num)
        rospy.Subscriber('stand_male_num', String, self.sit_man_num)
        rospy.Subscriber('stand_female_num', String, self.sit_female_num)
        rospy.Subscriber('sit_male_num', String, self.stand_man_num)
        rospy.Subscriber('stand_female_num', String, self.stand_female_num)

        rospy.Subscriber('taking_photo_signal', String, self.remind_people)
        if self.if_say == 0:
            rospy.Subscriber('recognizer_output', String, self.talk_back)

    def sit_num(self, msg):
        msg.data = msg.data.lower()
        self.sit_num = msg.data

    def stand_num(self, msg):
        msg.data = msg.data.lower()
        self.stand_num = msg.data

    def sit_man_num(self, msg):
        msg.data = msg.data.lower()
        self.sit_man_num = msg.data

    def sit_female_num(self, msg):
        msg.data = msg.data.lower()
        self.sit_female_num = msg.data

    def stand_man_num(self, msg):
        msg.data = msg.data.lower()
        self.stand_man_num = msg.data

    def stand_female_num(self, msg):
        msg.data = msg.data.lower()
        self.stand_female_num = msg.data

    def h_num(self, msg):
        msg.data = msg.data.lower()
        self.soundhandle.say('I have already taken the photo', self.voice)
        rospy.sleep(3)
        self.soundhandle.say('please wait for a moment', self.voice)
        rospy.sleep(3)
        self.crowd_num = msg.data
        print "human number is " + msg.data
        self.soundhandle.say('human number is  ' + msg.data, self.voice)
        rospy.sleep(4)

    def f_num(self, msg):
        msg.data = msg.data.lower()
        womannumber = msg.data
        print "female number is " + msg.data
        self.female_num = msg.data
        self.soundhandle.say('female number is  ' + msg.data, self.voice)
        rospy.sleep(4)

    def m_num(self, msg):
        msg.data = msg.data.lower()
        print "male number is " + msg.data
        mannumber = msg.data
        self.male_num = msg.data
        self.soundhandle.say('male number is ' + msg.data, self.voice)
        rospy.sleep(4)
        self.soundhandle.say('who wants to play riddles with me', self.voice)
        rospy.sleep(3.5)
        self.soundhandle.say(
            'please stand in front of me and wait for five seconds',
            self.voice)
        rospy.sleep(8.5)
        self.soundhandle.say('please ask me after you hear', self.voice)
        rospy.sleep(2.5)
        self.soundhandle.playWave(self.question_start_signal +
                                  "/question_start_signal.wav")
        rospy.sleep(1.3)
        self.soundhandle.say('Im ready', self.voice)
        rospy.sleep(1.3)
        self.soundhandle.playWave(self.question_start_signal +
                                  "/question_start_signal.wav")
        rospy.sleep(1.3)
        self.w = 1

    def answer_How_many_people_are_in_the_crowd(self, msg):
        msg.data = msg.data.lower()
        self.soundhandle.say(
            'the answer is there are ' + msg.data + ' in the crowd',
            self.voice)
        rospy.sleep(3.5)
        self.soundhandle.say('OK I am ready for next question', self.voice)
        rospy.sleep(2)
        self.soundhandle.playWave(self.question_start_signal +
                                  "/question_start_signal.wav")
        rospy.sleep(1.2)

    def remind_people(self, msg):
        msg.data = msg.data.lower()
        self.turn_end = rospy.Publisher('turn_end', String, queue_size=15)
        if msg.data == 'start':
            self.soundhandle.say('Im going to take a photo', self.voice)
            rospy.sleep(3)
            self.soundhandle.say('please look at me and smile', self.voice)
            rospy.sleep(3)
            self.soundhandle.say('three', self.voice)
            rospy.sleep(1)
            self.soundhandle.say('two', self.voice)
            rospy.sleep(1)
            self.soundhandle.say('one', self.voice)
            rospy.sleep(1)
            self.turn_end.publish("in_position")

    def talk_back(self, msg):
        msg.data = msg.data.lower()
        print msg.data
        if self.w == 1:
            self.sentence_as_array = msg.data.split('-')
            self.sentence = msg.data.replace('-', ' ')
            print self.sentence
            #object
            if msg.data.find('where-are-we') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('where-are-we', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is Japan', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(4)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                rospy.sleep(4)
                print "where-are-we"
                print "Japan"
            elif msg.data.find('how-many-teams-are-there') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared how-many-teams-are-there',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is five', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(4)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                rospy.sleep(4)
                print "how-many-teams-are-there"
                print "5"
            elif msg.data.find('participants-come-from') > -1 or msg.data.find(
                    'how-many-countries') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say(
                    'I heared how-many-countries-the-participants-come-from',
                    self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is three', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(4)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "how-many-countries-the-participants-come-from"
                rospy.sleep(4)
                print "3"
            elif msg.data.find('what-month-is-it-now') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared what-month-is-it-now',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is May', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(4)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                rospy.sleep(4)
                print "what-month-is-it-now"
                print "May"
            elif msg.data.find('where-are-the-chairs') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared where-are-the-chairs',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is in the living room',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(4)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                rospy.sleep(4)
                f.write('where-are-the-chairs')
                f.write('living-room')
            elif msg.data.find('how-many-chairs-are-there-in-the-house') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say(
                    'I heared how-many-chairs-are-there-in-the-house',
                    self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is five', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(4)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                rospy.sleep(4)
                print "how-many-chairs-are-there-in-the-house"
                print "5"
            elif msg.data.find('how-many-woman-are-there') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared how-many-woman-are-there',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is', self.voice)
                rospy.sleep(3)
                self.soundhandle.say(str(self.female_num), self.voice)
                rospy.sleep(1)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(4)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                rospy.sleep(4)
                print "how-many-woman-are-there"
                print self.female_num
            elif msg.data.find('how-many-man-is-standing') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared how-many-man-is-standing',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say(str(self.stand_man_num), self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "how-many-man-is-standing"
                print self.self.stand_man_num
            elif msg.data.find('where-is-the-tea') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared where-is-the-tea', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is on the table', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "I heared where-is-the-tea"
                print "on the table"
            elif msg.data.find('what-is-next-to-the-tea') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared what-is-next-to-the-tea',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is milk', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-is-next-to-the-tea"
                print "milk"
            elif msg.data.find('what-is-your-team-name') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared what-is-your-team-name',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is kamirider', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-is-your-team-name"
                print "kamirider"
            elif msg.data.find('what-is-your-team-name') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared what-is-your-team-name',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is kamirider', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-is-your-team-name"
                print "kamirider"
            elif msg.data.find('what-is-the-weather-today') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared what-is-the-weather-today',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is sunny', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-is-the-weather-today"
                print "sunny"
            elif msg.data.find('what-is-the-date-today') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared what-is-the-date-today',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is 3th May', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-is-the-date-today"
                print "3th May"
            elif msg.data.find('where-is-the-robotcup-held') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared where-is-the-robotcup-held',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is Ogaki Gifu', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "where-is-the-robotcup-held"
                print "Ogaki Gifu"
            elif msg.data.find('what-color-is-the-tea') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared what-color-is-the-tea',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is green', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-color-is-the-tear"
                print "green"
            elif msg.data.find('what-is-the-game') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared what-is-the-game', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is robotcup', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-is-the-game"
                print "robotcup"
            elif msg.data.find('how-many-beds-are-there-in-the-bedroom') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared what-is-the-game', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is one', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "how-many-beds-are-there-in-the-bedroom"
                print "one"
            elif msg.data.find(
                    'what-is-the-smallest-country-in-the-world') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say(
                    'I heared what-is-the-smallest-country-in-the-world',
                    self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is Vatican', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-is-the-smallest-country-in-the-world"
                print "Vatican"
            elif msg.data.find(
                    'what-is-the-smallest-country-in-the-world') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say(
                    'I heared what-is-the-smallest-country-in-the-world',
                    self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is Vatican', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-is-the-smallest-country-in-the-world"
                print "Vatican"
            elif msg.data.find('where-is-the-next-robotcup-held') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say(
                    'I heared where-is-the-next-robotcup-held', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is Canada', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "where-is-the-next-robotcup-held"
                print "Canada"
            elif msg.data.find('is-there-a-woman') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared is-there-a-woman', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is yes', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "is-there-a-woman"
                print "yes"
            elif msg.data.find('what-color-is-the-dekopon') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared what-color-is-the-dekopon',
                                     self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is orange', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-color-is-the-dekopon"
                print "orange"
            elif msg.data.find('where-is-kiwi') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say('I heared where-is-kiwi', self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is in the kitchen',
                                     self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "where-is-kiwi"
                print "kitchen"
            elif msg.data.find('what-is-the-highest-mountain-in-japan') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say(
                    'I heared what-is-the-highest-mountain-in-japan',
                    self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is in the Mount Fuji',
                                     self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-is-the-highest-mountain-in-japan"
                print "Mount Fuji"
            elif msg.data.find('who-is-the-statue-in-the-corridor') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say(
                    'I heared what-is-the-highest-mountain-in-japan',
                    self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is no bu na ka', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "who-is-the-statue-in-the-corridor"
                print "no bu na ka"
            elif msg.data.find(
                    'what-is-the-animal-detected-in-the-biscuit-package') > -1:
                os.system("~/catkin_ws/src/speech/kill_pocketsphinx.sh")
                self.soundhandle.say(
                    'I heared what-is-the-animal-detected-in-the-biscuit-package',
                    self.voice)
                rospy.sleep(4)
                self.soundhandle.say('the answer is beare', self.voice)
                rospy.sleep(3)
                self.soundhandle.say('OK I am ready for next question',
                                     self.voice)
                rospy.sleep(2.5)
                os.system("~/catkin_ws/src/speech/run_pocketsphinx.sh")
                self.soundhandle.playWave(self.question_start_signal +
                                          "/question_start_signal.wav")
                print "what-is-the-animal-detected-in-the-biscuit-package"
                print "bear"
            else:
                print 2

    def cleanup(self):
        rospy.loginfo("Shutting down spr node...")
Beispiel #40
0
        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."

    while not rospy.is_shutdown():
        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)
        
        print 'wave (assumes you have some xemacs21 sounds present)'
        soundhandle.playWave('/usr/share/xemacs21/xemacs-packages/etc/sounds/cuckoo.wav')

        sleep(3)
        
        print 'wave2 (assumes you have some xemacs21 sounds present)'
        soundhandle.playWave('/usr/share/xemacs21/xemacs-packages/etc/sounds/say-beep.wav')

        sleep(3)
Beispiel #41
0
class get_audio():
    def __init__(self):
        """
            初始化函数,初始化录音时的各项参数,以及ros话题和参数
            构想是使用pocketsphinx进行一些短的关键词的识别,主要是唤醒词jack以及终止词ok
            然后当pocketshpinx识别到唤醒词和终止词并通过话题输出之后,此脚本接受到话题的输出之后判断开始录音还是终止录音
        """
        # Record params
        rospy.on_shutdown(self.cleanup)
        self.CHUNK = 256
        self.FORMAT = pyaudio.paInt16
        self.CHANNELS = 1
        self.RATE = 11025
        self.RECORD_SECONDS = 7
        # Ros params
        self.start_record = False
        self.stop_record = False
        self.project_name = '/home/fjj/documents/fjj_ros_code/fjj_test_code/src/homework/sounds'
        self.count = 0
        self.sub_pocketsphinx_topic_name = None
        #self.pub_record_end_topic_name   = None
        self.pub_record_index_topic_name = None
        self.wavePath = '/home/fjj/documents/fjj_ros_code/fjj_test_code/src/homework/sounds/question_start_signal.wav'

        #self.voice = None

        self.get_params()

    def setup_recorder(self):
        self.recorder = pyaudio.PyAudio()

    def get_params(self):
        self.sub_pocketsphinx_topic_name = rospy.get_param(
            "sub_pocketsphinx_topic_name", "/kws_data")
        self.pub_record_end_topic_name = rospy.get_param(
            "pub_record_end_topic_name", "/audio_record")
        self.pub_record_index_topic_name = rospy.get_param(
            "pub_record_index_topic_name", "/audio_index")
        #self.voice = rospy.get_param("~voice", "voice_kal_diphone")

        rospy.Subscriber(self.sub_pocketsphinx_topic_name, String,
                         self.pocketCallback)
        #self.pub_record = rospy.Publisher(self.pub_record_end_topic_name, String, queue_size=1)
        self.pub_index = rospy.Publisher(self.pub_record_index_topic_name,
                                         Int8,
                                         queue_size=1)

        self.soundhandle = SoundClient(blocking=True)
        rospy.sleep(1)
        self.soundhandle.stopAll()
        rospy.sleep(1)

    def pocketCallback(self, msg):
        if msg.data.lower().strip() == 'jack':
            self.start_record = True
            self.stop_record = False
            self.get_audio()

        if msg.data.lower().strip() == 'ok' or msg.data.lower().strip(
        ) == 'okay':
            self.stop_record = True

    def get_audio(self):
        if self.start_record:
            self.setup_recorder()
            self.soundhandle.stopAll()
            print("PLAY SOUND")
            self.soundhandle.playWave(self.wavePath)
            print("[INFO] SUCCESSFULLY PLAY THE SOUND")
            file_name = self.project_name + '/audio_' + str(
                self.count) + '.wav'
            print("[INFO] Start to record input audio and save to file: %s" %
                  (file_name))
            stream = self.recorder.open(format=self.FORMAT,
                                        channels=self.CHANNELS,
                                        rate=self.RATE,
                                        input=True,
                                        frames_per_buffer=self.CHUNK)
            frames = []
            for i in range(int(self.RATE / self.CHUNK * self.RECORD_SECONDS)):
                if self.stop_record:
                    print("[INFO] Stop recording")
                    break
                data = stream.read(self.CHUNK)
                frames.append(data)
            print("[INFO] Recording finised now save %d.wav file" %
                  (self.count))

            stream.stop_stream()
            stream.close()
            self.recorder.terminate()

            wf = wave.open(file_name, 'wb')
            wf.setnchannels(self.CHANNELS)
            wf.setsampwidth(self.recorder.get_sample_size(self.FORMAT))
            wf.setframerate(self.RATE)
            wf.writeframes(b''.join(frames))
            wf.close()

            self.pub_index.publish(self.count)
            self.start_record = False
            self.count += 1

    def cleanup(self):
        self.soundhandle.stopAll()
Beispiel #42
0
class TalkBack:
    def __init__(self, script_path):
        rospy.init_node('speech_cordinator')

        rospy.on_shutdown(self.cleanup)

        # Set the default TTS voice to use
        self.voice = rospy.get_param("~voice", "voice_en1_mbrola")
        self.robot = rospy.get_param("~robot", "robbie")

        # Set the wave file path if used
        self.wavepath = rospy.get_param("~wavepath",
                                        script_path + "/../sounds")

        #define afternoon and morning
        self.noon = strftime("%p:", localtime())
        if self.noon == "AM:":
            self.noon1 = "Goood Morning  "
        else:
            self.noon1 = "Good After Noon   "
        self.local = strftime("%H:%M:", localtime())
        #local time
        self.local = strftime("%H:%M:", localtime())

        # Create the sound client object
        self.soundhandle = SoundClient()

        # Wait a moment to let the client connect to the
        # sound_play server
        rospy.sleep(1)

        # Make sure any lingering sound_play processes are stopped.
        self.soundhandle.stopAll()

        # Announce that we are ready for input
        self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
        rospy.sleep(1)
        #self.soundhandle.say(self.noon1 + self.robot +"   is on line" + " the time is   " + self.local, self.voice)
        #rospy.sleep(2)

        #rospy.loginfo("Say one of the navigation commands...")

        # Subscribe to the recognizer output and set the callback function
        rospy.Subscriber('/voice', SpeechRecognitionCandidates, self.talkback)
        rospy.Subscriber('/Tablet/voice', VoiceMessage, self.talkback2)
        rospy.Subscriber('/type_text', String, self.talkback3)
        self.pub = rospy.Publisher('/speech_parse', String, queue_size=1)
        self.pub_chat = rospy.Publisher('/speech_text', String, queue_size=1)

    def talkback2(self, msg):
        # Print the recognized words on the screen
        rospy.logwarn(msg.texts[0])
        self.hold = msg.texts[0]
        matchObj = re.match(r'^robbie', self.hold, re.M | re.I)
        if matchObj:
            self.task1 = re.sub('robbie ', '', self.hold, 1)  #for commands
            #self.hold1 = Dictum(self.task1)
            self.pub.publish(self.task1)
            #self.soundhandle.say(self.hold1, self.voice)
            # send sentence to NLTK /nltk_parse
        else:
            #self.soundhandle.say("alt input",self.voice)
            #send to chat minion chat
            self.pub_chat.publish(self.hold)

    def talkback(self, msg):
        # Print the recognized words on the screen
        rospy.loginfo(msg.transcript[0])
        self.hold = msg.transcript[0]
        matchObj = re.match(r'^robbie', self.hold, re.M | re.I)
        if matchObj:
            self.task1 = re.sub('robbie ', '', self.hold, 1)  #for commands

            self.pub.publish(self.task1)
            # send sentence to NLTK /nltk_parse
        else:
            #self.soundhandle.say("alt input",self.voice)
            #send to chat minion chat
            self.pub_chat.publish(self.hold)

    def talkback3(self, msg):
        # Print the recognized words on the screen
        rospy.logwarn(msg.data)
        self.hold = msg.data
        matchObj = re.match(r'^robbie', self.hold, re.M | re.I)
        if matchObj:
            self.task1 = re.sub('robbie ', '', self.hold, 1)  #for commands
            #self.hold1 = Dictum(self.task1)
            self.pub.publish(self.task1)
            #self.soundhandle.say(self.hold1, self.voice)
            # send sentence to NLTK /nltk_parse
        else:
            #self.soundhandle.say("alt input",self.voice)
            #send to chat minion chat
            self.pub_chat.publish(self.hold)

    def cleanup(self):
        self.soundhandle.stopAll()
        rospy.loginfo("Shutting down talk node...")
Beispiel #43
0
    sound = SoundClient(sound_action='sound_play', blocking=True)
    sound.actionclient.wait_for_server()

    interfaces = [
        x for x in ni.interfaces() if x[0:3] in ['eth', 'enp', 'wla', 'wlp']
        and 2 in ni.ifaddresses(x).keys()
    ]

    # If preferred interface is given, it is placed at the top of the interfaces list
    if rospy.has_param("~preferred_interface"):
        preferred_interface = rospy.get_param("~preferred_interface")
        if preferred_interface in interfaces:
            interfaces.remove(preferred_interface)
        interfaces.insert(0, preferred_interface)

    if len(interfaces) > 0:
        ip = ni.ifaddresses(interfaces[0])[2][0]['addr']
    else:
        ip = None

    # play sound
    rospy.loginfo("Playing {}".format(wav_file))
    sound.playWave(wav_file, replace=False)

    # notify ip address
    ip_text = "My internet address is {}".format(ip)
    rospy.loginfo(ip_text)
    ip_text = ip_text.replace('.', ', ')
    sound.say(ip_text, replace=False)
Beispiel #44
0
    rospy.sleep(1)

    soundhandle.stopAll()

    rospy.loginfo("This script will run continuously until you hit CTRL+C, testing various sound_node sound types.")

    #print 'Try to play wave files that do not exist.'
    #soundhandle.playWave('17')
    #soundhandle.playWave('dummy')

    # print 'say'
    # soundhandle.say('Hello world!')
    # sleep(3)

    rospy.loginfo('wave')
    soundhandle.playWave('say-beep.wav')
    sleep(2)

    rospy.loginfo('quiet wave')
    soundhandle.playWave('say-beep.wav', 0.3)
    sleep(2)

    rospy.loginfo('plugging')
    soundhandle.play(SoundRequest.NEEDS_PLUGGING)
    sleep(2)

    rospy.loginfo('quiet plugging')
    soundhandle.play(SoundRequest.NEEDS_PLUGGING, 0.3)
    sleep(2)

    rospy.loginfo('unplugging')
Beispiel #45
0
class Sounds(object):
    def __init__(self):
        self.soundhandle = SoundClient()
        self.subGesture = rospy.Subscriber('/ardrone/gest', Int8, self.receive_gesture)
        self.subMarker = rospy.Subscriber('/ardrone/switch_marker', Int16, self.receive_marker)
        self.subNobodyFound = rospy.Subscriber('/ardrone/nobody_found', Empty, self.receive_nobody)
        self.subTakeOff = rospy.Subscriber('/ardrone/takeoff', Empty, self.receive_takeoff)
        self.last_marker_1 = None
        
        self.subGesture = rospy.Subscriber('/ardrone_2/gest', Int8, self.receive_gesture_2)
        self.subMarker = rospy.Subscriber('/ardrone_2/switch_marker', Int16, self.receive_marker_2)
        self.subNobodyFound = rospy.Subscriber('/ardrone_2/nobody_found', Empty, self.receive_nobody_2)
        self.subTakeOff = rospy.Subscriber('/ardrone_2/takeoff', Empty, self.receive_takeoff_2)
        self.last_marker_2 = None
        
        
    def receive_takeoff(self, msg):
        print "received takeoff"
        self.last_marker_1 = None
        self.soundhandle.playWave(END_SENTENCE)
        rospy.sleep(1)
        self.soundhandle.playWave(TAKEOFF)
        
    
    def receive_nobody(self, msg):
       self.soundhandle.playWave(ERROR)
       rospy.sleep(1.0)
       self.soundhandle.playWave(NOBODY_FOUND)
       rospy.sleep(3.0)
       if self.last_marker_1 == 7:
          self.soundhandle.playWave(FOLLOW_JACK)
       
       elif self.last_marker_1 == 16:
           self.soundhandle.playWave(FOLLOW_UNKNOWN)
      
       elif self.last_marker_1 == 0:
           self.soundhandle.playWave(FOLLOW_ALE)
       
       elif self.last_marker_1 == 1:
           self.soundhandle.playWave(FOLLOW_JEROME)
       
       elif self.last_marker_1 == 2:
           self.soundhandle.playWave(FOLLOW_GIANNI)
       
       elif self.last_marker_1 == 3:
           self.soundhandle.playWave(FOLLOW_LUCA)
       
       elif self.last_marker_1 == 4:
           self.soundhandle.playWave(FOLLOW_JAWAD)                          
    
    def receive_marker(self, msg):
        if msg.data == 7:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_JACK)
        
        elif msg.data == 16:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_UNKNOWN)
        
        elif msg.data == 0:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_ALE)
                
        elif msg.data == 1:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_JEROME)
                             
        elif msg.data == 2:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_GIANNI)
       
        elif msg.data == 3:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_LUCA)
                         
        elif msg.data == 4:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_JAWAD)                 
        self.last_marker_1 = msg.data        
    
    def receive_gesture(self, msg):
        if msg.data == 1:
            self.soundhandle.playWave(OK_WORD)
            rospy.sleep(1.0)
            self.soundhandle.playWave(COMMAND_FOR_ME)
        
        elif msg.data == 2:
            self.soundhandle.playWave(OK_WORD)
            rospy.sleep(1.0)
            self.soundhandle.playWave(FOLLOW)
        
        elif msg.data == 3:
             self.soundhandle.playWave(END_SENTENCE)
             rospy.sleep(1)
             self.soundhandle.playWave(LANDING)      
        
        elif msg.data == 4:
             self.soundhandle.playWave(END_SENTENCE)
             rospy.sleep(1)
             self.soundhandle.playWave(SEARCH_LEFT)
             
        elif msg.data == 5:
             self.soundhandle.playWave(END_SENTENCE)
             rospy.sleep(1)
             self.soundhandle.playWave(SEARCH_RIGHT)
        
        elif msg.data == 10:
             self.soundhandle.playWave(ERROR)
             rospy.sleep(1)
             self.soundhandle.playWave(SENTENCE_UNFINISHED)
    
    def receive_takeoff_2(self, msg):
        self.last_marker_2 = None
        self.soundhandle.playWave(END_SENTENCE)
        rospy.sleep(1)
        self.soundhandle.playWave(TAKEOFF_2)
        
    
    def receive_nobody_2(self, msg):
       self.soundhandle.playWave(ERROR)
       rospy.sleep(1.0)
       self.soundhandle.playWave(NOBODY_FOUND_2)
       rospy.sleep(3.0)
       if self.last_marker_1 == 7:
          self.soundhandle.playWave(FOLLOW_JACK_2)
       
       elif self.last_marker_1 == 16:
           self.soundhandle.playWave(FOLLOW_UNKNOWN_2)
      
       elif self.last_marker_1 == 0:
           self.soundhandle.playWave(FOLLOW_ALE_2)
       
       elif self.last_marker_1 == 1:
           self.soundhandle.playWave(FOLLOW_JEROME_2)
       
       elif self.last_marker_1 == 2:
           self.soundhandle.playWave(FOLLOW_GIANNI_2)
       
       elif self.last_marker_1 == 3:
           self.soundhandle.playWave(FOLLOW_LUCA_2)
       
       elif self.last_marker_1 == 4:
           self.soundhandle.playWave(FOLLOW_JAWAD_2)                          
    
    def receive_marker_2(self, msg):
        if msg.data == 7:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_JACK_2)
        
        elif msg.data == 16:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_UNKNOWN_2)
        
        elif msg.data == 0:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_ALE_2)
                
        elif msg.data == 1:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_JEROME_2)
                             
        elif msg.data == 2:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_GIANNI_2)
       
        elif msg.data == 3:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_LUCA_2)
                         
        elif msg.data == 4:
            if self.last_marker_1 is not None and msg.data == self.last_marker_1:
                self.last_marker_1 = None
            
            else:    
                self.soundhandle.playWave(OK_WORD)
                rospy.sleep(1.0)
                self.soundhandle.playWave(FOLLOW_JAWAD_2)                 
        self.last_marker_1 = msg.data        
    
    def receive_gesture_2(self, msg):
        if msg.data == 1:
            self.soundhandle.playWave(OK_WORD)
            rospy.sleep(1.0)
            self.soundhandle.playWave(COMMAND_FOR_ME_2)
        
        elif msg.data == 2:
            self.soundhandle.playWave(OK_WORD)
            rospy.sleep(1.0)
            self.soundhandle.playWave(FOLLOW_2)
        
        elif msg.data == 3:
             self.soundhandle.playWave(END_SENTENCE)
             rospy.sleep(1)
             self.soundhandle.playWave(LANDING_2)      
        
        elif msg.data == 4:
             self.soundhandle.playWave(END_SENTENCE)
             rospy.sleep(1)
             self.soundhandle.playWave(SEARCH_LEFT_2)
             
        elif msg.data == 5:
             self.soundhandle.playWave(END_SENTENCE)
             rospy.sleep(1)
             self.soundhandle.playWave(SEARCH_RIGHT_2)
        
        elif msg.data == 10:
             self.soundhandle.playWave(ERROR)
             rospy.sleep(1)
             self.soundhandle.playWave(SENTENCE_UNFINISHED_2)               
Beispiel #46
0
class SpeechState(smach.State):
    """ Speech player state

    Takes in text and/or a wave file.  Given a wave file, plays the file.
    If no wave file is provided and text-to-speech is on, fetch the audio from
    Amazon Polly and play the audio.  If no wave file is provided and text-to-
    speech is off, return "no_audio"

    **Input keys**
        * text : str
            Can be None; the text version of the robot's speech.  Used to print
            to the screen.
        * wav_file : str
            Can be None if TTS is on. The path to the audio file.

    **Outcomes**
        * done
            Finished fetching behaviors
        * no_audio
            Couldn't find the wave file, or no wave file provided and TTS
            turned off
        * preempted
            State was preempted before audio finished playing.  If preempted,
            will try to stop the audio.

    """
    def __init__(self, use_tts, synchronizer, phrases=None, voice="Kimberly"):
        """ Constructor

        Initializes the speech state with the desired parameters; either with
        or without online TTS, and with or without a pre-generated phrase
        file.

        Parameters
        -----------
        use_tts : bool
            If true, allow online TTS
        synchronizer : Synchronizer
            Synchronizer object to allow sync of speech and behaviors.  Should
            be the same object as is passed to behavior ControllerState objects
            with ``setup_sync``
        voice : str, optional
            Which Amazon Polly voice to use. Defaults to Kimberly

        phrases : str, optional
            Path to the phrase file to use. If None, require online TTS.
        """
        smach.State.__init__(self,
                             outcomes=["preempted", "no_audio", "done"],
                             input_keys=["text", "wav_file"])
        self._tts = use_tts
        if use_tts:
            self._talker = CoRDialTTS(voice)
        self._sound_client = SoundClient()
        self._sync = synchronizer

    def execute(self, userdata):
        rospy.loginfo("Saying: {}".format(userdata.text))
        if userdata.wav_file == None:
            if userdata.text != None and len(userdata.text) != 0:
                speech_duration = self._talker.say(userdata.text, wait=False)
                rospy.sleep(0.5)
                self._sync.start()
            else:
                return "no_audio"
        else:
            wav_file = userdata.wav_file
            with contextlib.closing(wave.open(wav_file, 'r')) as f:
                frames = f.getnframes()
                rate = f.getframerate()
                speech_duration = frames / float(rate)
            self._sound_client.playWave(wav_file)
            self._sync.start()

        while rospy.Time.now() - self._sync.time < rospy.Duration(
                speech_duration):
            if self.preempt_requested():
                if self._tts:
                    self._talker.shutup()
                else:
                    self._sound_client.stopAll()
                self.service_preempt()
                return "preempted"
        return "done"
Beispiel #47
0
class TalkBack:
    def __init__(self):
        rospy.on_shutdown(self.cleanup)
          
        self.voice = rospy.get_param("~voice", "voice_cmu_us_bdl_arctic_clunits")
        self.wavepath = rospy.get_param("~wavepath", "")
        
        # Create the sound client object
        self.soundhandle = SoundClient()
        
        rospy.sleep(1)
        self.soundhandle.stopAll()
        
        # Announce that we are ready for input
        self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
        rospy.sleep(1)
        self.soundhandle.say("Hello there how can I help you", self.voice)
        	
        # Subscribe to the recognizer output
        rospy.Subscriber('/recognizer/output', String, self.talkback)

    
	
    def talkback(self, msg):
        # Print the recognized words on the screen
        rospy.loginfo(msg.data)
	twist =Twist()
	
        if msg.data ==  "left":
         #self.soundhandle.say("turning left", self.voice)
	 twist.linear.x = 0; twist.linear.y = 0; twist.linear.z = 0
         twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = 1	
	 pub.publish(twist)
	
        if msg.data == "right" :
         #self.soundhandle.say("turning right", self.voice)
	 twist.linear.x = 0; twist.linear.y = 0; twist.linear.z = 0
         twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = -1	
	 pub.publish(twist)

	if msg.data == "stop" :
         #self.soundhandle.say("brakes applied", self.voice)
	 twist.linear.x = 0; twist.linear.y = 0; twist.linear.z = 0
         twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = 0	
	 pub.publish(twist)

	if msg.data == "back":
         #self.soundhandle.say("going back", self.voice)
	 twist.linear.x = -1; twist.linear.y = 0; twist.linear.z = 0
         twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = 0
	 pub.publish(twist)

	if msg.data == "forward" :
         #self.soundhandle.say("going straight", self.voice)
	 twist.linear.x = 1; twist.linear.y = 0; twist.linear.z = 0
         twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = 0	
	 pub.publish(twist)
	
         	
        if msg.data == "bring me the soda" :
         self.soundhandle.say("ther are no glasses here", self.voice)
       
        elif msg.data == "who is suhas" :
         self.soundhandle.say("which suhas ranganath or rangaswamy", self.voice)

        elif msg.data == "what time is it" :
         self.soundhandle.say("the time is " , self.voice)
	 t = TimeInWords2()
    	 self.soundhandle.say(t.caltime(), self.voice)
           
        
        # Uncomment to play one of the built-in sounds
        #rospy.sleep(2)
        #self.soundhandle.play(5)
        
        # Uncomment to play a wave file
        #rospy.sleep(2)
        #self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
    def cleanup(self):
        rospy.loginfo("Shutting down talkback node...")
class LittleBot:
    def __init__(self, script_path):
        rospy.init_node('littlebot')

        rospy.on_shutdown(self.cleanup)

        self.wavepath = rospy.get_param("~wavepath",
                                        script_path + "/../sounds")

        self.soundhandle = SoundClient(blocking=True)

        rospy.sleep(1)

        self.soundhandle.stopAll()

        self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")

        rospy.loginfo("Ready, waiting for commands...")
        self.soundhandle.say('Hello. Nice to meet you.')

        rospy.Subscriber('/lm_data', String, self.talkback)

    def talkback(self, msg):

        rospy.loginfo(msg.data)

        if msg.data.find('WHO-ARE-YOU') > -1:
            self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")

            self.soundhandle.say("I am LittleBot. I will be your friend.")

        elif msg.data.find('WHERE-ARE-YOU-FROM') > -1:
            self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")

            self.soundhandle.say(
                "I heard you ask about my hometown. I am from Tianjin.")

        elif msg.data.find('WHAT-CAN-YOU-DO') > -1:
            self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")

            self.soundhandle.say(
                "I am a baby now, so I can just do little things. But I will learn."
            )

        elif msg.data.find('DO-YOU-KNOW-ME') > -1:
            self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")

            self.soundhandle.say("Of course. I am clever than you.")

        elif msg.data.find('DO-YOU-LIKE-DOING-HOMEWORK') > -1:
            self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")

            self.soundhandle.say("Well, I do not have homework.")

        elif msg.data.find('GOODBYE') > -1:
            self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")

            self.soundhandle.say("goodbye")

    def cleanup(self):
        self.soundhandle.stopAll()
        rospy.loginfo("Shutting down littlebot node...")
Beispiel #49
0
class VoiceNav:
    def __init__(self, script_path):
        rospy.init_node('voice_nav_move')
        
        rospy.on_shutdown(self.cleanup)
        
        # Set a number of parameters affecting the robot's speed
        self.max_speed = rospy.get_param("~max_speed", 0.4)
        self.max_angular_speed = rospy.get_param("~max_angular_speed", 1.5)
        self.speed = rospy.get_param("~start_speed", 0.1)
        self.angular_speed = rospy.get_param("~start_angular_speed", 0.5)
        self.linear_increment = rospy.get_param("~linear_increment", 0.05)
        self.angular_increment = rospy.get_param("~angular_increment", 0.4)
        
        # We don't have to run the script very fast
        self.rate = rospy.get_param("~rate", 5)
        r = rospy.Rate(self.rate)

        # A flag to determine whether or not voice control is paused
        self.paused = False

        self.passive = True
        self.voice = rospy.get_param("~voice", "voice_kal_diphone")
        self.wavepath = rospy.get_param("~wavepath", script_path + "/../sounds")
        
        # Create the sound client object
        self.soundhandle = SoundClient()
        
        # Wait a moment to let the client connect to the
        # sound_play server
        rospy.sleep(1)
        
        # Make sure any lingering sound_play processes are stopped.
        self.soundhandle.stopAll()
        
        # Announce that we are ready for input
        self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
        rospy.sleep(1)
        self.soundhandle.say("Ready", self.voice)
 
        # Initialize the Twist message we will publish.
        self.cmd_vel = Twist()

        # Publish the Twist message to the cmd_vel topic
        self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist)
        
        # Subscribe to the /recognizer/output topic to receive voice commands.
        rospy.Subscriber('/recognizer/output', String, self.speech_callback)

        # Subscribe to the move_base action server
        self.move_base = actionlib.SimpleActionClient("move_base", MoveBaseAction)
        
        # A mapping from keywords or phrases to commands
        self.keywords_to_command = {'stop': ['stop', 'halt', 'abort'],
                                    'living room': ['living', 'room'],
                                    'help': ['help', 'help me'],
                                    'hall': ['hole', 'hal'],
                                    'kitchen': ['kitchen'],
                                    'thank you': ['thank you', 'thanks'],
                                    'frobo': ['frobo'],
                                    'time': ['time', 'what is the time', 'tell me the time'],
                                    'date': ['date', 'what is the date', 'tell me the date']}
        
        rospy.loginfo("Ready to receive voice commands")

        # Goal state return values
        self.goal_states = ['PENDING', 'ACTIVE', 'PREEMPTED', 
                       'SUCCEEDED', 'ABORTED', 'REJECTED',
                       'PREEMPTING', 'RECALLING', 'RECALLED',
                       'LOST']
        
        # Set up the goal locations. Poses are defined in the map frame.  
        # An easy way to find the pose coordinates is to point-and-click
        # Nav Goals in RViz when running in the simulator.
        # Pose coordinates are then displayed in the terminal
        # that was used to launch RViz.
        self.locations = dict()
        
        self.locations['hall'] = Pose(Point(-0.486, -0.689, 0.000), Quaternion(0.000, 0.000, 0.000, 1.000))
        self.locations['living room'] = Pose(Point(1.623, 7.880, 0.000), Quaternion(0.000, 0.000, 0.707, 0.707))
        self.locations['kitchen'] = Pose(Point(-1.577, 6.626, 0.000), Quaternion(0.000, 0.000, 1.000, 0.000))

    def get_command(self, data):
        # Attempt to match the recognized word or phrase to the 
        # keywords_to_command dictionary and return the appropriate
        # command
        for (command, keywords) in self.keywords_to_command.iteritems():
            for word in keywords:
                if data.find(word) > -1:
                    return command
        
    def speech_callback(self, msg):
        #dont react upon anything if speech recognition is paused
        if self.paused:
           return
	
        # Get the motion command from the recognized phrase
        command = self.get_command(msg.data)
        
        # Log the command to the screen
        rospy.loginfo("Command: " + str(command))
        

        if self.passive:       
        # state passive listening untill attention is requested
            rospy.loginfo("Passive listening: " + str(command) + " ( " + str(msg.data) + " ) ")
            if command == 'stop': 
                # Stop the robot!  Publish a Twist message consisting of all zeros.         
                self.move_base.cancel_all_goals()
                self.msg = Twist()
                self.cmd_vel_pub.publish(self.msg)
            if command == 'frobo':
                #rospy.sleep(1)
        	self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
                self.passive = False    
		rospy.loginfo("Activated active listening")
            return           
        else:
            # Active listening, fetch real command    
            rospy.loginfo("Active listening: " + str(command) + " ( " + str(msg.data) + " ) ")
            #return to passive mode
            self.passive = True
            #Speak the recognized words in the selected voice
            self.soundhandle.say(msg.data, self.voice)  
        
            # The list of if-then statements should be fairly
            # self-explanatory
            if command == 'stop': 
                # Stop the robot!  Publish a Twist message consisting of all zeros.         
                self.move_base.cancel_all_goals()
                self.msg = Twist()
                self.cmd_vel_pub.publish(self.msg)
                rospy.loginfo("Stopped")
            
            elif command == 'time':
                self.paused=True
                now = datetime.datetime.now()
                self.soundhandle.say("the time is " + str(now.hour) + " hours and " + str(now.minute) + " minutes", self.voice)
                self.paused=False

            elif command == 'date':
                self.paused=True
                now = datetime.datetime.now()
                self.soundhandle.say("the date is " + now.strftime("%B") + str(now.day), self.voice)
                self.paused=False

            elif command == 'thank you':
                self.paused=True
                self.soundhandle.say("you are welcome", self.voice)
                self.paused=False
            
            elif command in self.locations:
                self.paused=True
                rospy.loginfo("OK, going to " + command)
                self.soundhandle.say("OK, going to " + command, self.voice)
                rospy.sleep(4)
                self.paused=False

                # Set up the next goal location
                self.goal = MoveBaseGoal()

                self.goal.target_pose.pose = self.locations[command] 
                self.goal.target_pose.header.frame_id = 'map'
                self.goal.target_pose.header.stamp = rospy.Time.now()

                # Start the robot toward the next location
                self.move_base.send_goal(self.goal)
       
                # Allow 5 minutes to get there
                finished_within_time = self.move_base.wait_for_result(rospy.Duration(300)) 
         
                # Check for success or failure
                if not finished_within_time:
                    self.move_base.cancel_goal()
                    rospy.loginfo("Timed out achieving goal")

                else:
                   state = self.move_base.get_state()
                   if state == GoalStatus.SUCCEEDED:
                       rospy.loginfo("Goal succeeded!")
                   else:
                       rospy.loginfo("Goal failed with error code: " + str(self.goal_states[state]))


            elif command == 'help':
                self.paused=True
                self.soundhandle.say("Hello my name is Frobo. I support the following commands: help, stop, date, time, kitchen, hall, living room", self.voice)
                rospy.sleep(32)
                self.paused=False

 
            elif command == 'frobo':
        	self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
                self.passive = False
                    
            else:
                return


    def cleanup(self):
        # When shutting down be sure to stop the robot!
        twist = Twist()
        self.cmd_vel_pub.publish(twist)
        rospy.sleep(1)
    def __init__(self):
        # initiliaze
        rospy.init_node('ttsconvert', anonymous=False)

        #rospy.loginfo('Example: Playing sounds in *blocking* mode.')
        soundhandle = SoundClient(blocking=True)

        #rospy.loginfo('Good Morning.')
        #soundhandle.playWave('/home/turtlebot/wavFiles/start.wav')

        # What to do you ctrl + c
        rospy.on_shutdown(self.shutdown)

        # Import the graphml to be read later
        G = nx.read_graphml("2nd_demo.graphml", unicode)
        #G = nx.read_graphml("/home/raeesa/networkx/examples/2nd_demo.graphml",unicode)
        #G = nx.read_graphml("/home/raeesa/Desktop/write_graphml.graphml",unicode)
        root = 'n1'
        current = root

        # Clear words.log
        f = open("words.log", "r+")
        f.seek(0)
        f.truncate()

        # Clear clean.log
        with open("clean.log", "w"):
            pass

# Constantly read from words.log for new lines
        while True:
            line = f.readline()

            # If the user said something
            if line:
                # The lines with dialogue all begin with a numerical value
                if line[0][:1] in '0123456789':
                    # remove 9 numbers, colon, and space from the beginning, and any whitespace from the end of the line
                    speech = line[11:].rstrip()
                    print speech

                    count = 0
                    # Search through all edges connected to the current node
                    for e in G.edges(current, data=True):

                        # If what was spoken matches the 'spoken' attribute of the edge
                        if str(speech) == str(e[2].values()[0]):
                            # Switch the current node to be the node the edge goes to
                            current = e[1]

                            # find '*' symbol in output string and and replace it with what user said stored in speech

                            # Get the dialogue stored in the new node and save it in 'output'
                            output = G.node[current]['dialogue']

                            tts = gTTS(text=output, lang='en')
                            tts.save('/home/raeesa/Desktop/line.wav')

                            subprocess.Popen([
                                'gnome-terminal', '-x', 'bash', '-c',
                                'pacmd set-source-mute 2 1'
                            ])
                            #subprocess.Popen(['gnome-terminal', '-x', 'bash', '-c','amixer set Capture nocap'])
                            #rospy.loginfo('playing output')
                            soundhandle.playWave(
                                '/home/raeesa/Desktop/line.wav', blocking=True)
                            #soundhandle.say(output)
                            subprocess.Popen([
                                'gnome-terminal', '-x', 'bash', '-c',
                                'pacmd set-source-mute 2 0'
                            ])

                            # Add 'output' to the top of clean.log
                            with open("clean.log", "r+") as g:
                                # Read everything from clean.log into 'content'
                                content = g.read()
                                # Go to the top of the file
                                g.seek(0, 0)
                                # Write 'output' with 'content' appended to the end back to clean.log
                                g.write(output.rstrip('\r\n') + '\n' + content)
                                g.close()

                    # If there are no outgoing edges from the current node, go back to the root
                            if G.out_degree(current) == 0:
                                current = root
Beispiel #51
0
class TalkBack:
    def __init__(self, script_path):
        rospy.init_node('speech_cordinator')

        rospy.on_shutdown(self.cleanup)
        
        # Set the default TTS voice to use
        self.voice = rospy.get_param("~voice", "voice_en1_mbrola")
        self.robot = rospy.get_param("~robot", "robbie")
        
        # Set the wave file path if used
        self.wavepath = rospy.get_param("~wavepath", script_path + "/../sounds")

        #define afternoon and morning
        self.noon = strftime("%p:", localtime())
        if self.noon == "AM:":
            self.noon1 = "Goood Morning  "
        else:
            self.noon1 ="Good After Noon   "
        self.local = strftime("%H:%M:", localtime())
        #local time
        self.local = strftime("%H:%M:", localtime())
        
        # Create the sound client object
        self.soundhandle = SoundClient()
        
        # Wait a moment to let the client connect to the
        # sound_play server
        rospy.sleep(1)
        
        # Make sure any lingering sound_play processes are stopped.
        self.soundhandle.stopAll()
        
        # Announce that we are ready for input
        self.soundhandle.playWave(self.wavepath + "/R2D2a.wav")
        rospy.sleep(1)
        #self.soundhandle.say(self.noon1 + self.robot +"   is on line" + " the time is   " + self.local, self.voice)
        #rospy.sleep(2)

        #rospy.loginfo("Say one of the navigation commands...")

        # Subscribe to the recognizer output and set the callback function
        rospy.Subscriber('/voice', SpeechRecognitionCandidates, self.talkback)
        rospy.Subscriber('/Tablet/voice', VoiceMessage, self.talkback2)
        rospy.Subscriber('/type_text', String, self.talkback3)
        self.pub = rospy.Publisher('/speech_parse', String, queue_size=1)
        self.pub_chat = rospy.Publisher('/speech_text', String, queue_size=1)

    def talkback2(self, msg):
        # Print the recognized words on the screen
        rospy.logwarn(msg.texts[0])
        self.hold = msg.texts[0]
        matchObj = re.match( r'^robbie', self.hold, re.M|re.I)
        if matchObj:
            self.task1 = re.sub('robbie ','',self.hold,1)#for commands
            #self.hold1 = Dictum(self.task1)
            self.pub.publish(self.task1)
            #self.soundhandle.say(self.hold1, self.voice)
            # send sentence to NLTK /nltk_parse
        else:
            #self.soundhandle.say("alt input",self.voice)
            #send to chat minion chat
            self.pub_chat.publish(self.hold)
        
    def talkback(self, msg):
        # Print the recognized words on the screen
        rospy.loginfo(msg.transcript[0])
        self.hold = msg.transcript[0]
        matchObj = re.match( r'^robbie', self.hold, re.M|re.I)
        if matchObj:
            self.task1 = re.sub('robbie ','',self.hold,1)#for commands
            
            self.pub.publish(self.task1)
            # send sentence to NLTK /nltk_parse
        else:
            #self.soundhandle.say("alt input",self.voice)
            #send to chat minion chat
            self.pub_chat.publish(self.hold)

    def talkback3(self, msg):
        # Print the recognized words on the screen
        rospy.logwarn(msg.data)
        self.hold = msg.data
        matchObj = re.match( r'^robbie', self.hold, re.M|re.I)
        if matchObj:
            self.task1 = re.sub('robbie ','',self.hold,1)#for commands
            #self.hold1 = Dictum(self.task1)
            self.pub.publish(self.task1)
            #self.soundhandle.say(self.hold1, self.voice)
            # send sentence to NLTK /nltk_parse
        else:
            #self.soundhandle.say("alt input",self.voice)
            #send to chat minion chat
            self.pub_chat.publish(self.hold)
        
        

    def cleanup(self):
        self.soundhandle.stopAll()
        rospy.loginfo("Shutting down talk node...")
Beispiel #52
0
    def speak(self):
        sound_client = SoundClient()
        G = nx.read_graphml("/opt/ros/indigo/share/pocketsphinx/demo/Ourstuff/navi_move.graphml",unicode)
	print "here"
        root = 'n1'
        current = root                            
	output = G.node[current]['dialogue']
        tts = gTTS(text = output, lang = 'en')
        tts.save('/home/turtlebot/wavFiles/output.wav')
	rospy.loginfo('Turtlebot says I understood what you said...')
        sound_client.playWave('/home/turtlebot/wavFiles/output.wav', blocking=True)
	output = None

        while True:
	    #counter = counter +1        
            # THE USER SPEAKS
	    rospy.sleep(1)
            subprocess.call('./speech-rec.sh')
	
            # ANALYZE WHAT THE USER SAID
            f = open("words.log","r+")
            line = f.readline()
            #output = None
            if line:
                if line[0] in 't':
                    speech = line[12:].rstrip().lower()
		    print speech
	            if speech == "die":
			break
		    see = -1
                    for e in G.edges(current, data=True):
                        expected = str(e[2].values()[0])
                        match = re.search(expected, speech)
                        if match or expected == 'room':
			    see = 1
                            current = e[1]
                            output = G.node[current]['dialogue']
                            if (expected=='left'):      
				self.goToDirection('left')                  
                            elif (expected=='right'):
				self.goToDirection('right')                                          
                            elif (expected=='back'):     
				self.goToDirection('back')                                     
                            elif (expected=='forward'):    
				self.goToDirection('forward')                                      
			    elif (expected == 'follow me'):
				self.follower()
			    elif (expected == 'square'):
				self.drawSquare()
			    elif (expected == 'dance'):
				self.dance()			    
		    print "out of the loop"
	            if see < 0:
	                #tts = gTTS(text = 'Sorry, I did not understand that.', lang = 'en')
		        #tts.save('/home/turtlebot/wavFiles/pardon.wav')
		        rospy.loginfo('Turtlebot says I do not understand...')
		        sound_client.playWave('/home/turtlebot/wavFiles/pardon.wav', blocking=True)
		
	    if output:
            	tts = gTTS(text = output, lang = 'en')
            	tts.save('/home/turtlebot/wavFiles/output.wav')
            	rospy.loginfo('Turtlebot says I understood what you said...')
            	sound_client.playWave('/home/turtlebot/wavFiles/output.wav', blocking=True)
            
            # CHECK IF YOU HAVE TO GO OUT OF LOOP
            if (output == "Bye"):
		sound_client.playWave('/home/turtlebot/wavFiles/AllByMyself.wav', blocking=True)
                #tts = gTTS(text = 'Byeeee', lang = 'en')
                #tts.save('/home/turtlebot/wavFiles/bye.wav')
                rospy.loginfo('Turtlebot says end of conversation...')
                sound_client.playWave('/home/turtlebot/wavFiles/bye.wav', blocking=True)
                break
	    
        return tracker
Beispiel #53
0
    
    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)
    #    
    print 'wave'
    soundhandle.playWave('say-beep.wav')
    sleep(2)
        
    print 'plugging'
    soundhandle.play(SoundRequest.NEEDS_PLUGGING)
    sleep(2)

    print 'unplugging'
    soundhandle.play(SoundRequest.NEEDS_UNPLUGGING)
    sleep(2)

    print 'plugging badly'
    soundhandle.play(SoundRequest.NEEDS_PLUGGING_BADLY)
    sleep(2)

    print 'unplugging badly'
Beispiel #54
0
class SpeechState(smach.State):
    """ Speech player state

    Takes in text and/or a wave file.  Given a wave file, plays the file.
    If no wave file is provided and text-to-speech is on, fetch the audio from
    Amazon Polly and play the audio.  If no wave file is provided and text-to-
    speech is off, return "no_audio"

    **Input keys**
        * text : str
            Can be None; the text version of the robot's speech.  Used to print
            to the screen.
        * wav_file : str
            Can be None if TTS is on. The path to the audio file.

    **Outcomes**
        * done
            Finished fetching behaviors
        * no_audio
            Couldn't find the wave file, or no wave file provided and TTS
            turned off
        * preempted
            State was preempted before audio finished playing.  If preempted,
            will try to stop the audio.

    """
    def __init__(self, use_tts, synchronizer, phrases=None, voice="Kimberly"):
        """ Constructor

        Initializes the speech state with the desired parameters; either with
        or without online TTS, and with or without a pre-generated phrase
        file.

        Parameters
        -----------
        use_tts : bool
            If true, allow online TTS
        synchronizer : Synchronizer
            Synchronizer object to allow sync of speech and behaviors.  Should
            be the same object as is passed to behavior ControllerState objects
            with ``setup_sync``
        voice : str, optional
            Which Amazon Polly voice to use. Defaults to Kimberly

        phrases : str, optional
            Path to the phrase file to use. If None, require online TTS.
        """
        smach.State.__init__(self,outcomes=["preempted","no_audio","done"],
                             input_keys=["text","wav_file"])
        self._tts = use_tts
        if use_tts:
            self._talker = CoRDialTTS(voice)
        self._sound_client = SoundClient()
        self._sync = synchronizer
 
    def execute(self,userdata):
        rospy.loginfo("Saying: {}".format(userdata.text))
        if userdata.wav_file==None:
            if userdata.text!=None and len(userdata.text)!=0:
                speech_duration = self._talker.say(userdata.text,wait=False)
                rospy.sleep(0.5)
                self._sync.start()
            else:
                return "no_audio"
        else:
            wav_file = userdata.wav_file
            with contextlib.closing(wave.open(wav_file,'r')) as f:
                frames=f.getnframes()
                rate=f.getframerate()
                speech_duration=frames/float(rate)
            self._sound_client.playWave(wav_file)
            self._sync.start()
        
        while rospy.Time.now()-self._sync.time<rospy.Duration(speech_duration):
            if self.preempt_requested():
                if self._tts:
                    self._talker.shutup()
                else:
                    self._sound_client.stopAll()
                self.service_preempt()
                return "preempted"
        return "done"
def wavHandler(data):
	soundhandle = SoundClient()
	rospy.sleep(1)
	soundhandle.playWave(data.data)
	rospy.sleep(1)
Beispiel #56
0
class TweetImageServer(object):
    def __init__(self):
        self.pack = rospkg.RosPack()
        self.bridge = cv_bridge.CvBridge()
        self.image_path = rospy.get_param('~image_path',
                                          '/tmp/tweet_image_server.png')
        self.image_timeout = rospy.get_param('~image_timeout', 5)
        account_info = rospy.get_param('~account_info',
                                       '/var/lib/robot/account.yaml')
        ckey, csecret, akey, asecret = load_oauth_settings(account_info)
        if not ckey or not csecret or not akey or not asecret:
            sys.exit(1)

        self.api = Twitter(consumer_key=ckey,
                           consumer_secret=csecret,
                           access_token_key=akey,
                           access_token_secret=asecret)
        self.client = SoundClient(blocking=True, sound_action='robotsound_jp')
        self.server = actionlib.SimpleActionServer('~tweet', TweetAction,
                                                   self._execute_cb)

    def _execute_cb(self, goal):
        ret = None
        success = True
        if goal.image:
            if os.path.exists(self.image_path):
                os.remove(self.image_path)
            self.sub = rospy.Subscriber(goal.image_topic_name, Image,
                                        self._image_cb)

        if goal.warning and goal.speak:
            if goal.warning_time <= 0:
                warning_text = 'ぜろ'
                goal.warning_time = 0
            elif goal.warning_time == 1:
                warning_text = 'いち'
            elif goal.warning_time == 2:
                warning_text = 'に'
            elif goal.warning_time == 3:
                warning_text = 'さん'
            elif goal.warning_time == 4:
                warning_text = 'よん'
            elif goal.warning_time == 5:
                warning_text = 'ご'
            elif goal.warning_time == 6:
                warning_text = 'ろく'
            elif goal.warning_time == 7:
                warning_text = 'なな'
            elif goal.warning_time == 8:
                warning_text = 'はち'
            elif goal.warning_time == 9:
                warning_text = 'きゅう'
            elif goal.warning_time >= 10:
                warning_text = 'じゅう'
                goal.warning_time = 10
            else:
                warning_text = 'さん'
                goal.warning_time = 3
            warning_text = warning_text + 'びょうまえ'
            self.client.say(warning_text)
            if goal.warning_time > 0:
                time.sleep(goal.warning_time)
            wave_path = os.path.join(self.pack.get_path('rostwitter'),
                                     'resource/camera.wav')
            self.client.playWave(wave_path)

        if goal.image:
            now = rospy.Time.now()
            while ((rospy.Time.now() - now).to_sec() < self.image_timeout
                   and not os.path.exists(self.image_path)):
                time.sleep(0.1)
                if self.server.is_preempt_requested():
                    rospy.logerr('tweet image server preempted')
                    self.server.set_preempted()
                    success = False
                    break
                feedback = TweetFeedback(stamp=rospy.Time.now())
                self.server.publish_feedback(feedback)
            if success and os.path.exists(self.image_path):
                ret = self.api.post_media(goal.text, self.image_path)
            else:
                rospy.logerr('cannot find image: {}'.format(self.image_path))
                ret = self.api.post_update(goal.text)
            self.sub.unregister()
            del self.sub
        else:
            ret = self.api.post_update(goal.text)

        if not ret or 'errors' in ret:
            success = False
            rospy.logerr('Failed to post: {}'.format(ret))

        if success:
            if goal.speak:
                self.client.say('ついーとしました')
            res = TweetResult(success=success)
            self.server.set_succeeded(res)

    def _image_cb(self, msg):
        img = self.bridge.imgmsg_to_cv2(msg, desired_encoding='bgr8')
        cv2.imwrite(self.image_path, img)
Beispiel #57
0
#*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#*  POSSIBILITY OF SUCH DAMAGE.
#***********************************************************

# Author: Blaise Gassend

import sys

if __name__ == '__main__':
    if len(sys.argv) < 2 or len(sys.argv) > 3 or sys.argv[1] == '--help':
        print 'Usage: %s sound_to_play.(ogg|wav) [volume]' % sys.argv[0]
        print
        print 'Plays an .OGG or .WAV file. The path to the file should be absolute, and be valid on the computer on which sound_play is running.\n The (optional) second parameter sets the volume for the sound as a value between 0 and 1.0, where 0 is mute.'
        exit(1)

    # Import after printing usage for speed.
    import rospy
    from sound_play.msg import SoundRequest
    from sound_play.libsoundplay import SoundClient

    rospy.init_node('play', anonymous=True)
    soundhandle = SoundClient()

    rospy.sleep(1)
    print 'Playing "%s".' % sys.argv[1]

    volume = float(sys.argv[2]) if len(sys.argv) == 3 else 1.0

    soundhandle.playWave(sys.argv[1], volume)
    rospy.sleep(1)
Beispiel #58
0
#!usr/bin/env python
import roslib; roslib.load_manifest('sound_play')
import rospy
from sound_play.libsoundplay import SoundClient

rospy.init_node('play_sound_file')
#Create a sound client instance
sound_client = SoundClient()
#wait for sound_play node to connect to publishers (otherwise it will miss first published msg)
rospy.sleep(2)
#Method 1: Play Wave file directly from Client
sound_client.playWave('/BobaBot/voice_utils/audio_recordings/thank_end.wav')
Beispiel #59
0
    def __init__(self):
        tracker = {'room': None}
        # initiliaze
        rospy.init_node('ttsconvert', anonymous=False)
        self.tf = TransformListener()
        #rospy.loginfo('Example: Playing sounds in *blocking* mode.')
        soundhandle = SoundClient(blocking=True)
        self.goal_sent = False
        #rospy.loginfo('Good Morning.')
        #soundhandle.playWave('/home/turtlebot/wavFiles/start.wav')
        self.move_base = actionlib.SimpleActionClient("move_base",
                                                      MoveBaseAction)
        rospy.loginfo("Wait for the action server to come up")
        # Allow up to 5 seconds for the action server to come up
        self.move_base.wait_for_server(rospy.Duration(5))
        # What to do you ctrl + c
        rospy.on_shutdown(self.shutdown)

        # Import the graphml to be read later
        G = nx.read_graphml("2nd_demo.graphml", unicode)
        root = 'n1'
        current = root

        # Clear words.log
        f = open("words.log", "r+")
        f.seek(0)
        f.truncate()

        # Clear clean.log
        with open("clean.log", "w"):
            pass

# Constantly read from words.log for new lines
        while True:
            line = f.readline()

            # If the user said something
            if line:
                # The lines with dialogue all begin with a numerical value
                if line[0][:1] in '0123456789':
                    # remove 9 numbers, colon, and space from the beginning, and any whitespace from the end of the line
                    speech = line[11:].rstrip()
                    print speech

                    count = 0
                    # Search through all edges connected to the current node
                    for e in G.edges(current, data=True):

                        # If what was spoken matches the 'spoken' attribute of the edge
                        if str(speech) == str(e[2].values()[0]):
                            # Switch the current node to be the node the edge goes to
                            current = e[1]

                            # find '*' symbol in output string and and replace it with what user said stored in speech

                            # Get the dialogue stored in the new node and save it in 'output'
                            output = G.node[current]['dialogue']
                            if current == 'n7':
                                output = output.replace('*', str(speech))
                                tracker['room'] = str(speech).lower()
                            print 'OUTPUT: %s' % output

                            tts = gTTS(text=output, lang='en')
                            tts.save('/home/raeesa/Desktop/line.wav')

                            subprocess.Popen([
                                'gnome-terminal', '-x', 'bash', '-c',
                                'pacmd set-source-mute 2 1'
                            ])
                            #rospy.loginfo('playing output')
                            soundhandle.playWave(
                                '/home/raeesa/Desktop/line.wav', blocking=True)
                            #soundhandle.say(output)
                            subprocess.Popen([
                                'gnome-terminal', '-x', 'bash', '-c',
                                'pacmd set-source-mute 2 0'
                            ])

                            # Add 'output' to the top of clean.log
                            with open("clean.log", "r+") as g:
                                # Read everything from clean.log into 'content'
                                content = g.read()
                                # Go to the top of the file
                                g.seek(0, 0)
                                # Write 'output' with 'content' appended to the end back to clean.log
                                g.write(output.rstrip('\r\n') + '\n' + content)
                                g.close()

                            if current == 'n9':
                                room = tracker.get('room')
                                position = {
                                    'x': goals.get(room, "201")[0],
                                    'y': goals.get(room, "201")[1]
                                }
                                # Customize the following values so they are appropriate for your location
                                #position = {'x': 5.12, 'y' : 2.72}
                                quaternion = {
                                    'r1': 0.000,
                                    'r2': 0.000,
                                    'r3': 0.000,
                                    'r4': 1.000
                                }

                                rospy.loginfo("Go to (%s, %s) pose",
                                              position['x'], position['y'])
                                self.goto(position, quaternion)

                    # If there are no outgoing edges from the current node, go back to the root
                            if G.out_degree(current) == 0:
                                current = root
Beispiel #60
0
    rospy.init_node("boot_sound")
    sound = SoundClient()
    time.sleep(1) # ???
    ac = actionlib.SimpleActionClient('sound_play', SoundRequestAction)
    ac.wait_for_server()
    if len(ni.ifaddresses('eth0')) > 2 :
        ip = ni.ifaddresses('eth0')[2][0]['addr']
    elif len(ni.ifaddresses('wlan0')) > 2 :
        ip = ni.ifaddresses('wlan0')[2][0]['addr']
    else:
        ip = None

    # play sound
    rospack = rospkg.RosPack()
    wav_file = os.path.join(rospack.get_path("jsk_fetch_startup"),"data/boot_sound.wav")
    rospy.loginfo("Playing {}".format(wav_file))
    sound.playWave(wav_file)
    time.sleep(10) # make sure to topic is going out

    # notify ip address
    ip_text = "My internet address is {}".format(ip)
    rospy.loginfo(ip_text)
    ip_text = ip_text.replace('.', ', ')
    sound.say(ip_text)
    time.sleep(1) # make sure to topic is going out