음성 낭독 보정: 날짜·시각(3:30→세시 삼십분)·비율, 표 단위 열(°C/%/mm), $1,200 쉼표 순서, 24시 고유어 시각; 🔊 텍스트 버튼이 통화와 같은 규칙을 쓰도록 통합

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-20 16:29:03 +09:00
1 parent 90fe19f7ba
commit 4acc24796c
2 files changed
+24 -4

No files matched your search

+3
View File
@@ -158,6 +158,7 @@ function _splitForSpeech(text) {
var start = 0;
for (var i = 0; i < text.length; i++) {
if (text[i] === '.' && /\d/.test(text[i - 1] || '') && /\d/.test(text[i + 1] || '')) continue; // decimal point, not a boundary
if (text[i] === '.' && /[A-Za-z0-9]/.test(text[i - 1] || '') && /[A-Za-z]/.test(text[i + 1] || '')) continue; // domain dot (investing.com), not a boundary
if (/[.!?\n]/.test(text[i])) {
var j = i + 1;
while (j < text.length && /[\s.!?]/.test(text[j])) j++;
@@ -288,6 +289,8 @@ function _hourReplacer(m, numStr, suffix) {
// bare "°C"/"°F" gets read as "그램"(grams) instead of degrees.
function _cleanForSpeech(text) {
if (typeof window !== 'undefined' && window.SpeechTables) text = window.SpeechTables.narrateTablesInText(text || ''); // 표 → 문장(speech-tables.js)
// 통화 낭독과 같은 규칙(날짜·시각·범위·도메인·쉼표 숫자·월 읽기 등)을 쓴다 — 두 벌로 갈라져 한쪽만 고쳐지던 문제(2026-10-20)
if (typeof window !== 'undefined' && typeof window.sanitizeForSpeech === 'function') return window.sanitizeForSpeech(text || '');
text = (typeof window !== 'undefined' && window.spellUnitsForSpeech) ? window.spellUnitsForSpeech(text || '') : (text || ''); // g/kg/GB/Hz… 단위 낭독(speech-units.js)
return (text || '')
.replace(/!\[.*?\]\(.*?\)/g, '')
+21 -4
View File
@@ -449,7 +449,7 @@
// (일/이/삼...), specifically for clock hours and hour-durations — "9시"
// is "아홉 시", never "구시" (reported 2026-07-10). Everything else (분,
// 초, 도, %, dates, etc.) correctly stays Sino-Korean via _numToHangulWord.
const _NATIVE_HOUR = { 1: '한', 2: '두', 3: '세', 4: '네', 5: '다섯', 6: '여섯', 7: '일곱', 8: '여덟', 9: '아홉', 10: '열', 11: '열한', 12: '열두' };
const _NATIVE_HOUR = { 1: '한', 2: '두', 3: '세', 4: '네', 5: '다섯', 6: '여섯', 7: '일곱', 8: '여덟', 9: '아홉', 10: '열', 11: '열한', 12: '열두', 13: '열세', 14: '열네', 15: '열다섯', 16: '열여섯', 17: '열일곱', 18: '열여덟', 19: '열아홉', 20: '스무', 21: '스물한', 22: '스물두', 23: '스물세', 24: '스물네' };
function _hourReplacer(m, numStr, suffix) {
const n = parseInt(numStr, 10);
return _NATIVE_HOUR[n] ? _NATIVE_HOUR[n] + suffix : m;
@@ -469,11 +469,17 @@
}
function sanitizeForSpeech(text) {
// 천 단위 쉼표(9,500 / 1,234,567)는 숫자 낭독 전에 제거한다. 안 그러면 "9"와 "500"이 따로 읽혀
// "9,500원"이 "구, 오백원"이 되어 "천"이 통째로 사라진다(09-26 "단어가 한번씩 빠진다", 표의 가격 열).
// 단위 낭독보다 먼저여야 "$1,200"이 "1달러,200"으로 쪼개지지 않는다.
text = String(text || '').replace(/(?<=\d),(?=\d{3}(?!\d))/g, '');
text = window.spellUnitsForSpeech ? window.spellUnitsForSpeech(text) : text; // g/kg/GB/Hz… 단위 낭독(speech-units.js)
return text
// 천 단위 쉼표(9,500 / 1,234,567)는 숫자 낭독 전에 제거한다. 안 그러면 "9"와 "500"이 따로 읽혀
// "9,500원"이 "구, 오백원"이 되어 "천"이 통째로 사라진다(09-26 "단어가 한번씩 빠진다", 표의 가격 열).
.replace(/(?<=\d),(?=\d{3}(?!\d))/g, '')
// 날짜 2026-10-19 / 2026.10.19 / 2026/10/19 → "2026년 10월 19일"(안 그러면 마이너스·점으로 읽힌다). 월은 아래에서 시월·유월 처리.
.replace(/(?<![\d.])(\d{4})\s*[-./]\s*(\d{1,2})\s*[-./]\s*(\d{1,2})(?![\d])/g, (_m, y, mo, d) => `${y}년 ${parseInt(mo, 10)}월 ${parseInt(d, 10)}일`)
// 시각 3:30 / 05:10 → "3시 30분"(정각이면 "3시"). 분이 한 자리인 3:1 같은 건 비율/점수로 "3 대 1".
.replace(/(?<![\d:])(\d{1,2}):(\d{2})(?![\d:])/g, (m, h, mi) => (+h <= 24 && +mi < 60) ? `${parseInt(h, 10)}시${+mi ? ' ' + parseInt(mi, 10) + '분' : ''}` : m)
.replace(/(?<![\d:])(\d{1,3}):(\d{1,2})(?![\d:])/g, '$1 대 $2')
// 낭독 전 정리(2026-10-19 "금리 읽는 게 이상"): 영문 괄호 병기는 한국어 음성으로 읽으면 어색해 뺀다,
// (수)는 요일로, 4.00%의 뒤쪽 0은 떼고(사점영영 → 사), 3.75%~4.00%는 "에서"로, 10월·6월은 시월·유월로,
// %포인트는 띄어 읽는다.
@@ -519,6 +525,15 @@
.replace(/(\d+(?:\.\d+)?)\s*m\/s/gi, '$1미터 매 초')
.replace(/(\d+(?:\.\d+)?)\s*mm/gi, '$1밀리미터')
.replace(/(\d+(?:\.\d+)?)\s*km/gi, '$1킬로미터')
// 숫자 없이 단위만 있는 경우(표의 '단위' 열 등): "단위 °C" → "단위 섭씨"
.replace(/(?<![A-Za-z0-9])°\s*C(?![A-Za-z])/g, '섭씨')
.replace(/(?<![A-Za-z0-9])°\s*F(?![A-Za-z])/g, '화씨')
.replace(/(?<![\d.])%(?!\w)/g, '퍼센트')
.replace(/(?<![A-Za-z0-9])km\/h(?![A-Za-z])/gi, '킬로미터 매 시')
.replace(/(?<![A-Za-z0-9])m\/s(?![A-Za-z])/gi, '미터 매 초')
.replace(/(?<![A-Za-z0-9])mm(?![A-Za-z])/g, '밀리미터')
.replace(/(?<![A-Za-z0-9])cm(?![A-Za-z])/g, '센티미터')
.replace(/(?<![A-Za-z0-9])km(?![A-Za-z])/g, '킬로미터')
// Wind-direction abbreviations in parens (e.g. "2.6 m/s (SSW)") aren't
// Korean words, so OmniVoice mangles them — spell out the compass point
// instead. Longest abbreviations first so "SSW" doesn't partial-match as
@@ -567,6 +582,8 @@
.trim();
}
window.sanitizeForSpeech = sanitizeForSpeech; // 텍스트 채팅 🔊 버튼(app/voice.js)도 같은 규칙을 쓴다
function enqueueSentence(text) {
text = sanitizeForSpeech((text || '').trim());
if (!text) return;