当前位置: 首页>>代码示例>>Python>>正文


Python SoundClient.playWave方法代码示例

本文整理汇总了Python中sound_play.libsoundplay.SoundClient.playWave方法的典型用法代码示例。如果您正苦于以下问题:Python SoundClient.playWave方法的具体用法?Python SoundClient.playWave怎么用?Python SoundClient.playWave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sound_play.libsoundplay.SoundClient的用法示例。


在下文中一共展示了SoundClient.playWave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: callback

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
 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()
开发者ID:cdondrup,项目名称:christmas,代码行数:9,代码来源:santa.py

示例2: __init__

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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...")
开发者ID:Ortega-R94,项目名称:donaxi_arm_2,代码行数:28,代码来源:numbers.py

示例3: play_nonblocking

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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.')
开发者ID:78226415,项目名称:audio_common,代码行数:27,代码来源:soundclient_example.py

示例4: __init__

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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)
开发者ID:mayacakmak,项目名称:robot_eup,代码行数:27,代码来源:voice.py

示例5: __init__

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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)
开发者ID:OpenFEI,项目名称:rfh_judite,代码行数:28,代码来源:voice_play.py

示例6: __init__

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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')
开发者ID:MarcelGabriel1993,项目名称:chatbot,代码行数:14,代码来源:speak.py

示例7: main

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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)
开发者ID:TKatayama,项目名称:eye_see,代码行数:14,代码来源:sample.py

示例8: __init__

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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)
开发者ID:amuaz2,项目名称:kamerider,代码行数:54,代码来源:speech_interaction.py

示例9: __init__

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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...")
开发者ID:Chengxi9,项目名称:rbx1,代码行数:52,代码来源:talkback.py

示例10: execute

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
    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
开发者ID:jypuigbo,项目名称:robocup-code,代码行数:17,代码来源:play_sound_sm.py

示例11: generate_sound

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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])
开发者ID:jttte,项目名称:PR2_xylophone,代码行数:19,代码来源:move_actions.py

示例12: play_blocking

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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.')
开发者ID:78226415,项目名称:audio_common,代码行数:21,代码来源:soundclient_example.py

示例13: Say

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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
开发者ID:rosalfred,项目名称:alfred_tts_linux,代码行数:43,代码来源:tts_node.py

示例14: goal_status

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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)
开发者ID:RCPRG-ros-pkg,项目名称:elektron_kinectbot,代码行数:32,代码来源:goal_status.py

示例15: __init__

# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import playWave [as 别名]
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...")
开发者ID:bhavyangupta,项目名称:pandubot_wkspc,代码行数:42,代码来源:talkback.py


注:本文中的sound_play.libsoundplay.SoundClient.playWave方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。