From 8cab4fd45bb108ddf045d9ec598aa2533f64f0e8 Mon Sep 17 00:00:00 2001 From: kim Date: Sat, 31 Oct 2026 00:05:06 +0900 Subject: [PATCH] =?UTF-8?q?=EB=82=AD=EB=8F=85:=20=EC=97=B0=EB=8F=84=20?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EC=8A=AC=EB=9E=98=EC=8B=9C=20=EB=82=A0?= =?UTF-8?q?=EC=A7=9C(10/30,=2011/2~11/8)=EB=A5=BC=20"M=EC=9B=94=20D?= =?UTF-8?q?=EC=9D=BC"=EB=A1=9C=20=E2=80=94=20"=EC=8B=AD=20=EC=82=BC?= =?UTF-8?q?=EC=8B=AD=20=ED=86=A0=EC=9A=94=EC=9D=BC"=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 답변에 "내일(10/30)", "11/2 월요일", "11/3~4"처럼 연도 없는 슬래시 날짜가 자주 나오는데, sanitizeForSpeech는 연도가 붙은 날짜만 월·일로 바꿔서 숫자만 한글로 풀려 월·일이 통째로 빠졌다(엔진 문제가 아니라 규칙 누락). - speech-dates.js(신규): 월≤12·일≤31이고 (앞수>뒷수 | 뒷수>12 | 뒤에 요일 | 앞에 오늘·내일·기준·발표 등 말머리)일 때만 날짜로 본다. 분수(1/2·3/4)·24/7·단위(m/s)는 보존. 점 표기(10.30)는 바로 뒤에 요일이 있을 때만. 범위(11/2~11/8, 11/3~4, 10/30(토)~10/31(일))는 "A에서 B", "일는→일은" 조사 보정. - voice-call.js sanitizeForSpeech가 단위 낭독보다 먼저 호출하고(통화·🔊 읽기 버튼 공통), index.html에서 로드. - tests/speech-dates.test.ts 8개 추가(speech-units·speech-tables 포함 22개 통과). Co-Authored-By: Claude Sonnet 5.5 --- tests/speech-dates.test.ts | 50 +++++++++++++++++++++++++ web-ui/html/index.html | 1 + web-ui/js/voice/speech-dates.js | 65 +++++++++++++++++++++++++++++++++ web-ui/js/voice/voice-call.js | 3 ++ 4 files changed, 119 insertions(+) create mode 100644 tests/speech-dates.test.ts create mode 100644 web-ui/js/voice/speech-dates.js diff --git a/tests/speech-dates.test.ts b/tests/speech-dates.test.ts new file mode 100644 index 0000000..3d42e60 --- /dev/null +++ b/tests/speech-dates.test.ts @@ -0,0 +1,50 @@ +/** + * speech-dates — TTS가 연도 없는 슬래시 날짜를 "십 삼십"으로 읽어 월·일이 빠지던 문제(2026-10-30). + * 표본: 같은 날 어시스턴트 답변의 "내일(10/30)", "11/2 월요일", "11/2~11/8", "11/3~4". + */ +import { test, describe } from 'node:test'; +import assert from 'node:assert/strict'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { spellDatesForSpeech: f } = require('../web-ui/js/voice/speech-dates.js'); + +describe('spellDatesForSpeech', () => { + test('슬래시 날짜는 월·일로', () => { + assert.equal(f('내일(10/30)은 강수'), '내일(10월 30일)은 강수'); + assert.equal(f('기상청 10/28 23시 발표 기준'), '기상청 10월 28일 23시 발표 기준'); + assert.equal(f('11/5 구름많음'), '11월 5일 구름많음'); + }); + test('요일이 붙으면 모호한 꼴도 날짜', () => { + assert.equal(f('11/2 월요일은 비'), '11월 2일 월요일은 비'); + assert.equal(f('9/11(월)'), '9월 11일(월)'); + assert.equal(f('3/4 토요일'), '3월 4일 토요일'); + }); + test('범위: 11/2~11/8, 11/3~4', () => { + assert.equal(f('다음 주(11/2~11/8) 예보'), '다음 주(11월 2일에서 11월 8일) 예보'); + assert.equal(f('11/3~4는 맑고'), '11월 3일에서 4일은 맑고'); + assert.equal(f('주말 10/30(토)~10/31(일)'), '주말 10월 30일(토)에서 10월 31일(일)'); + }); + test('날짜 말머리가 있으면 모호한 꼴도 날짜', () => { + assert.equal(f('내일 9/11 도착'), '내일 9월 11일 도착'); + }); + test('점 표기는 요일이 붙을 때만', () => { + assert.equal(f('10.30(토)'), '10월 30일(토)'); + assert.equal(f('10.30 토요일'), '10월 30일 토요일'); + assert.equal(f('기온 10.30도'), '기온 10.30도'); + assert.equal(f('가격 3.5배'), '가격 3.5배'); + }); + test('분수·비율·단위는 건드리지 않는다', () => { + assert.equal(f('1/2컵'), '1/2컵'); + assert.equal(f('3/4 정도'), '3/4 정도'); + assert.equal(f('24/7 운영'), '24/7 운영'); + assert.equal(f('풍속 2.6 m/s'), '풍속 2.6 m/s'); + assert.equal(f('성공률 9/10'), '성공률 9/10'); + }); + test('연도가 붙은 날짜는 그대로 둔다(뒤 규칙이 처리)', () => { + assert.equal(f('2026/10/30'), '2026/10/30'); + assert.equal(f('2026-10-30'), '2026-10-30'); + }); + test('빈 입력', () => { + assert.equal(f(''), ''); + assert.equal(f(null), ''); + }); +}); diff --git a/web-ui/html/index.html b/web-ui/html/index.html index 2166de6..c92985f 100644 --- a/web-ui/html/index.html +++ b/web-ui/html/index.html @@ -2148,6 +2148,7 @@ + diff --git a/web-ui/js/voice/speech-dates.js b/web-ui/js/voice/speech-dates.js new file mode 100644 index 0000000..185536f --- /dev/null +++ b/web-ui/js/voice/speech-dates.js @@ -0,0 +1,65 @@ +// speech-dates.js — 음성 읽기(TTS)용 "연도 없는 날짜" → "M월 D일" 변환 +// +// 2026-10-30 "스피치 엔진이 월·일을 구분하지 못한다 — '십 삼십 토요일'". 어시스턴트 답변은 날씨·일정에서 +// "내일(10/30)", "11/2 월요일", "11/2~11/8", "11/3~4"처럼 슬래시 날짜를 자주 쓴다. voice-call.js의 sanitizeForSpeech는 +// 연도가 붙은 날짜(2026-10-30)만 "월·일"로 바꿨기 때문에, 슬래시 날짜는 숫자만 한글로 풀려 "십 삼십"이 되고 "월·일"이 통째로 +// 빠졌다. 여기서 "M월 D일"로 바꿔 두면 뒤의 파이프라인이 10월→시월·6월→유월, 숫자→한글 낭독을 이어서 처리한다. +// +// 분수(1/2, 3/4)·비율·24/7을 날짜로 오인하지 않도록 보수적으로 판정한다: +// · 월 1~12, 일 1~31이어야 한다. +// · 앞 수가 뒤 수보다 크면(11/5 — 가분수는 거의 안 쓴다) 또는 뒤 수가 12를 넘으면(10/30) 날짜로 본다. +// · 그 밖의 모호한 꼴(3/4, 9/11)은 뒤에 요일이 오거나 앞에 날짜 말머리(오늘·내일·기준·발표…)가 있을 때만 날짜. +// · 점 표기(10.30)는 소수와 구별이 안 되므로 바로 뒤에 요일 표시가 있을 때만(10.30(토)). +// voice-call.js(통화)와 voice.js(읽기 버튼)가 sanitizeForSpeech를 통해 같이 쓴다. +(function (root) { + var WEEKDAY_AFTER = /^\s*(?:\(\s*[월화수목금토일]\s*\)|[월화수목금토일]요일|[월화수목금토일](?![가-힣A-Za-z0-9]))/; + var DATE_LEAD_BEFORE = /(?:오늘|내일|모레|어제|그제|글피|이번|다음|주말|기준|발표|예보|날짜|일정|마감|까지|부터|에서|예정|도착|출발|개봉|시작|종료)\s*[(\[]?\s*$/; + + function validMD(m, d) { return m >= 1 && m <= 12 && d >= 1 && d <= 31; } + + function isDateByContext(m, d, before, after, dotForm) { + if (!validMD(m, d)) return false; + if (WEEKDAY_AFTER.test(after)) return true; + if (dotForm) return false; // 점 표기는 요일이 붙어야만 + if (m > d || d > 12) return true; // 분수 꼴이 아님(11/5, 10/30) + return DATE_LEAD_BEFORE.test(before); // 3/4·9/11 같은 모호한 꼴은 말머리가 있을 때만 + } + + function spellDatesForSpeech(text) { + var src = String(text == null ? '' : text); + + // 1) 범위: 11/2~11/8, 11/3~4, 10/30(토)~10/31(일) → "11월 2일에서 11월 8일", "11월 3일에서 4일", "10월 30일(토)에서 10월 31일(일)" + src = src.replace(/(? 31)) return m0; + var tail = c !== null ? c + '월 ' + e + '일' : e + '일'; + return a + '월 ' + b + '일' + (wd1 || '') + '에서 ' + tail; + }); + + // 2) 슬래시 단일 날짜: 10/30, 11/2 월요일, (10/30) + src = src.replace(/(?