openreader/tests/unit/whisper-alignment-mapping.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

21 lines
904 B
TypeScript

import { test, expect } from '@playwright/test';
import {
mapWordsToSentenceOffsets,
} from '../../src/lib/server/whisper/alignment-mapping';
test.describe('whisper alignment mapping', () => {
test('maps words to sentence offsets with punctuation and repeated spaces', () => {
const aligned = mapWordsToSentenceOffsets('Hello, world again.', [
{ word: 'Hello', start: 0, end: 0.25 },
{ word: 'world', start: 0.25, end: 0.5 },
{ word: 'again', start: 0.5, end: 1.0 },
]);
expect(aligned.words).toHaveLength(3);
expect(aligned.words[0].charStart).toBe(0);
expect(aligned.words[0].charEnd).toBe(5);
expect(aligned.words[1].charStart).toBeGreaterThan(aligned.words[0].charEnd);
expect(aligned.words[2].charStart).toBeGreaterThan(aligned.words[1].charEnd);
expect(aligned.words[2].charEnd).toBeLessThanOrEqual('Hello, world again.'.length);
});
});