test.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2009, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 #include <sound_play/sound_play.h>
36 #include <unistd.h>
37 
38 void sleepok(int t, ros::NodeHandle &nh)
39 {
40  if (nh.ok())
41  sleep(t);
42 }
43 
44 int main(int argc, char **argv)
45 {
46  ros::init(argc, argv, "sound_play_test");
47 
48  ros::NodeHandle nh;
50  sound_play::SoundClient quiet_sc;
51 
52  sleepok(1, nh);
53 
54  while(nh.ok())
55  {
56  sc.say("Hello world!");
57  sleepok(2, nh);
58  quiet_sc.say("Hello world!");
59  sleepok(2, nh);
60 
61  const char *str1 = "I am annoying.";
62  sc.repeat(str1);
63  sleepok(4, nh);
64  sc.stopSaying(str1);
65  quiet_sc.repeat(str1);
66  sleepok(4, nh);
67  quiet_sc.stopSaying(str1);
68 
69  sc.playWave("/usr/share/xemacs21/xemacs-packages/etc/sounds/boing.wav");
70  sleepok(2, nh);
71  quiet_sc.playWave("/usr/share/xemacs21/xemacs-packages/etc/sounds/boing.wav");
72  sleepok(2, nh);
73 
74  const char *str2 = "/usr/share/xemacs21/xemacs-packages/etc/sounds/piano-beep.wav";
75  sc.startWave(str2);
76  sleepok(4, nh);
77  sc.stopWave(str2);
78  quiet_sc.startWave(str2);
79  sleepok(4, nh);
80  quiet_sc.stopWave(str2);
81 
82  sc.play(sound_play::SoundRequest::NEEDS_UNPLUGGING);
83  sleepok(2, nh);
84  quiet_sc.play(sound_play::SoundRequest::NEEDS_UNPLUGGING);
85  sleepok(2, nh);
86 
87  sc.play(sound_play::SoundRequest::NEEDS_UNPLUGGING);
88  sleepok(2, nh);
89  quiet_sc.play(sound_play::SoundRequest::NEEDS_UNPLUGGING);
90  sleepok(2, nh);
91 
92  sc.start(sound_play::SoundRequest::BACKINGUP);
93  sleepok(4, nh);
94  sc.stop(sound_play::SoundRequest::BACKINGUP);
95  quiet_sc.start(sound_play::SoundRequest::BACKINGUP);
96  sleepok(4, nh);
97  quiet_sc.stop(sound_play::SoundRequest::BACKINGUP);
98 
99  sleepok(2, nh);
100  sound_play::Sound s1 = sc.waveSound("/usr/share/xemacs21/xemacs-packages/etc/sounds/boing.wav");
101  s1.repeat();
102  sleepok(1, nh);
103  s1.stop();
104 
105  sleepok(2, nh);
106  sound_play::Sound s2 = quiet_sc.waveSound("/usr/share/xemacs21/xemacs-packages/etc/sounds/boing.wav");
107  s2.repeat();
108  sleepok(1, nh);
109  s2.stop();
110 
111  sleepok(2, nh);
112  sound_play::Sound s3 = sc.voiceSound("This is a really long sentence that will get cut off.");
113  s3.play();
114  sleepok(1, nh);
115  s3.stop();
116 
117  sleepok(2, nh);
118  sound_play::Sound s4 = quiet_sc.voiceSound("This is a really long sentence that will get cut off.");
119  s4.play();
120  sleepok(1, nh);
121  s4.stop();
122 
123  sleepok(2, nh);
124  sound_play::Sound s5 = sc.builtinSound(sound_play::SoundRequest::NEEDS_UNPLUGGING_BADLY);
125  s5.play();
126  sleepok(1, nh);
127  s5.stop();
128 
129  sleepok(2, nh);
130  sound_play::Sound s6 = quiet_sc.builtinSound(sound_play::SoundRequest::NEEDS_UNPLUGGING_BADLY);
131  s6.play();
132  sleepok(1, nh);
133  s6.stop();
134 
135  sleepok(2, nh);
136  sound_play::Sound s7 = sc.waveSoundFromPkg("sound_play", "sounds/BACKINGUP.ogg");
137  s7.play();
138  sleepok(1, nh);
139  s7.stop();
140 
141  sleepok(2, nh);
142  sound_play::Sound s8 = quiet_sc.waveSoundFromPkg("sound_play", "sounds/BACKINGUP.ogg");
143  s8.play();
144  sleepok(1, nh);
145  s8.stop();
146  }
147 }
void play(int sound, float volume=1.0f)
Play a buildin sound.
Definition: sound_play.h:314
void repeat()
Play the Sound repeatedly.
Definition: sound_play.h:98
s1
Definition: test.py:97
void repeat(const std::string &s, float volume=1.0f)
Say a string repeatedly.
Definition: sound_play.h:207
void sleepok(int t, ros::NodeHandle &nh)
Definition: test.cpp:38
s2
Definition: test.py:98
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void stopSaying(const std::string &s)
Stop saying a string.
Definition: sound_play.h:219
Sound builtinSound(int id, float volume=1.0f)
Create a builtin Sound.
Definition: sound_play.h:182
void startWave(const std::string &s, float volume=1.0f)
Plays a WAV or OGG file repeatedly.
Definition: sound_play.h:246
void play()
Play the Sound.
Definition: sound_play.h:88
Sound waveSoundFromPkg(const std::string &p, const std::string &s, float volume=1.0f)
Create a wave Sound from a package.
Definition: sound_play.h:170
void start(int sound, float volume=1.0f)
Play a buildin sound repeatedly.
Definition: sound_play.h:327
Sound waveSound(const std::string &s, float volume=1.0f)
Create a wave Sound.
Definition: sound_play.h:156
int main(int argc, char **argv)
Definition: test.cpp:44
s4
Definition: test.py:100
Sound voiceSound(const std::string &s, float volume=1.0f)
Create a voice Sound.
Definition: sound_play.h:143
void stopWave(const std::string &s)
Stop playing a WAV or OGG file.
Definition: sound_play.h:258
void say(const std::string &s, const std::string &voice="voice_kal_diphone", float volume=1.0f)
Say a string.
Definition: sound_play.h:195
s3
Definition: test.py:99
s5
Definition: test.py:101
s6
Definition: test.py:102
void playWave(const std::string &s, float volume=1.0f)
Plays a WAV or OGG file.
Definition: sound_play.h:233
Class that publishes messages to the sound_play node.
Definition: sound_play.h:61
bool ok() const
void stop()
Stop Sound playback.
Definition: sound_play.h:107
void stop(int sound)
Stop playing a built-in sound.
Definition: sound_play.h:338


sound_play
Author(s): Blaise Gassend
autogenerated on Tue Mar 26 2019 02:30:56