Skip to content

Commit

Permalink
feat: receptionist command similarity matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
m-barker committed Jul 6, 2024
1 parent cfbf075 commit e27d16a
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 17 deletions.
34 changes: 17 additions & 17 deletions tasks/gpsr/src/gpsr/states/command_similarity_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def execute(self, userdata):
sm = smach.StateMachine(outcomes=["succeeded", "failed"])
with sm:
sm.userdata.tts_phrase = "Please tell me your command."
# smach.StateMachine.add(
# "ASK_FOR_COMMAND",
# AskAndListen(),
# transitions={"succeeded": "COMMAND_SIMILARITY_MATCHER", "failed": "failed"},
# remapping={"transcribed_speech": "command"},
# )
smach.StateMachine.add(
"ASK_FOR_COMMAND",
AskAndListen(),
transitions={"succeeded": "COMMAND_SIMILARITY_MATCHER", "failed": "failed"},
remapping={"transcribed_speech": "command"},
)
sm.add(
"LISTEN",
Listen(),
Expand All @@ -71,18 +71,18 @@ def execute(self, userdata):
sm.add(
"COMMAND_SIMILARITY_MATCHER",
CommandSimilarityMatcher([1177943] * 10),
transitions={"succeeded": "LISTEN"},
transitions={"succeeded": "SAY_MATCHED_COMMAND", "failed": "failed"},
)
sm.add(
"SAY_MATCHED_COMMAND",
Say(),
transitions={
"succeeded": "ASK_FOR_COMMAND",
"aborted": "failed",
"preempted": "failed",
},
remapping={"text": "matched_command"},
)
# smach.StateMachine.add(
# "SAY_MATCHED_COMMAND",
# Say(),
# transitions={
# "succeeded": "ASK_FOR_COMMAND",
# "aborted": "failed",
# "preempted": "failed",
# },
# remapping={"text": "matched_command"},
# )

sm.execute()
rospy.spin()
82 changes: 82 additions & 0 deletions tasks/receptionist/src/receptionist/states/match_name_and_drink.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python3
import os
import rospy
import rospkg
import smach
from lasr_skills import AskAndListen, Say
from lasr_vector_databases_msgs.srv import TxtQuery, TxtQueryRequest


class MatchNameAndDrink(smach.State):
def __init__(self):
smach.State.__init__(
self,
outcomes=["succeeded", "failed"],
input_keys=["sequence"],
output_keys=["matched_name", "matched_drink", "sequence"],
)

self._query_service = rospy.ServiceProxy("lasr_faiss/txt_query", TxtQuery)
self._text_path = os.path.join(
rospkg.RosPack().get_path("receptionist"),
"data",
"name_and_drink_vector_db.txt",
)
self._index_path = os.path.join(
rospkg.RosPack().get_path("receptionist"), "data", "name_and_drink.index"
)

def execute(self, userdata):
rospy.loginfo(f"Received transcript: {userdata.sequence}")
request = TxtQueryRequest()
request.txt_paths = [self._text_path]
request.index_paths = [self._index_path]
request.query_sentence = userdata.sequence
request.k = 1
response = self._query_service(request)
matched_name, matched_drink = response.closest_sentences[0].split(
" and my favorite drink is "
)
matched_name = matched_name.split("My name is ")[1]
userdata.matched_name = matched_name
userdata.matched_drink = matched_drink
rospy.loginfo(
f"Matched name: {matched_name} and matched drink: {matched_drink}"
)
userdata.sequence = (
f"Hello {matched_name}, I see that your favorite drink is {matched_drink}."
)
return "succeeded"


if __name__ == "__main__":
rospy.init_node("match_name_and_drink")
sm = smach.StateMachine(outcomes=["succeeded", "failed"])
with sm:
smach.StateMachine.add(
"ASK_FOR_NAME_AND_DRINK",
AskAndListen(
tts_phrase="Hello, please tell me your name and favorite drink."
),
transitions={"succeeded": "MATCH_NAME_AND_DRINK", "failed": "failed"},
remapping={"transcribed_speech": "sequence"},
)
smach.StateMachine.add(
"MATCH_NAME_AND_DRINK",
MatchNameAndDrink(),
transitions={"succeeded": "SAY_MATCHED_NAME_AND_DRINK", "failed": "failed"},
remapping={"sequence": "sequence"},
)
smach.StateMachine.add(
"SAY_MATCHED_NAME_AND_DRINK",
Say(),
transitions={
"succeeded": "succeeded",
"aborted": "failed",
"preempted": "failed",
},
remapping={
"text": "sequence",
},
)
sm.execute()

0 comments on commit e27d16a

Please sign in to comment.