openreader/tests/unit/whisper-alignment-smoke.spec.ts
Richard R 874e5ef359 refactor(whisper): migrate word alignment to ONNX backend and remove whisper.cpp integration
Replace the previous whisper.cpp-based word alignment with a fully ONNX-based
implementation using onnxruntime-node and @huggingface/tokenizers. Add new
Whisper ONNX model management, alignment mapping, and spectral analysis modules.
Remove all code and documentation referencing whisper.cpp, update environment
variables, Dockerfile, and docs to reflect ONNX-only alignment. Add unit tests
for alignment and ONNX model logic.
2026-05-19 13:00:21 -06:00

37 lines
1.4 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { readFile } from 'fs/promises';
import path from 'path';
import { alignAudioWithText } from '../../src/lib/server/whisper/alignment';
test.describe('whisper alignment smoke', () => {
test('runs ONNX alignment end-to-end without decoder reshape errors', async () => {
test.setTimeout(180000);
const audioPath = path.join(process.cwd(), 'tests/files/sample.mp3');
const audioBytes = await readFile(audioPath);
const buffer = audioBytes.buffer.slice(audioBytes.byteOffset, audioBytes.byteOffset + audioBytes.byteLength);
const alignments = await alignAudioWithText(
buffer,
'This is a sample sentence used to validate whisper alignment execution.',
undefined,
{ lang: 'en' },
);
expect(alignments.length).toBe(1);
expect(Array.isArray(alignments[0].words)).toBe(true);
expect(alignments[0].words.length).toBeGreaterThan(0);
let maxEnd = 0;
let positiveDurationWordCount = 0;
for (const word of alignments[0].words) {
expect(Number.isFinite(word.startSec)).toBe(true);
expect(Number.isFinite(word.endSec)).toBe(true);
expect(word.endSec).toBeGreaterThanOrEqual(word.startSec);
maxEnd = Math.max(maxEnd, word.endSec);
if (word.endSec > word.startSec) positiveDurationWordCount += 1;
}
expect(maxEnd).toBeLessThanOrEqual(10.2);
expect(positiveDurationWordCount).toBeGreaterThan(0);
});
});