Transcripts: check the whisper model is installed, download it (trying each form the service has used), and say what came back if it will not
build-container / build (push) Failing after 6m18s

This commit is contained in:
nmemmert committed 2026-10-23 11:25:50 -04:00
1 parent 05e6b19bfa
commit c82bd7cae9
3 files changed
+18 -5

No files matched your search

+6
View File
@@ -5,10 +5,15 @@ let bad = 0; const ok = (c, m) => { console.log((c ? 'PASS ' : 'FAIL ') + m);
(async () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'trt-'));
let installed = false; const calls = [];
const srv = http.createServer((req, res) => {
const body = []; req.on('data', d => body.push(d)); req.on('end', () => {
const b = Buffer.concat(body).toString('latin1');
calls.push(req.method + ' ' + req.url);
if (req.method === 'GET' && req.url === '/v1/models/Systran/faster-whisper-small') { res.writeHead(installed ? 200 : 404); return res.end('{}'); }
if (req.method === 'POST' && req.url === '/v1/models') { installed = /faster-whisper-small/.test(b); res.writeHead(installed ? 201 : 422); return res.end('{}'); } // (this version of the service downloads through a body, the older path form is refused)
if (req.url === '/v1/audio/transcriptions' && req.method === 'POST') {
if (!installed) { res.writeHead(404); return res.end('{"detail":"Model is not installed locally"}'); }
if (!/response_format/.test(b) || !/faster-whisper-small/.test(b) || !/hello-audio/.test(b)) { res.writeHead(400); return res.end('bad form'); }
res.writeHead(200, { 'content-type': 'application/json' }); return res.end(JSON.stringify({ text: 'x', segments: [{ start: 0, end: 2.5, text: ' Welcome to the show. ' }, { start: 2.5, end: 6, text: ' Today we talk about <b>bread</b>.' }, { start: 6, end: 7, text: ' ' }] }));
}
@@ -36,6 +41,7 @@ let bad = 0; const ok = (c, m) => { console.log((c ? 'PASS ' : 'FAIL ') + m);
const audio = path.join(dir, 'a.bin'); fs.writeFileSync(audio, 'hello-audio');
const r = await tr.whisper(audio, 'audio'); ok(r && r.found && r.lines.length === 2 && r.lines[0].text === 'Welcome to the show.' && r.lines[1].text === 'Today we talk about bread.' && r.source === 'Transcribed on your server', 'speech-to-text segments become timed lines (blank ones dropped, tags removed)');
ok(calls.includes('POST /v1/models/Systran/faster-whisper-small') && calls.includes('POST /v1/models') && installed, 'a model that is not installed is downloaded first (trying the older form, then the newer)');
ok(r.lines[1].t === 2500 && r.lines[1].e === 2500 + 6000, 'times are in milliseconds');
srv.close(); fs.rmSync(dir, { recursive: true, force: true });
console.log(bad ? '\n' + bad + ' check(s) failed' : '\nAll transcript checks passed'); process.exit(bad ? 1 : 0);