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): count transcriptions per guide and add later speech to a step

davbioe4da701ffea4
diff --git a/src/entrypoints/background/__tests__/narration-settle.test.ts b/src/entrypoints/background/__tests__/narration-settle.test.ts
index 63b55dc..8df020d 100644
--- a/src/entrypoints/background/__tests__/narration-settle.test.ts
+++ b/src/entrypoints/background/__tests__/narration-settle.test.ts
@@ -34,11 +34,13 @@ vi.mock('@/lib/voice-narration', () => ({
narrateRecording: vi.fn(),
}));
+const getStepsForGuide = vi.fn();
+
vi.mock('@/core/guides/service', () => ({
saveTranscript: vi.fn().mockResolvedValue(undefined),
applyNarrationToSteps: vi.fn().mockResolvedValue(undefined),
findExistingStepIds: vi.fn().mockResolvedValue([]),
- getStepsForGuide: vi.fn().mockResolvedValue([]),
+ getStepsForGuide: (...args: unknown[]) => getStepsForGuide(...args),
}));
vi.mock('../deferred-descriptions', () => ({ discardDeferred: vi.fn() }));
@@ -79,6 +81,7 @@ beforeEach(() => {
hasVoiceHost.mockReset().mockResolvedValue(true);
closeVoiceHostIfIdle.mockReset().mockResolvedValue(undefined);
stopVoiceCapture.mockReset();
+ getStepsForGuide.mockReset().mockResolvedValue([]);
});
describe('a narration that has nothing left to transcribe', () => {
@@ -128,5 +131,52 @@ describe('a narration that has nothing left to transcribe', () => {
await applyNarration('g1', EMPTY_RESULT, false);
expect(getVoiceUpdate().phase).toBe('transcribing');
+ await applyNarration('g1', EMPTY_RESULT, true);
+ });
+});
+
+describe('transcriptions from two recordings in flight at once', () => {
+ it('settles once both have landed, whichever guide claimed last', async () => {
+ stopVoiceCapture.mockResolvedValue({ ok: true, audioEpochMs: 1_700_000_000_000, durationSeconds: 4 });
+
+ await beginRecording();
+ await stopVoiceNarration('g1');
+ await beginRecording();
+ await stopVoiceNarration('g2');
+
+ const settledWithin = () =>
+ Promise.race([
+ whenNarrationSettled().then(() => 'settled'),
+ new Promise((resolve) => setTimeout(() => resolve('still waiting'), 20)),
+ ]);
+
+ await applyNarration('g1', EMPTY_RESULT, true);
+ expect(await settledWithin()).toBe('still waiting');
+
+ await applyNarration('g2', EMPTY_RESULT, true);
+ expect(await settledWithin()).toBe('settled');
+ });
+});
+
+describe('the steps a stop hands to the transcriber', () => {
+ it('includes steps an earlier slice already narrated, so the tail still has somewhere to go', async () => {
+ getStepsForGuide.mockResolvedValue([
+ { id: 's1', timestamp: 1, narratedDescription: 'Open billing' },
+ { id: 's2', timestamp: 2 },
+ ]);
+ stopVoiceCapture.mockResolvedValue({ ok: true, audioEpochMs: 1_700_000_000_000, durationSeconds: 4 });
+
+ await beginRecording();
+ await stopVoiceNarration('g3');
+ await applyNarration('g3', EMPTY_RESULT, true);
+
+ expect(stopVoiceCapture).toHaveBeenCalledWith(
+ 'g3',
+ [
+ { stepId: 's1', timestamp: 1 },
+ { stepId: 's2', timestamp: 2 },
+ ],
+ expect.anything(),
+ );
});
});
diff --git a/src/entrypoints/background/__tests__/narration-transcript.test.ts b/src/entrypoints/background/__tests__/narration-transcript.test.ts
index d7d0c66..c963d1a 100644
--- a/src/entrypoints/background/__tests__/narration-transcript.test.ts
+++ b/src/entrypoints/background/__tests__/narration-transcript.test.ts
@@ -58,7 +58,7 @@ describe('applying a narration result', () => {
await applyNarration('g1', { descriptions: [], transcript: orphaned, stats }, false);
expect(saveTranscript).toHaveBeenCalledWith('g1', orphaned);
- expect(applyNarrationToSteps).toHaveBeenCalledWith([]);
+ expect(applyNarrationToSteps).toHaveBeenCalledWith([], 1_700_000_000_000);
});
it('keeps each transcribed slice as its own stored row', async () => {
@@ -80,6 +80,9 @@ describe('applying a narration result', () => {
false,
);
- expect(applyNarrationToSteps).toHaveBeenCalledWith([{ stepId: 's1', description: 'Open the billing tab' }]);
+ expect(applyNarrationToSteps).toHaveBeenCalledWith(
+ [{ stepId: 's1', description: 'Open the billing tab' }],
+ 1_700_000_000_000,
+ );
});
});
diff --git a/src/entrypoints/background/voice.ts b/src/entrypoints/background/voice.ts
index 1767d9b..873a3fb 100644
--- a/src/entrypoints/background/voice.ts
+++ b/src/entrypoints/background/voice.ts
@@ -93,7 +93,7 @@ let orphanAudio: VoiceRecording | null = null;
let transcribingGuideId: string | null = null;
let settleNarration: (() => void) | null = null;
let narrationSettled: Promise<void> | null = null;
-let outstandingTranscriptions = 0;
+const outstandingTranscriptions = new Map<string, number>();
const NARRATION_SETTLE_TIMEOUT_MS = 30000;
@@ -111,7 +111,7 @@ export function whenNarrationSettled(): Promise<void> {
function claimTranscription(guideId: string): void {
transcribingGuideId = guideId;
- outstandingTranscriptions += 1;
+ outstandingTranscriptions.set(guideId, (outstandingTranscriptions.get(guideId) ?? 0) + 1);
if (narrationSettled) return;
narrationSettled = new Promise<void>((resolve) => {
settleNarration = resolve;
@@ -119,10 +119,15 @@ function claimTranscription(guideId: string): void {
}
function releaseTranscription(guideId: string): boolean {
- if (transcribingGuideId !== guideId || outstandingTranscriptions === 0) return false;
- outstandingTranscriptions -= 1;
- if (outstandingTranscriptions > 0) return true;
- transcribingGuideId = null;
+ const claims = outstandingTranscriptions.get(guideId) ?? 0;
+ if (claims === 0) return false;
+ if (claims > 1) {
+ outstandingTranscriptions.set(guideId, claims - 1);
+ return true;
+ }
+ outstandingTranscriptions.delete(guideId);
+ if (transcribingGuideId === guideId) transcribingGuideId = [...outstandingTranscriptions.keys()].at(-1) ?? null;
+ if (outstandingTranscriptions.size > 0) return true;
settleNarration?.();
settleNarration = null;
narrationSettled = null;
@@ -309,7 +314,7 @@ export async function applyNarration(
const narrated = result.descriptions.map((entry) => entry.stepId);
const surviving = await findExistingStepIds(narrated);
const updates = narrationUpdates(result, surviving);
- await applyNarrationToSteps(updates);
+ await applyNarrationToSteps(updates, result.transcript.epochMs);
const narratedIds = updates.map((update) => update.stepId);
discardDeferred(guideId, narratedIds);
recordNarrated(guideId, narratedIds);