Ask Your Question
0

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
1

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

    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 imageJoy.Lin ( 2016-05-14 03:11:30 -0500 )edit

The documentation and example links are broken

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

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

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

Fixed the links; thanks for catching that.

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 1,218 times

Last updated: Jun 11 '16