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 first published 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()
Originally posted by pgrice with karma: 196 on 2012-08-15
This answer was ACCEPTED on the original site
Post score: 3