diff --git a/skills/src/lasr_skills/__init__.py b/skills/src/lasr_skills/__init__.py index 8bd00a28a..58b23b10b 100755 --- a/skills/src/lasr_skills/__init__.py +++ b/skills/src/lasr_skills/__init__.py @@ -9,3 +9,4 @@ from .go_to_location import GoToLocation from .go_to_semantic_location import GoToSemanticLocation from .say import Say +from .listen_for import ListenFor diff --git a/skills/src/lasr_skills/listen_for.py b/skills/src/lasr_skills/listen_for.py new file mode 100644 index 000000000..7b7456a6e --- /dev/null +++ b/skills/src/lasr_skills/listen_for.py @@ -0,0 +1,25 @@ +import smach_ros +from lasr_speech_recognition_msgs.msg import ( + TranscribeSpeechAction, + TranscribeSpeechGoal, +) + +from actionlib_msgs.msg import GoalStatus + + +class ListenFor(smach_ros.SimpleActionState): + def __init__(self, wake_word: str): + + def speech_result_cb(userdata, status, result): + if status == GoalStatus.SUCCEEDED: + if wake_word in result.transcription.lower().split(): + return "succeeded" + return "not_done" + return "failed" + + smach_ros.SimpleActionState.__init__( + self, + "transcribe_speech", + TranscribeSpeechAction, + result_cb=speech_result_cb, + )