Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/get_response_dynamic_timeout #211

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1855,17 +1855,35 @@ def __get_response(self, session: Session):
LOG.debug(f"get_response session: {session.session_id}")
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 ans:
timeout = self.config_core.get("skills", {}).get("get_response_timeout", 20)

def on_extension(msg):
nonlocal start
s = SessionManager.get(msg)
if s.session_id == session.session_id:
# this helps with slower voice satellites or in cases of very long responses
LOG.debug(f"Extending get_response wait time: {msg.msg_type}")
start = time.time() # reset timer

# if we have indications listener is busy, we allow extra time
self.bus.on("recognizer_loop:record_begin", on_extension)
self.bus.on("recognizer_loop:record_end", on_extension)

while time.time() - start <= timeout and not ans:
ans = self.__responses[session.session_id]
# 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
# a busy loop is needed to be able to raise an exception
time.sleep(0.1)
if ans is None:
# aborted externally (if None)
self.log.debug("get_response aborted")
break

self.bus.remove("recognizer_loop:record_begin", on_extension)
self.bus.remove("recognizer_loop:record_end", on_extension)
return ans

def get_response(self, dialog: str = '', data: Optional[dict] = None,
Expand Down
Loading