Skip to content

Commit

Permalink
Apply black
Browse files Browse the repository at this point in the history
  • Loading branch information
LoyVanBeek committed May 7, 2022
1 parent 63a33af commit d8d9d1b
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/hmi_picovoice/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,33 @@


class Server(AbstractHMIServer):
def __init__(self, name: str, context_url: str, require_endpoint: bool, rate: float):
def __init__(
self, name: str, context_url: str, require_endpoint: bool, rate: float
):
super(Server, self).__init__(name)

self._context_url = context_url
self._require_endpoint = require_endpoint
self._rate = rate

self._intent_client = actionlib.SimpleActionClient("get_intent", GetIntentAction)
self._intent_client = actionlib.SimpleActionClient(
"get_intent", GetIntentAction
)
rospy.loginfo(f"Waiting for {self._intent_client.action_client.ns} ..")
self._intent_client.wait_for_server()

rospy.loginfo(f"Server initialized (context_url={context_url}, require_endpoint={require_endpoint})")
rospy.loginfo(
f"Server initialized (context_url={context_url}, require_endpoint={require_endpoint})"
)

def _determine_answer(self, description, grammar, target, is_preempt_requested):
self._intent_client.send_goal(GetIntentGoal(
context_url=self._context_url,
require_endpoint=self._require_endpoint,
intents=[grammar]
))
self._intent_client.send_goal(
GetIntentGoal(
context_url=self._context_url,
require_endpoint=self._require_endpoint,
intents=[grammar],
)
)

r = rospy.Rate(self._rate)
while not rospy.is_shutdown():
Expand All @@ -41,9 +49,13 @@ def _determine_answer(self, description, grammar, target, is_preempt_requested):

result = self._intent_client.get_result()
if result is not None:
return HMIResult(
semantics={kv.key: kv.value for kv in result.slots},
sentence=result.intent
) if result.is_understood else None
return (
HMIResult(
semantics={kv.key: kv.value for kv in result.slots},
sentence=result.intent,
)
if result.is_understood
else None
)

r.sleep()

0 comments on commit d8d9d1b

Please sign in to comment.