Skip to content

Commit f2d5667

Browse files
committed
fix(cli): keep a spliced gap word that has no leading space
The filter dropped such a word; it is now kept and given its word boundary.
1 parent e7f5176 commit f2d5667

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎packages/cli/src/whisper/parakeet.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ describe("spliceGap", () => {
150150
expect(text(spliceGap(decoded, patch, 0, [3.3, 5]))).toBe("it's so what now");
151151
});
152152

153+
it("keeps a patch's first word even when it has no leading space", () => {
154+
const decoded = w([" so", 9], [" right", 12]);
155+
expect(text(spliceGap(decoded, w(["ask", 9.4], [" not", 10.1]), 0, [9.1, 12]))).toBe(
156+
"so ask not right",
157+
);
158+
});
159+
153160
it("keeps a real repeat that starts well inside the gap", () => {
154161
const decoded = w([" that", 2], [" right", 4]);
155162
const patch = w([" that", 3], [" is", 3.4]);

‎packages/cli/src/whisper/parakeet.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,15 @@ export function spliceGap(
209209
}));
210210
const kept = wordsOf(tokens(decoded, 0));
211211
const added = wordsOf(tokens(patch, offset)).filter(
212-
([first]) => first!.text.startsWith(" ") && first!.start >= from && first!.start < to,
212+
([first]) => first!.start >= from && first!.start < to,
213213
);
214214
const before = kept.filter(([first]) => first!.start < from).map(letters);
215215
const after = kept.filter(([first]) => first!.start >= to).map(letters);
216216
const head = added.filter(([first]) => first!.start < from + EDGE_SECONDS).map(letters);
217217
const tail = added.filter(([first]) => first!.start >= to - EDGE_SECONDS).map(letters);
218-
const fresh = added.slice(overlap(before, head), added.length - overlap(tail, after));
218+
const fresh = added
219+
.slice(overlap(before, head), added.length - overlap(tail, after))
220+
.map(([first, ...rest]) => [{ ...first!, text: ` ${first!.text.trimStart()}` }, ...rest]);
219221
const merged = [...kept, ...fresh].sort((a, b) => a[0]!.start - b[0]!.start).flat();
220222
return {
221223
tokens: merged.map((t) => t.text),

0 commit comments

Comments
 (0)