2 from __future__
import print_function
11 import actionlib_msgs.msg
as actionlib_msgs
14 import gcloud_speech_msgs.msg
as gcloud_speech_msgs
16 GoalStatus = actionlib_msgs.GoalStatus
19 def DoneCallback(state, result):
20 print(
"\n\nDone, state {}, result:\n{}\n".format(state,result))
24 print(
"The goal is now active.\n")
27 def FeedbackCallback(feedback):
28 print(
"{}\n".format(feedback))
31 global sigint_received
32 sigint_received =
False 34 def SignalIntHandler(signal, frame):
35 print(
"Received SIGINT.")
36 global sigint_received
37 sigint_received =
True 40 def DelayedExit(wait_time):
45 signal.signal(signal.SIGINT, SignalIntHandler)
48 "/cogrob/speech_to_text", gcloud_speech_msgs.SpeechToTextAction)
49 client.wait_for_server()
51 goal = gcloud_speech_msgs.SpeechToTextGoal()
52 client.send_goal(goal, done_cb=DoneCallback, active_cb=ActiveCallback,
53 feedback_cb=FeedbackCallback)
55 while client.get_state()
in [GoalStatus.PENDING, GoalStatus.ACTIVE]:
63 exit_thread = threading.Thread(target=DelayedExit, args=(1, ))
64 exit_thread.daemon =
True 69 client.wait_for_result()
72 if __name__ ==
'__main__':
74 rospy.init_node(
"gcloud_speech_example_client", anonymous=
True)
76 except rospy.ROSInterruptException:
77 print(
"Program interrupted before completion.", file=sys.stderr)
def SpeechToTextSimpleExampleClient()