Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(transcription): keep a word start that falls exactly on a speaker cut
Elian Dorana00e7ff0f4bb
diff --git a/apps/desktop/src/services/transcription/speakers.spec.ts b/apps/desktop/src/services/transcription/speakers.spec.tsindex 791fae3156..f0405594b1 100644--- a/apps/desktop/src/services/transcription/speakers.spec.ts+++ b/apps/desktop/src/services/transcription/speakers.spec.ts@@ -112,6 +112,15 @@ describe("snapToWordBoundary", () => {expect(snapToWordBoundary(3.7, words)).toBe(2.8);});+ it("keeps a word start that falls exactly on the cut over a farther one", () => {+ const exact = [+ { text: "so", startSeconds: 0 },+ { text: "we", startSeconds: 2 },+ { text: "go", startSeconds: 2.5 }+ ];+ expect(snapToWordBoundary(2, exact)).toBe(2);+ });+it("keeps the cut where no word starts within reach", () => {expect(snapToWordBoundary(10, words)).toBe(10);// The first word's start is no boundary: nothing precedes it.diff --git a/apps/desktop/src/services/transcription/speakers.ts b/apps/desktop/src/services/transcription/speakers.tsindex 39629c8934..c6196bf177 100644--- a/apps/desktop/src/services/transcription/speakers.ts+++ b/apps/desktop/src/services/transcription/speakers.ts@@ -115,13 +115,13 @@ export function snapToWordBoundary(cutSeconds: number, words: TimedWord[], reach.filter(({ seconds }) => Math.abs(seconds - cutSeconds) <= reachSeconds);const sentenceStarts = boundaries.filter(({ followsSentence }) => followsSentence);const candidates = sentenceStarts.length ? sentenceStarts : boundaries;- let best = cutSeconds;+ let best: number | undefined;for (const { seconds } of candidates) {- if (best === cutSeconds || Math.abs(seconds - cutSeconds) < Math.abs(best - cutSeconds)) {+ if (best === undefined || Math.abs(seconds - cutSeconds) < Math.abs(best - cutSeconds)) {best = seconds;}}- return best;+ return best ?? cutSeconds;}function normalize(vector: Float32Array) {