tts-voice-creator-clone-and.../scratch/patch_sync_dots.py
mARTin-B78 b43bacc275
Some checks are pending
Test and SonarQube / quality (push) Waiting to run
chore: add local maintenance utilities
2026-09-09 07:53:13 +02:00

52 lines
1.9 KiB
Python

import re
with open('static/js/rehearser.js', 'r') as f:
content = f.read()
# 1. In buildScriptPage, use serverCachedLines
content = content.replace(
"const isCached = rehState.synthCache.has(i);",
"const isCached = rehState.synthCache.has(i) || (rehState.serverCachedLines && rehState.serverCachedLines.has(i));"
)
# 2. Modify _lineAudioSyncDots to populate serverCachedLines and remove scanId
old_sync_dots = """let _lineAudioSyncedFor = null; // `${book}::${lineCount}` — avoid re-running the same scan on every small re-render
async function _lineAudioSyncDots() {
const book = _lineAudioBookName();
const scanId = `${book}::${rehState.lines.length}`;
if (_lineAudioSyncedFor === scanId) return;
_lineAudioSyncedFor = scanId;
_ensureNarrator();"""
new_sync_dots = """let _lineAudioSyncedFor = null; // unused now, kept for compat
async function _lineAudioSyncDots() {
if (!rehState.serverCachedLines) rehState.serverCachedLines = new Set();
const book = _lineAudioBookName();
_ensureNarrator();"""
content = content.replace(old_sync_dots, new_sync_dots)
old_foreach = """ const { existing } = await r.json();
(existing || []).forEach(key => {
const idx = keyToIdx.get(key);
if (idx == null) return;
rehState.staleLines.delete(idx);
_markSynthDot(idx, 'ok');
});
} catch (_) { /* dots just stay as-is; playback still checks the disk cache lazily either way */ }"""
new_foreach = """ const { existing } = await r.json();
(existing || []).forEach(key => {
const idx = keyToIdx.get(key);
if (idx == null) return;
rehState.staleLines.delete(idx);
rehState.serverCachedLines.add(idx);
_markSynthDot(idx, 'ok');
});
} catch (_) { /* dots just stay as-is; playback still checks the disk cache lazily either way */ }"""
content = content.replace(old_foreach, new_foreach)
with open('static/js/rehearser.js', 'w') as f:
f.write(content)