Skip to content

Commit

Permalink
feat/get_response_dynamic_timeout (#211)
Browse files Browse the repository at this point in the history
* fix/slow_get_response

ensure get_response doesnt timeout if we have indication the listener is still recording

extend default timeout to 20

this gives a larger time window for users to react to prompts from OVOS

* configurable timeout
  • Loading branch information
JarbasAl authored Jun 20, 2024
1 parent a15d282 commit 6db1d84
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1867,17 +1867,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

0 comments on commit 6db1d84

Please sign in to comment.