음성 낭독: 웹 주소·도메인을 '인베스팅 닷컴'처럼 읽기(경로 생략, 도메인 점에서 문장 안 끊음)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-19 23:51:08 +09:00
1 parent 29e182780e
commit 5f7d4890ae
1 file changed
+18
+18
View File
@@ -444,6 +444,19 @@
return _NATIVE_HOUR[n] ? _NATIVE_HOUR[n] + suffix : m;
}
const _TLD_KO = { com: '컴', net: '넷', org: '오알지', io: '아이오', kr: '케이알', gov: '거브', edu: '에듀', ai: '에이아이', dev: '데브', app: '앱', me: '미', tv: '티비', info: '인포', biz: '비즈' };
function _domainToSpeech(host) {
const parts = String(host).toLowerCase().split('.');
const out = [];
for (let i = 0; i < parts.length; i++) {
const p = parts[i];
if (i === 0) { out.push(p.replace(/-/g, ' ')); continue; }
if ((p === 'co' || p === 'or' || p === 'go') && parts[i + 1] === 'kr') { out.push('닷 ' + { co: '씨오', or: '오알', go: '지오' }[p]); continue; }
out.push('닷 ' + (_TLD_KO[p] || p));
}
return ' ' + out.join(' ').replace('닷 컴', '닷컴').replace('닷 넷', '닷넷') + ' ';
}
function sanitizeForSpeech(text) {
text = window.spellUnitsForSpeech ? window.spellUnitsForSpeech(text) : text; // g/kg/GB/Hz… 단위 낭독(speech-units.js)
return text
@@ -469,6 +482,9 @@
.replace(/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/gm, ' ')
// remaining table rows: "| a | b |" -> "a, b" so cells read as a list
.replace(/^\s*\|(.+)\|\s*$/gm, (_m, row) => row.split('|').map((c) => c.trim()).filter(Boolean).join(', '))
// 웹 주소는 도메인만 "인베스팅 닷컴"처럼 읽는다(경로·쿼리는 생략). www.는 뺀다.
.replace(/https?:\/\/(?:www\.)?([A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+)[^\s)\]]*/g, (_m, host) => _domainToSpeech(host))
.replace(/\b(?:www\.)?([A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.(?:com|net|org|kr|io|gov|edu|co\.kr|or\.kr|go\.kr|ai|dev|app|me|tv|info|biz))(?![A-Za-z])/gi, (_m, host) => _domainToSpeech(host))
.replace(/https?:\/\/\S+/g, ' ')
// OmniVoice reads a bare "°C"/"°F" as "그램"(grams) instead of degrees
// — the digits (even with a decimal point) come through fine once the
@@ -613,6 +629,8 @@
// 따로 읽혀 소수점·앞자리가 사라진다(2026-10-19 "소숫점 앞의 숫자가 빠진다"). 숫자 뒤 마침표가 버퍼 끝이면 더 받을 때까지 둔다.
// 턴이 끝나면 남은 꼬리는 별도로 낭독된다(finalText 경로).
if (text[i] === '.' && /\d/.test(text[i - 1] || '') && i === text.length - 1) break;
// 도메인의 점("investing.com")도 문장 끝이 아니다.
if (text[i] === '.' && /[A-Za-z0-9]/.test(text[i - 1] || '') && /^(?:com|net|org|kr|io|gov|edu|co|ai|dev|app|me|tv|info|biz|go|or|ne|ac)(?![A-Za-z])/i.test(text.slice(i + 1, i + 6))) continue;
if (/[.!?\n]/.test(text[i])) {
const boundaryChar = text[i];
let j = i + 1;