Follow me: steady 10 Hz control with prediction between sightings, one kept-open base connection, head tracks on its own thread, the followed person kept by position and clothes; Lumi: no fate error, cut-off sentences joined, no promise without its action, song bank only on song words

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 15:23:57 +09:00
co-authored by Claude Opus 5.5
parent 08e748e5ed
commit 4ab14b3af3
12 changed files with 450 additions and 125 deletions
+20 -4
View File
@@ -50,12 +50,14 @@ def ensure_stt_server():
raise RuntimeError("whisper-server did not start, see whisper_server.log")
def record(wait_s=8.0, on_start=None, abort=None):
def record(wait_s=8.0, on_start=None, abort=None, since=None):
"""Wait up to wait_s for speech to start, then until it ends. Returns a mic.Utterance or None.
abort: optional function checked every 30 ms; when it returns True, stop and return None."""
abort: optional function checked every 30 ms; when it returns True, stop and return None.
since: take speech that ended after this time, also one already heard (the rest of a sentence)."""
m = mic.get()
m.clear() # only speech that starts from now on
t0, started = time.time(), False
if since is None:
m.clear() # only speech that starts from now on
t0, started = since or time.time(), False
try:
while True:
if abort and abort():
@@ -121,6 +123,12 @@ NOT_SAID = re.compile(r"^\W*$|^\s*-|자막|시청해\s*주셔서|thanks? (?:you
# whisper's subtitle habits on music: no word at all, a dialogue dash ("-끝-", "- 네."),
# a caption credit ("자막 제공 및 광고를 포함하고 있습니다.")
_vad = {}
CUT_OFF = re.compile(r"(?:\b(?:let'?s|can you|could you|would you|will you|can i|and|but|or|the|a|an|to|of|with|"
r"my|your|i want|i'd like|i need)|(?<![가-힣])(?:저기|그리고|근데|혹시|그래서|그러니까|있잖아))\W*$", re.I)
# a sentence cut off by a pause longer than mic.END_SILENCE ("Let's" of "Let's ...
# follow me", 2026-10-22 14:36; today's clips: the longest pause inside an utterance
# 0.39 s at the 90th percentile, 0.51 s at most, so one cut in 140 turns)
MERGE_WAIT_S = 1.5 # s waited for the rest of a cut-off sentence; it is heard with the first part
BEAM_SIZE = 0 # whisper beam search width (0: the server's greedy decoding)
HEARD_DIR = ROOT / "logs" / "heard" # the last HEARD_KEEP utterances as wav, to check what Lumi really heard
@@ -288,6 +296,14 @@ def listen(wait_s=8.0, on_start=None, abort=None, full=False):
if u is None or u.seconds < 0.4:
return (None, u) if full else None
text = transcribe(u.mono) or None
if text and CUT_OFF.search(text): # "Let's" ... "follow me": the rest after a pause, heard as one
rest = record(MERGE_WAIT_S, abort=abort, since=u.t_end)
if rest is not None and rest.seconds >= 0.3:
import numpy as np
joined = np.concatenate([u.mono, np.zeros(int(0.3 * RATE), np.int16), rest.mono])
text2 = transcribe(joined)
if text2:
text, u.mono, u.t_end = text2, joined, rest.t_end
return (text, u) if full else text
+8 -3
View File
@@ -49,6 +49,9 @@ LATE_S = 0.4 # s; a move this late is skipped (the previous o
RETURN_WAIT_S = 3.0 # s a new song waits for the head to get back from the last one
BANK_SIM = 0.80 # song bank (assistant/song_bank.py): the closest wording at least this similar ...
BANK_MARGIN = 0.05 # ... and this much closer than the closest wording of another kind
BANK_MIN_WORDS = 3 # the bank reads only words with a song or music word in them and at least this many
# words ("Let's", cut off from "Let's follow me", sang once, 2026-10-22)
SONG_WORD = re.compile(r"\bsing|\bsong|\bmusic|\btunes?\b|\bplaylist|k-?pop|노래|노레|노랠|음악|곡|불러|부르|틀어|들려|케이팝", re.I)
SING = re.compile(r"\bsing\b|\bsay (?:a |some )?songs?\b|" # whisper writes "let's say song"
r"\b(?:play|put on|turn on|start)(?: me| us)? (?:a |some |any |another |the |your )?(?:songs?|music|tunes?)\b|"
@@ -144,13 +147,15 @@ _bank = None
def bank_read(text, last=""):
"""'sing' / 'list' when these words mean the same as the bank's wordings of that kind (bge-m3 through
assistant/knowledge.embed, ~20 ms), else None (the LLM decides; also when the closest are the bank's
near misses, and for a 'sing' with any word that might be a title: "jingle bells please"). Negation, a condition or a later time, the
near misses, and for a 'sing' with any word that might be a title: "jingle bells please"). Only words with a song
or music word and BANK_MIN_WORDS words are read: a cut-off start ("Let's", "can you", "루미야 저기") never sings. Negation, a condition or a later time, the
person singing, a question about liking music or "is / does ...?", and any words with a turn before them (the
talk decides what "yes" means) are never read here."""
global _bank
t = text or ""
if NOT_REQUEST.search(t) or NOT_ASKED.search(t) or re.match(r"\W*(?:is|are|was|were|does|did|has|have)\b", t, re.I) \
or re.search(r"\b(?:like|love|enjoy|favou?rite)\b|좋아|싫어", t, re.I) and re.search(r"\?|까요?\W*$|니\W*$", t) or last:
if not SONG_WORD.search(t) or len(re.findall(r"\w+", t)) < BANK_MIN_WORDS or NOT_REQUEST.search(t) or \
NOT_ASKED.search(t) or re.match(r"\W*(?:is|are|was|were|does|did|has|have)\b", t, re.I) or \
re.search(r"\b(?:like|love|enjoy|favou?rite)\b|좋아|싫어", t, re.I) and re.search(r"\?|까요?\W*$|니\W*$", t) or last:
return None
from assistant import knowledge, song_bank
try: