Skip to content

Commit

Permalink
__get_response_v1
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Oct 2, 2023
1 parent 7480a96 commit 2a0c79b
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ def play_audio(self, filename: str, instant: bool = False):
self.bus.emit(message.forward("mycroft.audio.queue",
{"uri": filename}))

def __get_response_v1(self):
def __get_response_v1(self, session=None):
"""Helper to get a response from the user
NOTE: There is a race condition here. There is a small amount of
Expand All @@ -1511,13 +1511,10 @@ def __get_response_v1(self):
Returns:
str: user's response or None on a timeout
"""
srcm = dig_for_message() or Message("", context={"source": "skills",
"skill_id": self.skill_id})
self.bus.emit(srcm.forward("skill.converse.get_response.enable",
{"skill_id": self.skill_id}))
session = session or SessionManager.get()

# TODO: Support `message` signature like default?
def converse(utterances, lang=None):
self.__responses[session.session_id] = utterances
converse.response = utterances[0] if utterances else None
converse.finished = True
return True
Expand All @@ -1529,23 +1526,22 @@ def converse(utterances, lang=None):
self.converse = converse

# 10 for listener, 5 for SST, then timeout
ans = []
# NOTE: a threading.Event is not used otherwise we can't raise the
# AbortEvent exception to kill the thread
# this is for compat with killable_intents decorators
start = time.time()
while time.time() - start <= 15 and not converse.finished:
# TODO: Refactor to event-based handling
while time.time() - start <= 15 and not ans:
ans = self.__responses[session.session_id]
time.sleep(0.1)
if self.__response is not False:
if self.__response is None:
# aborted externally (if None)
self.log.debug("get_response aborted")
if ans is None:
# aborted externally (if None)
self.log.debug("get_response aborted")
converse.finished = True
converse.response = self.__response # external override
break

self.converse = self._original_converse
self.bus.emit(srcm.forward("skill.converse.get_response.disable",
{"skill_id": self.skill_id}))
return converse.response
return ans

def __handle_get_response(self, message):

Expand Down Expand Up @@ -1691,7 +1687,8 @@ def _wait_response(self, is_cancel: callable, validator: callable,
if ans or ans is None: # canceled response
break

self.__responses.pop(session.session_id)
if session.session_id in self.__responses:
self.__responses.pop(session.session_id)

if isinstance(ans, list):
ans = ans[0] # TODO handle multiple transcriptions
Expand Down

0 comments on commit 2a0c79b

Please sign in to comment.