Class SoundClient

Nested Relationships

Nested Types

Class Documentation

class SoundClient

Class that publishes messages to the sound_play node.

This class is a helper class for communicating with the sound_play node via the sound_play::SoundRequest message. It has two ways of being used:

  • It can create Sound classes that represent a particular sound which can be played, repeated or stopped.

  • It provides methods for each way in which the sound_play::SoundRequest message can be invoked.

Public Functions

inline SoundClient(rclcpp::Node::SharedPtr nh, const std::string &topic)

Create a SoundClient that publishes on the given topic.

Creates a SoundClient that publishes to the given topic relative to the given NodeHandle.

Parameters:
  • nh – Node handle to use when creating the topic.

  • topic – Topic to publish to.

inline SoundClient(rclcpp::Node::SharedPtr nh)

Create a SoundClient with the default topic.

Creates a SoundClient that publishes to “robotsound”.

Parameters:

nh – Node handle to use when creating the topic.

inline Sound voiceSound(const std::string &s, float volume = 1.0f)

Create a voice Sound.

Creates a Sound corresponding to saying the indicated text.

Parameters:
  • s – Text to say

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline Sound waveSound(const std::string &s, float volume = 1.0f)

Create a wave Sound.

Creates a Sound corresponding to indicated file.

Parameters:
  • s – File to play. Should be an absolute path that exists on the machine running the sound_play node.

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline Sound waveSoundFromPkg(const std::string &p, const std::string &s, float volume = 1.0f)

Create a wave Sound from a package.

Creates a Sound corresponding to indicated file.

Parameters:
  • p – Package containing the sound file.

  • s – Filename of the WAV or OGG file. Must be an path relative to the package valid on the computer on which the sound_play node is running

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline Sound builtinSound(int id, float volume = 1.0f)

Create a builtin Sound.

Creates a Sound corresponding to indicated builtin wave.

Parameters:
  • id – Identifier of the sound to play.

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline void say(const std::string &s, const std::string &voice = "voice_kal_diphone", float volume = 1.0f)

Say a string.

Send a string to be said by the sound_node. The vocalization can be stopped using stopSaying or stopAll.

Parameters:
  • s – String to say

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline void repeat(const std::string &s, float volume = 1.0f)

Say a string repeatedly.

The string is said repeatedly until stopSaying or stopAll is used.

Parameters:
  • s – String to say repeatedly

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline void stopSaying(const std::string &s)

Stop saying a string.

Stops saying a string that was previously started by say or repeat. The argument indicates which string to stop saying.

Parameters:

s – Same string as in the say or repeat command

inline void playWave(const std::string &s, float volume = 1.0f)

Plays a WAV or OGG file.

Plays a WAV or OGG file once. The playback can be stopped by stopWave or stopAll.

Parameters:
  • s – Filename of the WAV or OGG file. Must be an absolute path valid on the computer on which the sound_play node is running

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline void startWave(const std::string &s, float volume = 1.0f)

Plays a WAV or OGG file repeatedly.

Plays a WAV or OGG file repeatedly until stopWave or stopAll is used.

Parameters:
  • s – Filename of the WAV or OGG file. Must be an absolute path valid on the computer on which the sound_play node is running.

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline void stopWave(const std::string &s)

Stop playing a WAV or OGG file.

Stops playing a file that was previously started by playWave or startWave.

Parameters:

s – Same string as in the playWave or startWave command

inline void playWaveFromPkg(const std::string &p, const std::string &s, float volume = 1.0f)

Plays a WAV or OGG file from a package.

Plays a WAV or OGG file once. The playback can be stopped by stopWaveFromPkg or stopAll.

Parameters:
  • p – Package name containing the sound file.

  • s – Filename of the WAV or OGG file. Must be an path relative to the package valid on the computer on which the sound_play node is running

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline void startWaveFromPkg(const std::string &p, const std::string &s, float volume = 1.0f)

Plays a WAV or OGG file repeatedly.

Plays a WAV or OGG file repeatedly until stopWaveFromPkg or stopAll is used.

Parameters:
  • p – Package name containing the sound file.

  • s – Filename of the WAV or OGG file. Must be an path relative to the package valid on the computer on which the sound_play node is running

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline void stopWaveFromPkg(const std::string &p, const std::string &s)

Stop playing a WAV or OGG file.

Stops playing a file that was previously started by playWaveFromPkg or startWaveFromPkg.

Parameters:
  • p – Package name containing the sound file.

  • s – Filename of the WAV or OGG file. Must be an path relative to the package valid on the computer on which the sound_play node is running

inline void play(int sound, float volume = 1.0f)

Play a buildin sound.

Starts playing one of the built-in sounds. built-ing sounds are documented in SoundRequest.msg. Playback can be stopped by stopAll.

Parameters:
  • sound – Identifier of the sound to play.

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline void start(int sound, float volume = 1.0f)

Play a buildin sound repeatedly.

Starts playing one of the built-in sounds repeatedly until stop or stopAll is used. Built-in sounds are documented in SoundRequest.msg.

Parameters:
  • sound – Identifier of the sound to play.

  • volume – Volume at which to play the sound. 0 is mute, 1.0 is 100%.

inline void stop(int sound)

Stop playing a built-in sound.

Stops playing a built-in sound started with play or start.

Parameters:

sound – Same sound that was used to start playback.

inline void stopAll()

Stop all currently playing sounds.

This method stops all speech, wave file, and built-in sound playback.

inline void setQuiet(bool state)

Turns warning messages on or off.

If a message is sent when no node is subscribed to the topic, a warning message is printed. This method can be used to enable or disable warnings.

Parameters:

state – True to turn off messages, false to turn them on.

class Sound

Public Functions

inline void play()

Play the Sound.

This method causes the Sound to be played once.

inline void repeat()

Play the Sound repeatedly.

This method causes the Sound to be played repeatedly until stop() is called.

inline void stop()

Stop Sound playback.

This method causes the Sound to stop playing.