scripts
say.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
#***********************************************************
4
#* Software License Agreement (BSD License)
5
#*
6
#* Copyright (c) 2009, Willow Garage, Inc.
7
#* All rights reserved.
8
#*
9
#* Redistribution and use in source and binary forms, with or without
10
#* modification, are permitted provided that the following conditions
11
#* are met:
12
#*
13
#* * Redistributions of source code must retain the above copyright
14
#* notice, this list of conditions and the following disclaimer.
15
#* * Redistributions in binary form must reproduce the above
16
#* copyright notice, this list of conditions and the following
17
#* disclaimer in the documentation and/or other materials provided
18
#* with the distribution.
19
#* * Neither the name of the Willow Garage nor the names of its
20
#* contributors may be used to endorse or promote products derived
21
#* from this software without specific prior written permission.
22
#*
23
#* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
#* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
#* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
#* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
#* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
#* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
#* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
#* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
#* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
#* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
#* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
#* POSSIBILITY OF SUCH DAMAGE.
35
#***********************************************************
36
37
# Author: Blaise Gassend
38
39
40
import
sys
41
42
if
__name__ ==
'__main__'
:
43
import
rospy
44
argv = rospy.myargv()
45
if
len(argv) > 1
and
argv[1] ==
'--help'
:
46
print(
'Usage: %s \'String to say.\''
% argv[0])
47
print(
' %s < file_to_say.txt'
% argv[0])
48
print()
49
print(
'Says a string. For a string on the command line, you must use quotes as'
)
50
print(
'appropriate. For a string on standard input, the command will wait for'
)
51
print(
'EOF before saying anything.'
)
52
exit(-1)
53
54
# Import after printing usage for speed.
55
from
sound_play.msg
import
SoundRequest
56
from
sound_play.libsoundplay
import
SoundClient
57
58
if
len(argv) == 1:
59
print(
'Awaiting something to say on standard input.'
)
60
61
# Ordered this way to minimize wait time.
62
rospy.init_node(
'say'
, anonymous=
True
)
63
soundhandle =
SoundClient
()
64
rospy.sleep(1)
65
66
voice =
'voice_kal_diphone'
67
volume = 1.0
68
69
if
len(argv) == 1:
70
s = sys.stdin.read()
71
else
:
72
s = argv[1]
73
74
if
len(argv) > 2:
75
voice = argv[2]
76
if
len(argv) > 3:
77
volume = float(argv[3])
78
79
rospy.loginfo(
'Saying: %s'
% s)
80
rospy.loginfo(
'Voice: %s'
% voice)
81
rospy.loginfo(
'Volume: %s'
% volume)
82
83
soundhandle.say(s, voice, volume)
84
rospy.sleep(1)
sound_play.libsoundplay.SoundClient
This class is a helper class for communicating with the sound_play node via the sound_play....
Definition:
libsoundplay.py:92
sound_play.libsoundplay
Definition:
libsoundplay.py:1
sound_play
Author(s): Blaise Gassend
autogenerated on Fri Aug 16 2024 02:42:13