tts-voice-creator-clone-and.../static/js/init.js

53 lines
2.6 KiB
JavaScript

// ── Init ──────────────────────────────────────────────────────────────────
if (typeof initBenchmarkSampleControls === 'function') initBenchmarkSampleControls();
// Sync visible preview-text input with hidden benchmark-sample-text
(function syncPreviewInput() {
const visible = $('vl-preview-sample');
const hidden = $('benchmark-sample-text');
if (!visible || typeof BENCHMARK_SAMPLE_STORAGE_KEY === 'undefined') return;
const stored = localStorage.getItem(BENCHMARK_SAMPLE_STORAGE_KEY);
visible.value = stored || DEFAULT_BENCHMARK_SAMPLE_TEXT;
if (hidden) hidden.value = visible.value;
visible.addEventListener('input', () => {
if (hidden) hidden.value = visible.value;
localStorage.setItem(BENCHMARK_SAMPLE_STORAGE_KEY, visible.value.trim());
});
})();
// Sync flag button to current preview text language (best-match)
(function syncPreviewLangBtn() {
const ta = $('vl-preview-sample');
const btn = $('vl-preview-lang-btn');
if (!ta || !btn || typeof VL_SAMPLE_TEXTS === 'undefined') return;
const cur = ta.value.trim();
const matched = Object.keys(VL_SAMPLE_TEXTS).find(l => VL_SAMPLE_TEXTS[l] === cur) || 'EN';
const flags = typeof _VL_LANG_FLAG !== 'undefined' ? _VL_LANG_FLAG : {};
const labels = typeof LANGUAGE_LABELS !== 'undefined' ? LANGUAGE_LABELS : {};
const cc = (flags[matched] || 'gb').toLowerCase();
btn.innerHTML = `<span class="fi fi-${cc}"></span>`;
btn.title = (labels[matched] || matched) + ' — click to change sample language';
btn.dataset.lang = matched;
})();
// Synth mode segmented control (preview text vs. reference transcript)
(function initSynthMode() {
const seg = $('vl-synth-mode-seg');
const wrap = $('vl-preview-text-wrap');
if (!seg) return;
seg.querySelectorAll('.vl-synth-seg-btn').forEach(btn => {
btn.addEventListener('click', () => {
seg.querySelectorAll('.vl-synth-seg-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
if (wrap) wrap.classList.toggle('hidden', btn.dataset.mode === 'transcript');
});
});
})();
loadSettings().then(() => {
refreshSttBackends();
renderIntegrationSnippets();
// Do not let the first-run settings dialog's deferred navigation overwrite a
// section the user opened while the loader was still finishing its startup.
if (!localStorage.getItem(SETTINGS_SEEN_KEY) && !window._navRequestedSection) openSettings(true);
}).catch(e => status('Settings load failed: ' + e.message));