Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

fix(voice): extend the last step window to the end of the recording

Luis Ortiz37a90658f618
diff --git a/src/core/capture/voice/__tests__/step-windows.test.ts b/src/core/capture/voice/__tests__/step-windows.test.ts
index b98cdb5..895e5fc 100644
--- a/src/core/capture/voice/__tests__/step-windows.test.ts
+++ b/src/core/capture/voice/__tests__/step-windows.test.ts
@@ -5,11 +5,11 @@ const EPOCH = 1_000_000;
describe('buildStepWindows', () => {
it('returns nothing for no steps', () => {
- expect(buildStepWindows([], EPOCH)).toEqual([]);
+ expect(buildStepWindows([], EPOCH, 30)).toEqual([]);
});
it('gives the first step the interval from the start of the audio', () => {
- const [window] = buildStepWindows([{ stepId: 'a', timestamp: EPOCH + 4000 }], EPOCH);
+ const [window] = buildStepWindows([{ stepId: 'a', timestamp: EPOCH + 4000 }], EPOCH, 4);
expect(window).toEqual({ stepId: 'a', from: 0, to: 4 });
});
@@ -20,6 +20,7 @@ describe('buildStepWindows', () => {
{ stepId: 'b', timestamp: EPOCH + 9000 },
],
EPOCH,
+ 9,
);
expect(windows).toEqual([
{ stepId: 'a', from: 0, to: 4 },
@@ -27,6 +28,44 @@ describe('buildStepWindows', () => {
]);
});
+ it('extends the last window to the end of the recording so trailing narration is kept', () => {
+ const windows = buildStepWindows(
+ [
+ { stepId: 'a', timestamp: EPOCH + 4000 },
+ { stepId: 'b', timestamp: EPOCH + 9000 },
+ ],
+ EPOCH,
+ 21.5,
+ );
+ expect(windows).toEqual([
+ { stepId: 'a', from: 0, to: 4 },
+ { stepId: 'b', from: 4, to: 21.5 },
+ ]);
+ });
+
+ it('gives a single step the whole recording', () => {
+ expect(buildStepWindows([{ stepId: 'a', timestamp: EPOCH + 4000 }], EPOCH, 12)).toEqual([
+ { stepId: 'a', from: 0, to: 12 },
+ ]);
+ });
+
+ it('leaves the last window alone when the recording ends at the last step', () => {
+ const windows = buildStepWindows(
+ [
+ { stepId: 'a', timestamp: EPOCH + 4000 },
+ { stepId: 'b', timestamp: EPOCH + 9000 },
+ ],
+ EPOCH,
+ 9,
+ );
+ expect(windows[1].to).toBe(9);
+ });
+
+ it('never shrinks the last window when the duration is shorter than the last step', () => {
+ const windows = buildStepWindows([{ stepId: 'a', timestamp: EPOCH + 9000 }], EPOCH, 2);
+ expect(windows).toEqual([{ stepId: 'a', from: 0, to: 9 }]);
+ });
+
it('sorts unordered marks before building windows', () => {
const windows = buildStepWindows(
[
@@ -34,13 +73,27 @@ describe('buildStepWindows', () => {
{ stepId: 'a', timestamp: EPOCH + 4000 },
],
EPOCH,
+ 9,
);
expect(windows.map((w) => w.stepId)).toEqual(['a', 'b']);
});
it('clamps a step recorded before the audio epoch to a zero-width window at zero', () => {
- const [window] = buildStepWindows([{ stepId: 'a', timestamp: EPOCH - 5000 }], EPOCH);
- expect(window).toEqual({ stepId: 'a', from: 0, to: 0 });
+ const windows = buildStepWindows(
+ [
+ { stepId: 'a', timestamp: EPOCH - 5000 },
+ { stepId: 'b', timestamp: EPOCH + 3000 },
+ ],
+ EPOCH,
+ 3,
+ );
+ expect(windows[0]).toEqual({ stepId: 'a', from: 0, to: 0 });
+ });
+
+ it('still gives a step recorded before the audio epoch the trailing audio when it is last', () => {
+ expect(buildStepWindows([{ stepId: 'a', timestamp: EPOCH - 5000 }], EPOCH, 8)).toEqual([
+ { stepId: 'a', from: 0, to: 8 },
+ ]);
});
it('never produces a window that ends before it starts', () => {
@@ -51,6 +104,7 @@ describe('buildStepWindows', () => {
{ stepId: 'c', timestamp: EPOCH + 1000 },
],
EPOCH,
+ 5,
);
for (const window of windows) expect(window.to).toBeGreaterThanOrEqual(window.from);
});
@@ -63,6 +117,7 @@ describe('buildStepWindows', () => {
{ stepId: 'c', timestamp: EPOCH + 3000 },
],
EPOCH,
+ 10,
);
for (let i = 1; i < windows.length; i += 1) expect(windows[i].from).toBe(windows[i - 1].to);
});
diff --git a/src/core/capture/voice/step-windows.ts b/src/core/capture/voice/step-windows.ts
index 3e8fdb0..f7f1905 100644
--- a/src/core/capture/voice/step-windows.ts
+++ b/src/core/capture/voice/step-windows.ts
@@ -7,7 +7,7 @@ export interface StepMark {
timestamp: number;
}
-export function buildStepWindows(marks: StepMark[], audioEpochMs: number): StepWindow[] {
+export function buildStepWindows(marks: StepMark[], audioEpochMs: number, durationSeconds: number): StepWindow[] {
const windows: StepWindow[] = [];
let from = 0;
for (const mark of [...marks].sort((a, b) => a.timestamp - b.timestamp)) {
@@ -15,5 +15,7 @@ export function buildStepWindows(marks: StepMark[], audioEpochMs: number): StepW
windows.push({ stepId: mark.stepId, from: absoluteSeconds(from), to: absoluteSeconds(to) });
from = to;
}
+ const last = windows[windows.length - 1];
+ if (last) last.to = absoluteSeconds(Math.max(last.to, durationSeconds));
return windows;
}