File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
utilities/smarc_utilities Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 55
55
[submodule "external_equipment/PlayStation-JoyInterface-ROS2 "]
56
56
path = external_equipment/PlayStation-JoyInterface-ROS2
57
57
url = https://github.com/HarvestX/PlayStation-JoyInterface-ROS2
58
+ branch = humble
Original file line number Diff line number Diff line change 20
20
tests_require = ['pytest' ],
21
21
entry_points = {
22
22
'console_scripts' : [
23
+ 'simple_tts = smarc_utilities.tts:main' ,
23
24
],
24
25
},
25
26
)
Original file line number Diff line number Diff line change
1
+ import subprocess
2
+ from rclpy .node import Node
3
+ from std_msgs .msg import String
4
+
5
+
6
+ class TTS :
7
+ def __init__ (self ,
8
+ node : Node ,
9
+ topic : str = "speak" ,
10
+ engine : str = "spd-say" ):
11
+
12
+ self ._node = node
13
+ self ._topic = topic
14
+ self ._engine = engine
15
+
16
+ self ._speak_sub = self ._node .create_subscription (
17
+ String ,
18
+ self ._topic ,
19
+ self .speak ,
20
+ 10
21
+ )
22
+
23
+ def speak (self , text : String ):
24
+ t = text .data
25
+ if not t :
26
+ self ._node .get_logger ().warn ("Received empty text for TTS." )
27
+ return
28
+ self ._node .get_logger ().info (f"Speaking: { t } " )
29
+ subprocess .run ([self ._engine , t ])
30
+
31
+
32
+
33
+ def main ():
34
+ import rclpy
35
+ from rclpy .executors import SingleThreadedExecutor
36
+
37
+ rclpy .init ()
38
+ node = Node ("tts_node" )
39
+ tts = TTS (node )
40
+
41
+ executor = SingleThreadedExecutor ()
42
+ executor .add_node (node )
43
+
44
+ try :
45
+ executor .spin ()
46
+ except KeyboardInterrupt :
47
+ pass
48
+ finally :
49
+ node .destroy_node ()
50
+ rclpy .shutdown ()
51
+
You can’t perform that action at this time.
0 commit comments