낭독: 연도 없는 슬래시 날짜(10/30, 11/2~11/8)를 "M월 D일"로 — "십 삼십 토요일" 수정
답변에 "내일(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 <noreply@anthropic.com>
This commit is contained in:
1 parent
896561c909
commit
8cab4fd45b
4 files changed
+119
No files matched your search
@@ -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), '');
|
||||
});
|
||||
});
|
||||
@@ -2148,6 +2148,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../js/voice/speech-dates.js"></script>
|
||||
<script src="../js/voice/speech-units.js"></script>
|
||||
<script src="../js/voice/speech-tables.js"></script>
|
||||
<script src="../js/voice/voice-call.js"></script>
|
||||
|
||||
@@ -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(/(?<![\d./])(\d{1,2})\/(\d{1,2})(\s*\(\s*[월화수목금토일]\s*\))?\s*[~∼~]\s*(?:(\d{1,2})\/)?(\d{1,2})(?![\d/])/g,
|
||||
function (m0, m1, d1, wd1, m2, d2) {
|
||||
var a = +m1, b = +d1, c = m2 === undefined ? null : +m2, e = +d2;
|
||||
if (!validMD(a, b)) return m0;
|
||||
if (c !== null ? !validMD(c, e) : (e < 1 || e > 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(/(?<![\d./])(\d{1,2})\/(\d{1,2})(?![\d/])/g, function (m0, mo, da, offset, whole) {
|
||||
var before = whole.slice(Math.max(0, offset - 12), offset);
|
||||
var after = whole.slice(offset + m0.length);
|
||||
if (!isDateByContext(+mo, +da, before, after, false)) return m0;
|
||||
return +mo + '월 ' + +da + '일';
|
||||
});
|
||||
|
||||
// 3) 점 단일 날짜: 요일이 바로 붙은 10.30(토) / 10.30 토요일만
|
||||
src = src.replace(/(?<![\d./])(\d{1,2})\.(\d{1,2})(?![\d.])/g, function (m0, mo, da, offset, whole) {
|
||||
var before = whole.slice(Math.max(0, offset - 12), offset);
|
||||
var after = whole.slice(offset + m0.length);
|
||||
if (!isDateByContext(+mo, +da, before, after, true)) return m0;
|
||||
return +mo + '월 ' + +da + '일';
|
||||
});
|
||||
|
||||
// 4) "…일" 뒤에 붙은 조사 보정(범위 끝 "4일는" → "4일은")
|
||||
src = src.replace(/(\d)일(는|가)(?![가-힣])/g, function (_m, n, j) { return n + '일' + (j === '는' ? '은' : '이'); });
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = { spellDatesForSpeech: spellDatesForSpeech };
|
||||
if (root) root.spellDatesForSpeech = spellDatesForSpeech;
|
||||
})(typeof window !== 'undefined' ? window : (typeof globalThis !== 'undefined' ? globalThis : null));
|
||||
@@ -473,6 +473,9 @@
|
||||
// "9,500원"이 "구, 오백원"이 되어 "천"이 통째로 사라진다(09-26 "단어가 한번씩 빠진다", 표의 가격 열).
|
||||
// 단위 낭독보다 먼저여야 "$1,200"이 "1달러,200"으로 쪼개지지 않는다.
|
||||
text = String(text || '').replace(/(?<=\d),(?=\d{3}(?!\d))/g, '');
|
||||
// 연도 없는 슬래시 날짜 10/30·11/2~11/8 → "10월 30일"(10-30 "십 삼십 토요일"로 월·일이 빠지던 문제, speech-dates.js).
|
||||
// 연도 있는 날짜 규칙·시월/유월·숫자 낭독보다 먼저여야 뒤 파이프라인이 이어서 처리한다.
|
||||
text = window.spellDatesForSpeech ? window.spellDatesForSpeech(text) : text;
|
||||
text = window.spellUnitsForSpeech ? window.spellUnitsForSpeech(text) : text; // g/kg/GB/Hz… 단위 낭독(speech-units.js)
|
||||
return text
|
||||
// 날짜 2026-10-19 / 2026.10.19 / 2026/10/19 → "2026년 10월 19일"(안 그러면 마이너스·점으로 읽힌다). 월은 아래에서 시월·유월 처리.
|
||||
|
||||
Reference in new issue
Block a user