<s> import rospy <EOL> import threading , time , pyttsx <EOL> import actionlib <EOL> from basics . msg import TalkAction , TalkGoal , TalkResult <EOL> class TalkNode ( ) : <EOL> def __init__ ( self , node_name , action_name ) : <EOL> rospy . init_node ( node_name ) <EOL> self . server = actionlib . SimpleActionServer ( action_name , TalkAction , <EOL> self . do_talk , False ) <EOL> self . engine = pyttsx . init ( ) <EOL> self . engine_thread = threading . Thread ( target = self . loop ) <EOL> self . engine_thread . start ( ) <EOL> self . engine . setProperty ( '<STR_LIT>' , rospy . get_param ( '<STR_LIT>' , <NUM_LIT:1.0> ) ) <EOL> self . engine . setProperty ( '<STR_LIT>' , rospy . get_param ( '<STR_LIT>' , <NUM_LIT> ) ) <EOL> self . preempt = rospy . get_param ( '<STR_LIT>' , False ) <EOL> self . server . start ( ) <EOL> def loop ( self ) : <EOL> self . engine . startLoop ( False ) <EOL> while not rospy . is_shutdown ( ) : <EOL> self . engine . iterate ( ) <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> self . engine . endLoop ( ) <EOL> def do_talk ( self , goal ) : <EOL> self . engine . say ( goal . sentence ) <EOL> while self . engine . isBusy ( ) : <EOL> if self . preempt and self . server . is_preempt_requested ( ) : <EOL> self . engine . stop ( ) <EOL> while self . engine . isBusy ( ) : <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> self . server . set_preempted ( TalkResult ( ) , "<STR_LIT>" ) <EOL> return <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> self . server . set_succeeded ( TalkResult ( ) , "<STR_LIT>" ) <EOL> talker = TalkNode ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> rospy . spin ( ) </s>
