From 05e6b19bfad5b071f3048937030861c5fb1d743e Mon Sep 17 00:00:00 2001 From: nmemmert <67961292+nmemmert@users.noreply.github.com> Date: Fri, 23 Oct 2026 11:20:31 -0400 Subject: [PATCH] Transcripts: ask the whisper service to download its model first --- transcripts.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/transcripts.js b/transcripts.js index 791767c..45ce57a 100644 --- a/transcripts.js +++ b/transcripts.js @@ -69,7 +69,11 @@ const jobs = new Map(); // key -> { state: 'running' | 'error', since, error } let chain = Promise.resolve(); // one at a time: it is heavy const fileOf = key => path.join(cfg.dir, key + '.json'); const keyFor = (kind, id, src) => crypto.createHash('sha1').update(kind + '|' + id + '|' + src).digest('hex'); +let modelReady = null; // the service must have the model on disk before it can use it: ask for it once (a no-op when it is already there) +const ensureModel = () => modelReady || (modelReady = fetch(cfg.api + '/v1/models/' + cfg.model, { method: 'POST', signal: AbortSignal.timeout(30 * 60e3) }) + .then(r => { if (!r.ok && r.status !== 409) throw new Error('status ' + r.status); }).catch(e => { modelReady = null; if (/^status 4\d\d/.test(e.message)) return; throw e; })); async function whisper(file, name) { + try { await ensureModel(); } catch (e) { throw new Error(`Could not reach the transcription service at ${cfg.api} (${why(e)}). Is the whisper container running? Check its log.`); } const form = new FormData(); form.append('file', await fs.openAsBlob(file), name || 'audio'); form.append('model', cfg.model); form.append('response_format', 'verbose_json'); form.append('timestamp_granularities[]', 'segment');