is_speaking.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 
5 from actionlib_msgs.msg import GoalStatus
6 from actionlib_msgs.msg import GoalStatusArray
7 import std_msgs.msg
8 
9 
10 class IsSpeaking(object):
11 
12  def __init__(self):
13  super(IsSpeaking, self).__init__()
14 
15  self.sub = rospy.Subscriber(
16  '~robotsound',
17  GoalStatusArray,
18  callback=self.callback,
19  queue_size=1)
20 
21  self.is_speaking = False
22  self.pub_speech_flag = rospy.Publisher(
23  '~output/is_speaking',
24  std_msgs.msg.Bool, queue_size=1)
25 
26  self.timer = rospy.Timer(rospy.Duration(0.01), self.speech_timer_cb)
27 
28  def check_speak_status(self, status_msg):
29  """Returns True when speaking.
30 
31  """
32  # If it is not included in the terminal state,
33  # it is determined as a speaking state.
34  if status_msg.status in [GoalStatus.ACTIVE,
35  GoalStatus.PREEMPTING,
36  GoalStatus.RECALLING]:
37  return True
38  return False
39 
40  def callback(self, msg):
41  for status in msg.status_list:
42  if self.check_speak_status(status):
43  self.is_speaking = True
44  return
45  self.is_speaking = False
46 
47  def speech_timer_cb(self, timer):
48  self.pub_speech_flag.publish(
49  std_msgs.msg.Bool(self.is_speaking))
50 
51 
52 if __name__ == '__main__':
53  rospy.init_node('is_speaking')
54  app = IsSpeaking()
55  rospy.spin()
def check_speak_status(self, status_msg)
Definition: is_speaking.py:28
def callback(self, msg)
Definition: is_speaking.py:40
def speech_timer_cb(self, timer)
Definition: is_speaking.py:47


sound_play
Author(s): Blaise Gassend
autogenerated on Fri Jun 9 2023 02:47:15