Rules: one guard for what is not an order; own voice in the clip mic dropped; whisper slips of places and amounts read right

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 01:03:06 +09:00
co-authored by Claude Opus 5.5
parent 2aa68eba00
commit 840f80fb39
11 changed files with 674 additions and 71 deletions
+115
View File
@@ -0,0 +1,115 @@
"""Spoken cases, set 5 (hearing round 2, 2026-10-22 night): short commands, numbers with units, and marker names
on several maps (tests/blind/maps.py), English, Korean and mixed. Format of tests/asr_cases.py plus "markers" (the
map the case is read against).
.venv/bin/python tests/asr_check.py --cases 5 [--session]
"""
from tests.blind.maps import MAPS
CASES = []
OFFICE = MAPS["office"]
def add(lang, text, say=None, kind="command", markers=OFFICE):
"""say: the words as spoken (numbers in words), in the case's language; mixed: [(lang, words), ...]."""
if isinstance(say, list):
pieces = say
else:
pieces = [("ko" if lang == "ko" else "en", say or text)]
CASES.append({"kind": kind, "lang": lang, "text": text, "say": pieces, "markers": markers})
# ---- short commands, said alone
for t in ["Stop.", "Stop!", "Stop it.", "Wait.", "Wait a second.", "Wave.", "Wave to me.", "Hand.", "Your hand.",
"Come.", "Come here.", "Follow me.", "Here.", "Over here.", "Come back.", "Look back.", "Look behind you.",
"Look up.", "Look down.", "Look left.", "Look right.", "Look at me.", "Turn left.", "Turn right.",
"Turn around.", "Go home.", "Sing.", "Sing a song.", "Louder.", "Quieter.", "Speak slower.", "Open your hand.",
"Close your hand.", "Give it to me.", "Take it.", "Put it down.", "Go back.", "Move forward.", "Back up.",
"Lift up.", "Go down.", "Higher.", "Lower.", "Be quiet.", "What time is it?", "How's the weather?",
"Battery?", "Again.", "One more time.", "A bit more.", "Okay.", "Thanks.", "Bye.", "Never mind.",
"Hold on.", "Freeze.", "Halt.", "Enough."]:
add("en", t, kind="short")
for t, say in [("멈춰", None), ("멈춰!", None), ("그만", None), ("그만해", None), ("정지", None), ("스톱", None),
("잠깐", None), ("잠깐만", None), ("손 흔들어", None), ("손 흔들어 줘", None), ("손", None), ("손 줘", None),
("따라와", None), ("나 따라와", None), ("이리 와", None), ("와", None), ("여기", None), ("여기로", None),
("돌아와", None), ("뒤 봐", None), ("뒤 돌아봐", None), ("고개 들어", None), ("고개 숙여", None),
("위 봐", None), ("아래 봐", None), ("왼쪽 봐", None), ("오른쪽 봐", None), ("나 봐", None),
("왼쪽으로 돌아", None), ("오른쪽으로 돌아", None), ("뒤로 돌아", None), ("집에 가", None),
("홈으로 가", None), ("노래해", None), ("노래 불러 줘", None), ("크게 말해", None), ("작게 말해", None),
("천천히 말해", None), ("손 펴", None), ("손 쥐어", None), ("줘", None), ("이거 받아", None),
("내려놔", None), ("뒤로 가", None), ("앞으로 가", None), ("올라가", None), ("내려가", None),
("조용히 해", None), ("몇 시야?", None), ("날씨 어때?", None), ("배터리 얼마야?", None), ("한 번 더", None),
("조금 더", None), ("다시", None), ("고마워", None), ("잘 가", None), ("됐어", None), ("괜찮아", None)]:
add("ko", t, say, kind="short")
# ---- numbers with units (said in words)
EN_MOVES = [("Go forward 1 meter.", "Go forward one meter."), ("Move back half a meter.", None),
("Go forward 50 centimeters.", "Go forward fifty centimeters."), ("Move back 30 centimeters.", "Move back thirty centimeters."),
("Go forward 2 meters.", "Go forward two meters."), ("Go back 1.5 meters.", "Go back one and a half meters."),
("Move left 20 centimeters.", "Move left twenty centimeters."), ("Move right 1 meter.", "Move right one meter."),
("Turn left 30 degrees.", "Turn left thirty degrees."), ("Turn right 90 degrees.", "Turn right ninety degrees."),
("Turn left 45 degrees.", "Turn left forty five degrees."), ("Turn right 180 degrees.", "Turn right one hundred eighty degrees."),
("Turn 60 degrees to the left.", "Turn sixty degrees to the left."), ("Forward 1 meter.", "Forward one meter."),
("Back 50 centimeters.", "Back fifty centimeters."), ("Go 3 meters forward.", "Go three meters forward."),
("Lift up 5 centimeters.", "Lift up five centimeters."), ("Lower 10 centimeters.", "Lower ten centimeters.")]
for t, say in EN_MOVES:
add("en", t, say)
KO_MOVES = [("1미터 앞으로 가", "일 미터 앞으로 가"), ("반 미터 뒤로 가", None), ("50센티 앞으로", "오십 센티 앞으로"),
("30센티 뒤로", "삼십 센티 뒤로"), ("2미터 앞으로 가 줘", "이 미터 앞으로 가 줘"),
("1미터 50센티 뒤로 가", "일 미터 오십 센티 뒤로 가"), ("왼쪽으로 20센티 가", "왼쪽으로 이십 센티 가"),
("오른쪽으로 1미터 가", "오른쪽으로 일 미터 가"), ("왼쪽으로 30도 돌아", "왼쪽으로 삼십 도 돌아"),
("오른쪽으로 90도 돌아", "오른쪽으로 구십 도 돌아"), ("45도 왼쪽으로 돌아", "사십오 도 왼쪽으로 돌아"),
("180도 돌아", "백팔십 도 돌아"), ("30도 오른쪽", "삼십 도 오른쪽"), ("1미터", "일 미터"),
("반 미터", None), ("50센티", "오십 센티"), ("30도", "삼십 도"), ("앞으로 3미터", "앞으로 삼 미터"),
("5센티 올려", "오 센티 올려"), ("10센티 내려", "십 센티 내려"), ("한 걸음 앞으로", None),
("1미터만 와", "일 미터만 와")]
for t, say in KO_MOVES:
add("ko", t, say)
for t, say in [("1미터 forward", [("ko", "일 미터"), ("en", "forward")]),
("turn left 30도", [("en", "turn left"), ("ko", "삼십 도")]),
("50센티 back", [("ko", "오십 센티"), ("en", "back")]),
("go 1미터 앞으로", [("en", "go"), ("ko", "일 미터 앞으로")])]:
add("mix", t, say)
# ---- marker names on several maps
CONF = MAPS["conference"]
for t, say in [("Go to the Main Stage.", None), ("Take me to Booth 12.", "Take me to booth twelve."),
("Go to Registration.", None), ("Go to the photo zone.", None), ("Go to the lounge.", None),
("Go to the Coffee Bar.", None), ("Go to Exit B.", None), ("Main Stage, please.", None),
("Booth 12.", "Booth twelve."), ("Coffee Bar.", None), ("Lumi, go to the main stage.", None),
("Bring me to registration.", None), ("Go home.", None), ("Go to dock 2 and charge.", "Go to dock two and charge.")]:
add("en", t, say, markers=CONF)
for t, say in [("메인 스테이지로 가", None), ("부스 12로 가", "부스 십이로 가"), ("부스 12로 가 줘", "부스 열둘로 가 줘"),
("레지스트레이션으로 가", None), ("포토존으로 가", None), ("포토존 가자", None), ("라운지로 가", None),
("라운지로 데려다 줘", None), ("커피 바로 가", None), ("커피바로 가 줘", None), ("엑시트 비로 가", None),
("포토존", None), ("라운지", None), ("메인 스테이지", None), ("홈으로 가", None), ("도크 투로 가서 충전해", None)]:
add("ko", t, say, markers=CONF)
for t, say in [("Main Stage로 가", [("en", "Main Stage"), ("ko", "로 가")]),
("Booth 12로 가 줘", [("en", "Booth twelve"), ("ko", "로 가 줘")]),
("Coffee Bar로 가", [("en", "Coffee Bar"), ("ko", "로 가")]),
("go to 포토존", [("en", "go to"), ("ko", "포토존")]),
("go to 라운지", [("en", "go to"), ("ko", "라운지")])]:
add("mix", t, say, markers=CONF)
KOREAN_MAP = MAPS["korean"]
for t, say in [("커피코너로 가", None), ("부스3으로 가", "부스 삼으로 가"), ("입구로 가", None), ("무대로 가", None),
("안내데스크로 가", None), ("휴게실로 가", None), ("회의실로 가 줘", None), ("커피코너", None)]:
add("ko", t, say, markers=KOREAN_MAP)
for t, say in [("Go to the 커피코너.", [("en", "Go to the"), ("ko", "커피코너")]),
("Take me to 회의실.", [("en", "Take me to"), ("ko", "회의실")])]:
add("mix", t, say, markers=KOREAN_MAP)
EXPO, HALL = MAPS["expo"], MAPS["hall"]
for t, say, m in [("Go to booth A.", None, EXPO), ("Go to booth 3.", "Go to booth three.", EXPO),
("Go to the entrance.", None, EXPO), ("Go to the info desk.", None, EXPO),
("Go to the coffee corner.", None, EXPO), ("Go to gate 1.", "Go to gate one.", HALL),
("Go to gate 2.", "Go to gate two.", HALL), ("Go to hall A.", None, HALL),
("Go to the photo zone.", None, HALL), ("Go to the table front.", None, HALL)]:
add("en", t, say, markers=m)
for t, say, m in [("부스 에이로 가", None, EXPO), ("부스 쓰리로 가", None, EXPO), ("인포 데스크로 가", None, EXPO),
("커피 코너로 가", None, EXPO), ("게이트 원으로 가", None, HALL), ("게이트 투로 가", None, HALL),
("홀 에이로 가", None, HALL), ("포토 존으로 가", None, HALL)]:
add("ko", t, say, markers=m)
for n, ko in [(1, "일"), (3, "삼"), (5, "오"), (7, "칠"), (9, "구"), (10, "십")]:
add("ko", f"p{n}로 가", f"피 {ko}로 가")
add("en", f"Go to p{n}.", f"Go to p {['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'][n - 1]}.")
for t, say in [("p3로 가 줘", "피쓰리로 가 줘"), ("p5", "피 파이브"), ("p8로", "피 에잇으로"), ("p2", "피 이")]:
add("ko", t, say)
+31 -2
View File
@@ -7,11 +7,13 @@ microphones, sent through ears.transcribe() exactly as Lumi does, then through L
.venv/bin/python tests/asr_check.py --cases 2 # the second set (tests/asr_cases2.py)
.venv/bin/python tests/asr_check.py --cases 3 # noise and talk not to Lumi (tests/asr_cases3.py)
.venv/bin/python tests/asr_check.py --cases 4 # music only, and speech over soft music (tests/asr_cases4.py)
.venv/bin/python tests/asr_check.py --cases 5 # short commands, numbers with units, marker names (asr_cases5.py)
.venv/bin/python tests/asr_check.py --cases tests/blind/train/hearing.py # any file with CASES (own markers)
.venv/bin/python tests/asr_check.py --trim 0.3 # the audio without its last 0.3 s (early transcription)
.venv/bin/python tests/asr_check.py --no-vad # without the speech detector and the subtitle-text filter
.venv/bin/python tests/asr_check.py --heard # also the real clips in logs/heard/ (text only, no judgement)
.venv/bin/python tests/asr_check.py --set LANG_RETRY=False --tag before # an ears constant; -> logs/asr_check_before.md
.venv/bin/python tests/asr_check.py --memo # whisper's answers kept (logs/asr_check/memo.jsonl), re-runs fast
Needs a whisper-server; the check starts its own on STT_PORT (never the live one on 8096, which Lumi uses).
A case is right when the text routes as the written text does (tests/command_check.rules: the same motion, or both
@@ -37,7 +39,7 @@ from audio import ears
from tests.asr_cases import CASES
from tests.asr_cases2 import CASES as CASES2
from tests.asr_cases3 import CASES as CASES3
from tests import asr_cases4
from tests import asr_cases4, asr_cases5
from tests.command_check import rules
ROOT = pathlib.Path(__file__).resolve().parents[1]
@@ -190,10 +192,12 @@ def main(args):
global STT_PORT
STT_PORT = int(args[args.index("--port") + 1])
start_server()
if "--memo" in args:
memo()
rng = np.random.default_rng(5)
rows, t0 = [], time.time()
which = args[args.index("--cases") + 1] if "--cases" in args else "1"
pool = {"1": CASES, "2": CASES2, "3": CASES3, "4": asr_cases4.CASES}.get(which) or load(which)
pool = {"1": CASES, "2": CASES2, "3": CASES3, "4": asr_cases4.CASES, "5": asr_cases5.CASES}.get(which) or load(which)
trim = int(float(args[args.index("--trim") + 1]) * ears.RATE) if "--trim" in args else 0
cases = [c for c in pool if not only or re.search(only, c["text"])]
for i, c in enumerate(cases):
@@ -223,6 +227,31 @@ def main(args):
report(rows, time.time() - t0, ROOT / "logs" / f"{name}.md")
def memo():
"""Every whisper call kept in logs/asr_check/memo.jsonl by its audio and arguments: a re-run with other choices in
ears asks whisper only for what it never heard (and gets the same answer, no sampling noise between runs)."""
f = OUT / "memo.jsonl"
seen = {}
if f.exists():
for line in f.open():
try:
k, v = json.loads(line)
seen[k] = tuple(v)
except ValueError: # a line cut by another process
pass
infer = ears._infer
def cached(wav, prompt, language=None, **kw):
k = hashlib.md5(wav).hexdigest() + json.dumps([prompt, language, ears.BEAM_SIZE, sorted(kw.items())],
ensure_ascii=False)
if k not in seen:
seen[k] = infer(wav, prompt, language, **kw)
with f.open("a") as out:
out.write(json.dumps([k, seen[k]], ensure_ascii=False) + "\n")
return seen[k]
ears._infer = cached
def load(path):
"""CASES of any case file (tests/blind/...: the same format, places with their own markers)."""
import importlib.util
+111
View File
@@ -0,0 +1,111 @@
"""Lumi's own voice in the clip mic (audio/mouth.py echo()): what the speaker played against what the mic heard.
.venv/bin/python tests/echo_check.py # made cases, and the real clips in logs/asr_real/ when there
Made cases: Lumi's lines (TTS voice F1) through a room as the clip mic hears the speaker (echo, noise, 0-0.8 s late,
the utterance a part of the sentence) must score >= mouth.ECHO_MIN; a visitor (other voices) close to the clip mic
while Lumi talks in the background (12-20 dB lower), also saying Lumi's own words, must score below it. Real: the
owner's clips against Lumi's lines (low), and the clips that were Lumi's own voice live (2026-10-22 18:25, 18:49)
against the line Lumi said then. The TTS samples differ each time it is made (a made line against itself made
again: 0.4-0.6 instead of 0.8), so the real own-voice scores here are lower than live, where mouth keeps the samples
it played: only the made cases decide ECHO_MIN; the live log's "own voice" lines show the real scores.
"""
import wave
from pathlib import Path
import numpy as np
from audio import mouth
from tests.asr_check import synth, room
ROOT = Path(__file__).resolve().parents[1]
RATE = 16000
LINES = ["I can see you through my cameras and sensors to make sure I navigate around you safely.",
"Your right hand is still empty.", "Okay, I'm looking to the left.",
"It is mainly clear right now with a temperature of 23 degrees, but you should be prepared for rain later.",
"네, 충전소로 갈게요. 잠시만 기다려 주세요.", "저는 커피를 직접 만들 수는 없지만, 커피 바까지 안내해 드릴 수 있어요."]
VISITOR = [("en", "Stop, please stop."), ("en", "Can you see me?"), ("en", "What is in my hand?"),
("ko", "잠깐만, 그만해."), ("ko", "루미야, 이리 와."), ("en", "Let's follow me.")]
ARM = "My arm is in a position I don't know, so I won't move it."
OWN_REAL = {"1022/182501": ARM, # heard "I am dumb, so I won't move it."
"1022/182504": "Please bring it near its look pose by hand.", # "It's bringing your insulin to the hand."
"1022/182519": ARM, # "I won't move it."
"184903": "Your right hand is still empty."} # "It's still empty." (logs/heard)
NEAR_SPEAKER = dict(rt60=0.35, snr=20, peak=0.2, babble=False) # the speaker ~1 m from the clip mic
def lumi(text, speed=0.92):
return synth([("ko" if any("가" <= ch <= "힣" for ch in text) else "en", text)], "F1", speed)
def score(mic, played, lag):
"""echo() with `played` started `lag` s before the mic heard it, the mic's audio ending now."""
mouth._played.clear()
end = 1000.0
start_mic = end - len(mic) / RATE
mouth._played.append([start_mic - lag, start_mic - lag + len(played) / RATE, played.astype(np.float32)])
return mouth.echo(mic, end)
def made():
rng = np.random.default_rng(3)
own, other = [], []
for i, text in enumerate(LINES):
x = lumi(text)
for k in range(4):
lag = rng.uniform(0.0, 0.8)
a = int(rng.uniform(0, 0.5) * len(x))
part = x[a:a + int(rng.uniform(1.2, 4.0) * RATE)] # the part the mic cut as one utterance
heard = room(part, NEAR_SPEAKER, rng)
# the mic hears part (from sample a) lag s after it played: played started (a/RATE + lag) s before
own.append(score(heard, x, a / RATE + lag - 0.3)) # room() puts 0.3 s before it
assert score(heard, x, a / RATE + len(x) / RATE + 2) is None # said after Lumi stopped: not judged
lang, words = VISITOR[(i + k) % len(VISITOR)]
v = synth([(lang, words)], ["M2", "F3", "M4", "F5"][k], 1.0)
for same in (False, True):
if same: # the visitor says Lumi's own words
v = synth([("ko" if any("가" <= ch <= "힣" for ch in text) else "en", text)], "M3", 1.0)[:len(part)]
bg = room(part[:len(v)], NEAR_SPEAKER, rng).astype(np.float32)
db = rng.uniform(12, 20)
n = min(len(v), len(bg))
vv, bg = v[:n] * 32767 * 0.3, bg[:n]
mix = vv + bg * np.sqrt(np.mean(vv ** 2) / (np.mean(bg ** 2) + 1e-9)) / 10 ** (db / 20)
mix = np.concatenate([np.zeros(int(0.3 * RATE)), mix, np.zeros(int(0.3 * RATE))])
other.append(score(mix.astype(np.int16), x, a / RATE + lag - 0.3))
return own, other
def clip(name):
f = ROOT / "logs" / "asr_real" / f"{name}.wav"
f = f if f.exists() else ROOT / "logs" / "heard" / f"{name}.wav"
if not f.exists():
return None
with wave.open(str(f)) as w:
return np.frombuffer(w.readframes(w.getnframes()), np.int16)
def best(mic, played):
"""The best echo() over every lag (the real clips' play times are not known): harder for the visitor clips."""
return max(score(mic, played, lag) or 0.0 for lag in np.arange(-len(mic) / RATE, len(played) / RATE, 1.0))
def real():
from tests.asr_live import REAL
own = {n: best(clip(n), lumi(t)) for n, t in OWN_REAL.items() if clip(n) is not None}
visitor = {n: max(best(clip("1022/" + n), lumi(t)) for t in set(OWN_REAL.values()) | {LINES[0]})
for n, said in REAL.items() if said and clip("1022/" + n) is not None}
return own, visitor
if __name__ == "__main__":
own, other = made()
print(f"made: own voice {len(own)}: min {min(own):.2f}, median {np.median(own):.2f}; "
f"visitor over Lumi {len(other)}: max {max(other):.2f}, median {np.median(other):.2f}")
print(f" own below {mouth.ECHO_MIN}: {sum(s < mouth.ECHO_MIN for s in own)}, visitor at or above: "
f"{sum(s >= mouth.ECHO_MIN for s in other)}")
assert min(own) >= mouth.ECHO_MIN > max(other)
own_r, vis_r = real()
if own_r:
print("real own voice:", {k: round(v, 2) for k, v in own_r.items()})
print(f"real visitor clips {len(vis_r)}: max {max(vis_r.values()):.2f}, at or above {mouth.ECHO_MIN}: "
f"{[k for k, v in vis_r.items() if v >= mouth.ECHO_MIN]}")
+29 -1
View File
@@ -25,4 +25,32 @@ assert llm_direct.render([{"role": "system", "content": "S"}, {"role": "user", "
# a prefill (system + turns) is the start of the next prompt, so the runner's cache holds it
start = [{"role": "system", "content": "S"}, {"role": "user", "content": "Q"}, {"role": "assistant", "content": "A"}]
assert llm_direct.render(start + [{"role": "user", "content": "Q2"}]).startswith(llm_direct.render(start, reply=False))
print(f"ok: {len(CUTS)} cuts, the prompt, the prefill")
# Lumi's own voice in the clip mic (mouth.echo): what the speaker played 0.4 s earlier, quieter, with noise -> high; a
# visitor's sound over it -> low; a sound after Lumi stopped -> no judgement. Speech-like test sounds: noise with a
# syllable-rate envelope in each of four bands (tests/echo_check.py uses real TTS)
import numpy as np # noqa: E402
rng = np.random.default_rng(0)
def voice(seconds):
n = int(seconds * 16000)
out = np.zeros(n, np.float32)
for lo, hi in [(200, 600), (600, 1200), (1200, 2400), (2400, 4000)]:
spec = np.fft.rfft(rng.standard_normal(n))
f = np.fft.rfftfreq(n, 1 / 16000)
spec[(f < lo) | (f > hi)] = 0
env = np.repeat(rng.uniform(0, 1, n // 1600 + 1) ** 2, 1600)[:n] # a new level every 0.1 s
out += np.fft.irfft(spec, n).astype(np.float32) * env
return out / np.abs(out).max() * 0.5
played, other = voice(3.0), voice(2.0)
mouth._played.clear()
mouth._played.append([100.0, 103.0, played]) # played from t = 100 s to 103 s
heard = played[8000:40000] * 0.3 + rng.standard_normal(32000).astype(np.float32) * 0.005 # 0.5-2.5 s of it, 0.4 s late
assert mouth.echo((heard * 32767).astype(np.int16), 102.9) >= mouth.ECHO_MIN
visitor = other * 0.5 + played[8000:40000] * 0.05 # a visitor close to the mic, Lumi 20 dB lower
assert mouth.echo((visitor * 32767).astype(np.int16), 102.9) < mouth.ECHO_MIN
assert mouth.echo((heard * 32767).astype(np.int16), 106.0) is None # said 1 s after Lumi stopped
print(f"ok: {len(CUTS)} cuts, the prompt, the prefill, own voice")