Updates to the assistants overall abilities, like always listening, and only responding on messages when activated.

This commit is contained in:
TMN AI
2026-09-30 20:25:15 -06:00
parent 8bcd539b31
commit 34b2d302f9
10 changed files with 82 additions and 7 deletions
+19 -4
View File
@@ -12,6 +12,9 @@ Rules, all aimed at not waking up on ordinary conversation:
that bolt" and "the bolt on the door" never count.
- Whole words only: "boltage" is not "bolt".
- Longest phrase wins, so "hey thunderbolt" isn't read as "hey" + garbage.
- Except *anywhere* words ("assistant"): one of those anywhere in what was
said counts, and the whole transcript is the request ("set a timer,
assistant" asks "set a timer, assistant").
"""
from __future__ import annotations
@@ -30,10 +33,11 @@ def _words(text: str) -> list:
return [(m.group(0), m.start(), m.end()) for m in _WORD.finditer(text.lower())]
def find_wake(transcript: str, phrases: Iterable[str]) -> Tuple[bool, str]:
"""(heard, remainder): whether a wake phrase opens *transcript*, and the
request that followed it in the same breath ("" if it was just the
phrase)."""
def find_wake(transcript: str, phrases: Iterable[str],
anywhere: Iterable[str] = ()) -> Tuple[bool, str]:
"""(heard, remainder): whether a wake phrase opens *transcript* (or an
*anywhere* word appears in it), and the request that came with it in the
same breath ("" if it was just the phrase)."""
words = _words(transcript or "")
if not words:
return False, ""
@@ -47,4 +51,15 @@ def find_wake(transcript: str, phrases: Iterable[str]) -> Tuple[bool, str]:
if len(span) == len(phrase) and all(w == p for (w, _, _), p in zip(span, phrase)):
rest = transcript[span[-1][2]:]
return True, rest.lstrip(" \t,.;:!?-—").strip()
return _find_anywhere(transcript, words, anywhere)
def _find_anywhere(transcript: str, words: list, anywhere: Iterable[str]) -> Tuple[bool, str]:
said = [w for w, _, _ in words]
for phrase in {tuple(_WORD.findall(p.lower())) for p in anywhere if p.strip()}:
n = len(phrase)
if any(tuple(said[i:i + n]) == phrase for i in range(len(said) - n + 1)):
if all(w in phrase or w in _FILLER for w in said):
return True, "" # just the word on its own: wait for the request
return True, transcript.strip()
return False, ""