Improve command, cup task and talk understanding in English and Korean

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 15:30:06 +09:00
co-authored by Claude Opus 5.5
parent e3a1c123c9
commit e3fcfd30ab
23 changed files with 1380 additions and 167 deletions
+44 -9
View File
@@ -20,7 +20,10 @@ EN_NUM = {"one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven
"ten": 10, "eleven": 11, "twelve": 12}
KO_EN_NUM = {"원": 1, "투": 2, "쓰리": 3, "스리": 3, "뜨리": 3, "트리": 3, "포": 4, "파이브": 5, "화이브": 5,
"식스": 6, "씩스": 6, "세븐": 7, "쎄븐": 7, "에잇": 8, "에이트": 8, "나인": 9, "텐": 10, "일레븐": 11,
"트웰브": 12} # English numbers said in Korean ("피쓰리", "포인트 원")
"트웰브": 12, "써틴": 13, "서틴": 13, "포틴": 14, "피프틴": 15, "휘프틴": 15, "식스틴": 16, "세븐틴": 17,
"에이틴": 18, "나인틴": 19} # English numbers said in Korean ("피쓰리", "포인트 원")
KO_EN_TENS = {"트웬티": 20, "트웨니": 20, "써티": 30, "서티": 30, "포티": 40, "피프티": 50, "휘프티": 50, "식스티": 60,
"세븐티": 70, "에이티": 80, "나인티": 90} # before a unit only (numbers): "에이티 센티"
NATIVE = {"한": 1, "두": 2, "세": 3, "네": 4, "다섯": 5, "여섯": 6, "일곱": 7, "여덟": 8, "아홉": 9, "열": 10}
SINO = {"일": 1, "이": 2, "삼": 3, "사": 4, "오": 5, "육": 6, "륙": 6, "칠": 7, "팔": 8, "구": 9}
_D = "[일이삼사오육륙칠팔구]"
@@ -112,6 +115,12 @@ def markers(t):
def numbers(t):
"""Distances and angles in lower-case text -> digits and metres: "half a meter" -> "0.5 m", "오십 센치" -> "0.5 m",
"일 미터 반" -> "1.5 m", "구십 도" -> "90도"."""
t = re.sub(rf"(?<![가-힣])(?:({'|'.join(KO_EN_TENS)})\s?)?({'|'.join(sorted(KO_EN_NUM, key=len, reverse=True))})?"
rf"(?<=[가-힣])\s*(?=(?:{UNIT}|도|degrees?|디그리스?)(?![a-z가-힣]))",
lambda m: f"{KO_EN_TENS.get(m.group(1), 0) + KO_EN_NUM.get(m.group(2), 0)} "
if m.group(1) or m.group(2) else m.group(0), t)
# Konglish amounts: "텐 센치", "에이티 센티", "트웬티 파이브 도"
t = re.sub(r"(\d+)\s*디그리스?(?![가-힣])", r"\1도", t) # "피프틴 디그리"
t = re.sub(r"\bone and a half\b", "1.5", t)
t = re.sub(rf"\b({'|'.join(TENS)})(?:[ -]({'|'.join(list(EN_NUM)[:9])}))?\b",
lambda m: str(TENS[m.group(1)] + EN_NUM.get(m.group(2), 0)), t)
@@ -122,7 +131,7 @@ def numbers(t):
lambda m: str(1000 * _num(m.group(1)) if m.group(1) else 1000), t) # "a thousand", "five thousand"
t = re.sub(rf"\b([2-9]|{'|'.join(list(EN_NUM)[1:9])}) hundred(?: and)?(?: (\d+))?\b",
lambda m: str(100 * _num(m.group(1)) + int(m.group(2) or 0)), t) # "two hundred and fifty"
t = re.sub(rf"\b({'|'.join(TEEN)}|eleven|twelve)\b(?=\s*{UNIT}(?![a-z]))",
t = re.sub(rf"\b({'|'.join(TEEN)}|eleven|twelve)\b(?=\s*(?:{UNIT}(?![a-z])|degrees?\b|도(?![가-힣])))",
lambda m: str(TEEN.get(m.group(1)) or EN_NUM[m.group(1)]), t) # "fifteen centimetres"
t = re.sub(r"\b(?:a|one) hundred(?: and)? (\d+)\b", lambda m: str(100 + int(m.group(1))), t)
t = re.sub(r"\b(?:a|one) hundred\b", "100", t)
@@ -143,11 +152,16 @@ def numbers(t):
t = re.sub(rf"(?:(?<=으로)|(?<=로))\s*({_SINO})\s*도(?![가-힣])", lambda m: f" {sino(m.group(1))}도", t)
t = re.sub(rf"(?<![가-힣\d])({_SINO})\s*도(?=\s+(?:왼쪽|오른쪽|뒤로|돌))", lambda m: f"{sino(m.group(1))}도", t)
t = re.sub(r"(\d+)\s*degrees?(?=\s*[가-힣])", r"\1도", t) # "왼쪽으로 45 degrees 돌아"
t = re.sub(r"(?<![\d.])(\d+) 도(?=\s+(?:왼|오른|위|아래|밑|좌|우|뒤|돌|회전|틀|꺾))", r"\1도", t) # "고개를 90 도 오른쪽으로"
t = re.sub(rf"(?:^|(?<=으로)|(?<=[~,\s몸]))({_SINO})\s*도(?=\s*(?:왼|오른|좌|우|회전|돌|틀|꺾|만|쯤|정도|얼른|빨리|천천히|살짝|좀|퍼뜩|언능))",
lambda m: f"{sino(m.group(1))}도 ", t) # written together: "왼쪽으로십오도회전해"
t = re.sub(r"(?<![\d.])(\d+) ?(?:m|미터)\s?([1-9])0(?![\d.]|\s*(?:센|cm|밀|mm|미|m\b|도))(?=\s*(?:만|쯤|정도)?\s*(?:[가-힣]|$))",
lambda m: f"{m.group(1)}.{m.group(2)} m", t) # "1미터 50" is 1.5 m
t = re.sub(rf"\bhalf (?:a |an )?{UNIT}", "0.5 m", t)
t = re.sub(rf"반\s*{UNIT}", "0.5 m", t)
for w, d in NUM_WORDS.items():
if w.isascii():
t = re.sub(rf"\b{w}\b(?=\s*(?:{UNIT}(?![a-z])|degrees?|and a (?:half|0\.5)))", d, t) # "one meter", "a meter"
t = re.sub(rf"\b{w}\b(?=\s*(?:{UNIT}(?![a-z])|degrees?|도(?![가-힣])|and a (?:half|0\.5)))", d, t) # "one meter", "a meter"
else:
t = re.sub(rf"(?<![가-힣]){w}\s*(?={UNIT})", d + " ", t)
t = re.sub(rf"(?<![\d.])0(\d)\s*(?={UNIT}(?![a-z]))", r"0.\1 ", t) # whisper's "05 meters": 0.5 m
@@ -274,7 +288,7 @@ ASR_SLIPS = [ # how whisper writes Korean commands (tests/asr_check.py, 2026-1
(r"([a-z0-9])\.?\s+(으로|로)\s*(?=가|와|이동|돌아)", r"\1\2 "), # "P3. 로가줘", "final point. 로 가": one word
(r"(?<=로)\s*가죠(?![가-힣])", " 가 줘"), # "p3로 가 줘" written "p3로 가죠"
(r"\blook (?:last|lest|less)(?=[\s.!,]*$)", "look left"), (r"\bdoc t\b", "dock 2"), # said at the end
(r"고게(?=\s*(?:들|숙))", "고개"), (r"찝어", "집어"), (r"파이나(?=\s*(?:갔|가|로))", "파이널"),
(r"고게(?=\s*(?:들|숙)|[를는도가]?\s)", "고개"), (r"찝어", "집어"), (r"파이나(?=\s*(?:갔|가|로))", "파이널"),
# the owner's English as whisper wrote it live (logs/lumi.log 2026-10-21 / 22)
(r"\bcount to(?= p\s?\d)", "come to"), # "Let's count to p5."
# the head up / down, said or heard loosely (2026-10-23 15:08-15:16: "Look at the bellow.", "Look it up.")
@@ -296,6 +310,10 @@ ASR_SLIPS = [ # how whisper writes Korean commands (tests/asr_check.py, 2026-1
_NO = r"(?<![가-힣a-z])"
KONGLISH = [ # English direction words said in Korean -> the Korean word ("레프트로 반 미터 가 줘요", "라이트 턴 해")
(r"왼쭉|왼족", "왼쪽"), (r"멈처|멈쳐", "멈춰"), (r"슴니(?=다|까)", "습니"), (r"(?<![가-힣])야루미", "야 루미"),
(r"(?:쉐|셰)이크 ?핸즈?|핸드 ?쉐이크", "악수"), (r"(?<![가-힣])히어로(?= ?(?:와|오|가까이))", "이리로"),
(r"리프트 ?다운(?: ?(?:해|하(?:게나?|세요|십시오|시게|시오)?))?(?=\s|$|[?.!~,])", "몸 내려"),
(r"리프트 ?업(?: ?(?:해|하(?:게나?|세요|십시오|시게|시오)?))?(?=\s|$|[?.!~,])", "몸 올려"), # read by norm and ko_plain
(_NO + r"레프트\s*(?:쪽으로|으로|로|쪽)?", "왼쪽으로 "),
(_NO + r"라이트\s*(?:쪽으로|으로|로|쪽)(?![가-힣])|" + _NO + r"라이트(?=\s*(?:턴|turn|무브|move|\d|반\s*미터))",
"오른쪽으로 "), # "라이트 켜" is a light
@@ -311,6 +329,7 @@ KONGLISH = [ # English direction words said in Korean -> the Korean word ("레
(r"(고개|머리|헤드|얼굴)\s*(?:를|을)?\s*업(?![가-힣])", r"\1 들어"),
(r"(고개|머리|헤드|얼굴)\s*(?:를|을)?\s*다운(?![가-힣])", r"\1 숙여"),
(_NO + r"헤드(?=\s)", "고개"),
(_NO + r"웨이스트(?=\s|를|을|는|가)", "허리"),
]
@@ -415,8 +434,17 @@ _END_NOT_ASKED = r"(?=(?:\s+(?:빨리|얼른|어서|좀|제발|당장|지금|ple
_HON = r"(?:세요|세용|세여|십시오|시오|셔요|시죠|실래요|실래|시겠어요|시겠습니까|시겠어|시게|이소(?:마|예)?|거라|너라|렴|라고요?|랑께요?|래이|이라|쇼|시라|시지요|실래예|씨요|세예)"
_LOOK_AT = r"(왼쪽|오른쪽|위|위쪽|아래|아래쪽|뒤|뒤쪽|앞|하늘|천장|바닥|여기|이쪽|저쪽|나|날|저|정면|좌측|우측)"
KO_PLAIN = [
*((re.compile(a), b) for a, b in KONGLISH[:8]), # slips / Konglish above
(re.compile(r"(?<=[가-힣?!.~]) +(?:허허|하하|헤헤|호호|히히|ㅋ+|ㅎ+)[\s!.~]*$"), ""), # a laugh after it: "돌아 봐요 허허"
(re.compile(r"(?<![가-힣])(?:퍼뜩|퍼떡|언능|얼렁|싸게싸게)(?![가-힣])"), "빨리"), # dialect "quickly"
(re.compile(r"(?<=봐) 봐(?=\s*(?:[,.!?~…]|$))"), ""), # "돌아가 봐 봐": once
(re.compile(r"(?<=[려어아여]) (?:좀|한 ?번) (?=놔|놓|둬|두)"), " "), # "컵 내려 좀 놔 줘": a softener
(re.compile(r"(?<=[가-힣])게나(?=\s*(?:[,.!?~…]|$))"), "게"), # 하게체 "이동하게나", "주게나"
(re.compile(r"겄슈|겄어유|겠슈"), "겠어요"), (re.compile(r"(?<=[가-힣])세유(?=\s*(?:[,.!?~…]|$))"), "세요"), # 충청
(re.compile(r"(?<![가-힣])(\S*?[가-힣])(?:으)?(?:시겠어요|시겠습니까|시겠어|실래요|실래)\s*\?"), "STEMQ"),
# "회전하시겠어요?": please turn
(re.compile(r"(?<=아니 )(\S+?)(?:이요|요)(?=\s*(?:[,.!?~…]|$))"), r"\1"), # "아 아니 정면이요": the noun
(re.compile(r"오른쭉|오른족"), "오른쪽"), (re.compile(r"(?<![가-힣])외쪽"), "왼쪽"), (re.compile(r"고게(?= )"), "고개"),
(re.compile(r"오른쭉|오른족"), "오른쪽"), (re.compile(r"(?<![가-힣])외쪽"), "왼쪽"), (re.compile(r"고게(?=[를는도가]?\s)"), "고개"),
(re.compile(r"(루미야|루미씨|루미 씨)(?=[가-힣])"), r"\1 "), # "루미야오른쪽 봐"
(re.compile(r"(?<![가-힣])쫌(?![가-힣])"), "좀"), (re.compile(r"(?<![가-힣])놉여"), "높여"),
(re.compile(r"(?<= )주드라(?:고|구)|(?<= )주드랑께"), "줘"), # 전라: "와 주드라고"
@@ -429,7 +457,10 @@ KO_PLAIN = [
(re.compile(r"(\d+(?:\.\d+)?\s*(?:도|미터|센티(?:미터)?|센치|cm|m)(?![가-힣a-z]))\s+(?:좀|쫌|한번|한 번)\s+(?=[가-힣])"), r"\1 "),
# "45도 좀 돌아 줘": the amount, then the verb
(re.compile(r"(?<= )조(?:잉)?(?=\s*(?:[,.!?~…]|$))"), "줘"), # "흔들어 조잉", "손 한번 조"
(re.compile(r"악수 ?(?:한 ?번)? ?(?:할까요?|하실래요?|합시다|하십시다|하자잉|허자잉?|하입시더)"), "악수하자"), # shake hands = wave
(re.compile(r"악수 ?(?:한 ?번)? ?(?:할까요?|하실까요?|할래요?|하시죠|하시겠어요|하실래요?|합시다|하십시다|하자잉|허자잉?|하입시더|하세|허세|합세|하시게)(?![가-힣])\s*\??"),
"악수하자"), # shake hands = wave; 하게체 "악수하세"
(re.compile(r"(?<=[어아여해줘봐와가라자워려춰켜꺼놔둬]) (?:응|엉|알았지|알겠지|알았죠|알겠죠|오케이)"
r"\s*[?!.~]*(?=\s*$)"), ""), # a tag after the order: "고개 들어 응?"
(re.compile(r"(?<=[가-힣](?:라|자)) 마(?=\s*(?:[,.!?~…]|$))"), ""), # 경상: "팔 접어 봐라 마"
(re.compile(_LOOK_AT + r" ?(?:한번 )?(?:바|보게)(?= 주|\s*(?:[,.!?~]|$))"), r"\1 봐"), # whisper "왼쪽바", 하게체 "하늘보게"
(re.compile(r"(\S+) ?주면 안 (?:돼|될까|되나|되겠니|되겠어|되겠습니까)(?:요)?\s*\??" + r"(?=\s*(?:[,.!~…]|$))"), r"\1 줘?"),
@@ -473,7 +504,9 @@ def _stem_l(word):
if not j or j[2] != 8:
return None
stem = word[:-1] + _syl(j[0], j[1])
return {"드": "들", "도": "돌", "여": "열", "미": "밀", "내미": "내밀", "흔드": "흔들"}.get(stem, stem)
if stem.endswith("시") and len(stem) > 1 and stem not in ("다시",):
stem = stem[:-1].removesuffix("으") or stem # honorific: "트실 수" -> 트, "도실 수" -> 도, "집으실" -> 집
return {"드": "들", "도": "돌", "트": "틀", "여": "열", "미": "밀", "내미": "내밀", "흔드": "흔들"}.get(stem, stem)
def _can_you(m, kind):
@@ -508,12 +541,14 @@ def ko_plain(t):
for rx, to in KO_PLAIN:
if to in ("CAN_L", "CAN_N"):
t = rx.sub(lambda m: _can_you(m, to), t)
elif to == "STEM":
elif to in ("STEM", "STEMQ"):
def stem(m):
w = m.group(1)
if KO_SOCIAL_BEFORE.search(m.string[:m.start()]):
return m.group(0)
got = _stem_aform(w[:-1] if w.endswith("으") and len(w) > 1 and _jamo(w[-2]) and _jamo(w[-2])[2] else w)
if to == "STEMQ" and got:
return got + ("?" if got == "줘" else " 줘?")
return got if got else m.group(0)
t = rx.sub(stem, t)
else:
@@ -536,7 +571,7 @@ def norm(text, names=()):
"""Lower case, whisper's slips (ASR_SLIPS), Konglish directions (KONGLISH), numbers first ("point five meters" is
a distance), then marker names (names: the map's)."""
t = " " + (text or "").lower().replace("’", "'") + " "
t = re.sub(r"(\S+)[—–-]+\s*(?=\1)", "", t) # a stutter: "육십 센— 센티", "go ah— ahead"
t = re.sub(r"(?<!\S)(\S+)[—–-]+\s*(?=\1)", "", t) # a stutter: "육십 센— 센티", "go ah— ahead"
t = re.sub(r"(?<=[가-힣])(?=\d+(?:\.\d+)?\s*(?:미터|센티|센치|cm|m\b|도))", " ", t) # "오른쪽으로80센티미터"
for slip, said in ASR_SLIPS + KONGLISH:
t = re.sub(slip, said, t)