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

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

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

Joy.Lin gravatar image

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

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
1

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

ahendrix gravatar image

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

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");

    ros::spin();
}
edit flag offensive delete link more

Comments

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 -0600 )edit

The documentation and example links are broken

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

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

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

Fixed the links; thanks for catching that.

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

Question Tools

1 follower

Stats

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

Seen: 2,222 times

Last updated: Jun 11 '16