voice: hold the wake word until the scheduler reaches a result
Gate the wake word on the scheduler's single slot being free: a wake that fires while the current request is still running is ignored (traced voice_wake_blocked), so a second command cannot start mid-run. The gate is GatewayService.input_ready (False while a run executes, True when idle or paused for the user's answer), handed to adapters via set_input_ready; the voice adapter passes it to VoiceDaemon.input_ready.
This commit is contained in:
1 parent
ff94ea938c
commit
88700898be
8 files changed
+130
-7
No files matched your search
@@ -633,11 +633,16 @@ class VoiceDaemon:
|
||||
"""
|
||||
|
||||
def __init__(self, cfg: dict | None = None, trace=None, engines: VoiceEngines | None = None,
|
||||
name: str = "voice"):
|
||||
name: str = "voice", input_ready=None):
|
||||
cfg = cfg or {}
|
||||
self.config = cfg
|
||||
self.trace = trace
|
||||
self.name = name
|
||||
#: Optional predicate: whether a new command may start now. While it
|
||||
#: returns False the wake word is ignored (the scheduler's single slot
|
||||
#: is still running the current request), so a second command cannot be
|
||||
#: started before the first reaches a result. None = always ready.
|
||||
self.input_ready = input_ready
|
||||
self.wake_threshold = float((cfg.get("wake", {}) or {}).get("threshold", 0.2))
|
||||
#: After the wake word, how long to wait for the command's speech to
|
||||
#: begin before giving up (a natural pause after "hey <word>" — e.g.
|
||||
@@ -766,6 +771,18 @@ class VoiceDaemon:
|
||||
score = engines.wake.score(pcm)
|
||||
if score < self.wake_threshold:
|
||||
continue
|
||||
if self.input_ready is not None and not self.input_ready():
|
||||
# The single scheduler slot is still running the current
|
||||
# request: hold the wake word until it reaches a result (or
|
||||
# pauses for the user's answer), so a new command cannot start
|
||||
# while one is in flight. Reset the detector so the same wake
|
||||
# phrase does not immediately re-fire once the slot frees.
|
||||
try:
|
||||
engines.wake.reset()
|
||||
except Exception:
|
||||
pass
|
||||
self._event("voice_wake_blocked", score=round(float(score), 3))
|
||||
continue
|
||||
self._event("voice_wake", score=round(float(score), 3))
|
||||
try:
|
||||
engines.wake.reset()
|
||||
|
||||
Reference in new issue
Block a user