From 41c48b10e87788068dff1c8d68d69536070a1ee0 Mon Sep 17 00:00:00 2001 From: nmemmert <67961292+nmemmert@users.noreply.github.com> Date: Tue, 27 Oct 2026 08:55:49 -0400 Subject: [PATCH] Transcribe only at night when TRANSCRIBE_HOURS is set Queued jobs wait until the window opens (local time, so set TZ); a started job finishes. Co-Authored-By: Claude Sonnet 5.5 --- transcripts.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/transcripts.js b/transcripts.js index 031f190..eea88a1 100644 --- a/transcripts.js +++ b/transcripts.js @@ -110,9 +110,14 @@ async function fetchAudio(src, cookie, tmp) { let n = 0; const body = Readable.fromWeb(r.body); body.on('data', c => { n += c.length; if (n > MAX_AUDIO) body.destroy(new Error('That audio file is too large to transcribe')); }); await pipeline(body, fs.createWriteStream(tmp, { mode: 0o600 })); } +// TRANSCRIBE_HOURS=22-6 keeps the (slow, CPU-hungry) speech-to-text to the night: a job waits in the queue until that window opens (local time, so set TZ). A job that has started finishes even if the window closes. Empty = any time. +const NIGHT = (process.env.TRANSCRIBE_HOURS || '').match(/^(\d{1,2})\s*-\s*(\d{1,2})$/); +const inWindow = () => { if (!NIGHT) return true; const a = +NIGHT[1], b = +NIGHT[2], h = new Date().getHours(); return a === b || (a < b ? h >= a && h < b : h >= a || h < b); }; +async function untilWindow() { while (!inWindow()) await new Promise(r => setTimeout(r, 60e3)); } function startJob(key, src, cookie, getAudio, ep) { jobs.set(key, { state: 'running', since: Date.now() }); chain = chain.then(async () => { + await untilWindow(); const tmp = path.join(os.tmpdir(), 'nehub-tr-' + key); try { if (getAudio) await saveAudio(await getAudio(), tmp); else await fetchAudio(src, cookie, tmp); const r = await whisper(tmp, 'audio'); if (!r) throw new Error('No speech was found in that audio'); atomicWrite(fileOf(key), JSON.stringify(ep ? { ...r, ep } : r)); jobs.delete(key); } catch (e) { jobs.set(key, { state: 'error', since: Date.now(), error: e.message }); setTimeout(() => jobs.delete(key), 10 * 60e3).unref(); }