설정 화면(음성 탭): 낭독 속도 슬라이더·음성 종류 선택·기준 음성 다시 뽑기 (voice.engine.ttsSpeed/ttsVoice)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-20 16:46:05 +09:00
1 parent 042768f067
commit 4761fe8ffe
3 files changed
+117

No files matched your search

+45
View File
@@ -470,6 +470,51 @@ export function registerSettingsRoutes(app: Express): void {
res.json({ success: true });
});
// ── 실시간 음성 엔진(통화·🔊): 낭독 속도·음성 종류 ─────────────────────────────────
// 엔진 시작 인자로 넘어가므로 저장 후 서버 재시작 때 적용된다(voice-engine-client.ts).
const designedRefPath = (voice: string) =>
path.join(path.dirname(String(((cm.getConfig() as any).voice?.engine?.speakerWav) || path.join(cm.getConfigDir(), 'voice', 'speaker_ko.wav'))),
'designed_' + voice.trim().toLowerCase().replace(/[^A-Za-z0-9_-]+/g, '_').slice(0, 40) + '.wav');
app.get('/api/settings/voice-engine', (_req, res) => {
const e = (cm.getConfig() as any).voice?.engine || {};
const voice = String(e.ttsVoice || 'clone');
res.json({
success: true,
ttsSpeed: Math.min(1.4, Math.max(0.8, Number(e.ttsSpeed) || 1.15)),
ttsVoice: voice,
designedRefExists: voice !== 'clone' && fs.existsSync(designedRefPath(voice)),
});
});
app.post('/api/settings/voice-engine', (req, res) => {
const b = req.body || {};
const current = cm.getConfig() as any;
const engine = { ...(current.voice?.engine || {}) };
if (b.ttsSpeed !== undefined) {
const v = Number(b.ttsSpeed);
if (!Number.isFinite(v) || v < 0.8 || v > 1.4) { res.status(400).json({ success: false, error: 'ttsSpeed must be 0.8..1.4' }); return; }
engine.ttsSpeed = Math.round(v * 100) / 100;
}
if (b.ttsVoice !== undefined) {
const v = String(b.ttsVoice).trim();
if (!v || v.length > 120) { res.status(400).json({ success: false, error: 'ttsVoice must be 1..120 chars' }); return; }
engine.ttsVoice = v;
}
cm.updateConfig({ voice: { ...(current.voice || {}), engine } } as any);
res.json({ success: true, restartRequired: true, ttsSpeed: engine.ttsSpeed, ttsVoice: engine.ttsVoice });
});
// 저장된 기준 음성을 지워 다음 시작 때 새로 뽑게 한다(생성물이라 지워도 안전)
app.post('/api/settings/voice-engine/reroll', (req, res) => {
const voice = String(req.body?.voice || (cm.getConfig() as any).voice?.engine?.ttsVoice || 'clone');
if (voice === 'clone') { res.status(400).json({ success: false, error: 'clone has no designed reference' }); return; }
const f = designedRefPath(voice);
let removed = false;
try { if (fs.existsSync(f)) { fs.unlinkSync(f); removed = true; } } catch (err: any) { res.status(500).json({ success: false, error: err.message }); return; }
res.json({ success: true, removed, restartRequired: true });
});
// ── Session ─────────────────────────────────────────────────────────────────
app.get('/api/settings/session', (_req, res) => {
+26
View File
@@ -1866,6 +1866,32 @@
<!-- ── Voice Settings ────────────────────────────────────────── -->
<div id="settings-panel-voice" style="display:none;padding:14px 16px">
<!-- 실시간 음성 엔진: 낭독 속도·음성 종류 (통화와 🔊 버튼 공통) -->
<div style="border:1px solid var(--line);border-radius:12px;padding:14px;margin-bottom:14px">
<div class="right-section-title" style="margin-bottom:10px">낭독 (통화 · 🔊 버튼)</div>
<div style="display:flex;gap:18px;flex-wrap:wrap;align-items:center">
<label style="font-size:12px;color:var(--muted)">음성 종류
<select id="ve-voice" onchange="veVoiceChanged()" style="margin-left:6px;border:1px solid var(--line);border-radius:8px;padding:5px;font-size:12px">
<option value="clone">기본 (등록된 목소리)</option>
<option value="female">여자</option>
<option value="male">남자</option>
<option value="girl">여자아이</option>
<option value="boy">남자아이</option>
<option value="child">어린이</option>
<option value="elderly_female">할머니</option>
<option value="elderly_male">할아버지</option>
<option value="__custom">직접 입력(영어 지시문)…</option>
</select></label>
<input id="ve-voice-custom" type="text" placeholder="female, teenager, high pitch" style="display:none;width:240px;border:1px solid var(--line);border-radius:8px;padding:5px;font-size:12px">
<label style="font-size:12px;color:var(--muted)">속도
<input id="ve-speed" type="range" min="0.8" max="1.4" step="0.05" oninput="document.getElementById('ve-speed-val').textContent=Number(this.value).toFixed(2)+'배'" style="vertical-align:middle;margin:0 6px;width:160px">
<span id="ve-speed-val" style="display:inline-block;min-width:42px">1.15배</span></label>
<button class="btn btn-sm" onclick="saveVoiceEngine()">저장</button>
<button class="btn btn-sm" id="ve-reroll" onclick="rerollVoiceRef()" style="display:none">목소리 다시 뽑기</button>
<span id="ve-status" style="font-size:12px;color:var(--muted)"></span>
</div>
<div style="font-size:11px;color:var(--muted);margin-top:8px;line-height:1.6">저장한 뒤 <b>서버를 재시작</b>하면 적용됩니다. 속도는 0.8~1.4배(1.5배 이상은 숫자·단위가 빠지는 것을 확인했습니다). 기본 외의 목소리는 처음 한 번 만든 기준 음성을 저장해 계속 같은 음색으로 읽습니다. 마음에 안 들면 "목소리 다시 뽑기" 후 재시작하세요.</div>
</div>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:14px">
<!-- STT -->
<div style="border:1px solid var(--line);border-radius:12px;padding:14px">
+46
View File
@@ -1235,6 +1235,52 @@ async function loadVoiceSettings() {
v('voice-tts-provider', cfg.tts?.provider);
v('voice-tts-model', cfg.tts?.model);
} catch (e) { console.warn('loadVoiceSettings:', e); }
try { loadVoiceEngine(); } catch {}
}
// ── 실시간 음성 엔진: 낭독 속도·음성 종류 ──────────────────────────────────────────
function veVoiceChanged() {
const sel = document.getElementById('ve-voice'), c = document.getElementById('ve-voice-custom'), rr = document.getElementById('ve-reroll');
if (c) c.style.display = sel.value === '__custom' ? '' : 'none';
if (rr) rr.style.display = sel.value === 'clone' ? 'none' : '';
}
async function loadVoiceEngine() {
const st = document.getElementById('ve-status');
try {
const r = await api('/api/settings/voice-engine');
const sel = document.getElementById('ve-voice');
const known = Array.from(sel.options).some(o => o.value === r.ttsVoice && o.value !== '__custom');
sel.value = known ? r.ttsVoice : '__custom';
document.getElementById('ve-voice-custom').value = known ? '' : r.ttsVoice;
const sp = document.getElementById('ve-speed'); sp.value = r.ttsSpeed;
document.getElementById('ve-speed-val').textContent = Number(r.ttsSpeed).toFixed(2) + '배';
veVoiceChanged();
if (st) st.textContent = r.ttsVoice === 'clone' ? '' : (r.designedRefExists ? '기준 음성 저장됨' : '기준 음성은 다음 시작 때 만들어집니다');
} catch (e) { if (st) st.textContent = '불러오기 실패: ' + e.message; }
}
async function saveVoiceEngine() {
const st = document.getElementById('ve-status');
const sel = document.getElementById('ve-voice').value;
const voice = sel === '__custom' ? document.getElementById('ve-voice-custom').value.trim() : sel;
if (!voice) { if (st) st.textContent = '지시문을 입력하세요'; return; }
try {
await api('/api/settings/voice-engine', { method: 'POST', body: JSON.stringify({
ttsVoice: voice, ttsSpeed: Number(document.getElementById('ve-speed').value),
}) });
if (st) st.textContent = '저장됨 — 서버를 재시작하면 적용됩니다';
} catch (e) { if (st) st.textContent = '저장 실패: ' + e.message; }
}
async function rerollVoiceRef() {
const st = document.getElementById('ve-status');
const sel = document.getElementById('ve-voice').value;
const voice = sel === '__custom' ? document.getElementById('ve-voice-custom').value.trim() : sel;
try {
const r = await api('/api/settings/voice-engine/reroll', { method: 'POST', body: JSON.stringify({ voice }) });
if (st) st.textContent = r.removed ? '기준 음성을 지웠습니다 — 재시작하면 새로 만듭니다' : '저장된 기준 음성이 없습니다';
} catch (e) { if (st) st.textContent = '실패: ' + e.message; }
}
async function saveVoiceSettings() {