ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Similar to using the text-to-speech from the sound_play node, you have two (very similar) options. First import the SoundClient from the sound_play.libsoundplay. Then you can play a sound file (.wav or .ogg) with the sound client's '.playWave("/full/path/to/sound.wav")' method. Or you can use the client's '.waveSound("/full/path/to/sound.wav")' method to create a Sound object. Then use the Sound objects '.play()' method to play the sound.

Here is an example snippet showing both:

    #!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 the first published message)
    rospy.sleep(2)
    #Method 1: Play Wave file directly from Client
    sound_client.playWave('/full/path/to/sound.wav')

    #Method 2: Create Sound instance for file, play with '.play()' method
    sound = sound_client.waveSound('/full/path/to/sound.wav')
    sound.play()
click to hide/show revision 2
fix spacing in python

Similar to using the text-to-speech from the sound_play node, you have two (very similar) options. First import the SoundClient from the sound_play.libsoundplay. Then you can play a sound file (.wav or .ogg) with the sound client's '.playWave("/full/path/to/sound.wav")' method. Or you can use the client's '.waveSound("/full/path/to/sound.wav")' method to create a Sound object. Then use the Sound objects '.play()' method to play the sound.

Here is an example snippet showing both:

    #!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 the first published message)
msg)
    rospy.sleep(2)
    #Method 1: Play Wave file directly from Client
    sound_client.playWave('/full/path/to/sound.wav')

    #Method 2: Create Sound instance for file, play with '.play()' method
    sound = sound_client.waveSound('/full/path/to/sound.wav')
    sound.play()