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

How do I play sound file in a C++ node with sound_play

asked 2016-05-09 10:19:34 -0500

Joy.Lin gravatar image

updated 2016-05-09 10:21:42 -0500

hi everyone. I want to play a sound file on a C++ node with sound_play. I have downloaded the audio_common package already , but I don't know how to use it to realize my purpose. Please anyone can give me a detailed tutorial . I use indigo catkin ubuntu 14.04

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-05-10 15:39:54 -0500

ahendrix gravatar image

updated 2016-06-11 12:30:35 -0500

From the 'Code API' link on the sound_play wiki page you can get to the documentation and example for the C++ SoundPlay client.

The function you probably want to use is playWaveFromPkg; it should look something like this:

int main(int argc, char ** argv) {
    ros::init(argc, argv, "example");

    ros::NodeHandle nh;
    sound_play::SoundClient sc;

    sc.playWaveFromPkg("sound_play", "sounds/BACKINGUP.ogg");

edit flag offensive delete link more


Thank you very much . I can play the sound file successfully!! However, I can't control its volume, it's always too low.

Joy.Lin gravatar image Joy.Lin  ( 2016-05-14 03:11:30 -0500 )edit

The documentation and example links are broken

rodrigobdz gravatar image rodrigobdz  ( 2016-06-11 04:13:57 -0500 )edit

The links are now found under the docs directory for each distribution

rodrigobdz gravatar image rodrigobdz  ( 2016-06-11 04:30:21 -0500 )edit

Fixed the links; thanks for catching that.

ahendrix gravatar image ahendrix  ( 2016-06-11 12:30:52 -0500 )edit

Question Tools

1 follower


Asked: 2016-05-09 10:19:34 -0500

Seen: 2,162 times

Last updated: Jun 11 '16