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): describe a step right away when there was nothing to transcribe

Luis Ortiz30c7d28919d0
diff --git a/src/entrypoints/background/deferred-descriptions.ts b/src/entrypoints/background/deferred-descriptions.ts
index e822497..f11c738 100644
--- a/src/entrypoints/background/deferred-descriptions.ts
+++ b/src/entrypoints/background/deferred-descriptions.ts
@@ -29,6 +29,14 @@ export function deferDescription(guideId: string, stepId: string, domContext: DO
deferred.set(guideId, forGuide);
}
+export function takeDeferredDescription(guideId: string, stepId: string): DOMContext | undefined {
+ const forGuide = deferred.get(guideId);
+ if (!forGuide) return undefined;
+ const domContext = forGuide.get(stepId);
+ forGuide.delete(stepId);
+ return domContext;
+}
+
export function takeDeferredDescriptions(guideId: string, narratedStepIds: readonly string[]): DeferredDescription[] {
const forGuide = deferred.get(guideId);
if (!forGuide) return [];
diff --git a/src/entrypoints/background/describe-unnarrated.ts b/src/entrypoints/background/describe-unnarrated.ts
index adc5e28..b3a0057 100644
--- a/src/entrypoints/background/describe-unnarrated.ts
+++ b/src/entrypoints/background/describe-unnarrated.ts
@@ -1,8 +1,16 @@
-import { applyAiDescription } from '@/core/guides/service';
+import { applyAiDescription, clearStepAiPending } from '@/core/guides/service';
import { generateAiDescription } from './ai-description';
-import { takeDeferredDescriptions } from './deferred-descriptions';
+import { takeDeferredDescription, takeDeferredDescriptions } from './deferred-descriptions';
import { queueDescription } from './description-queue';
+export function describeStepNow(guideId: string, stepId: string): void {
+ const domContext = takeDeferredDescription(guideId, stepId);
+ queueDescription(guideId, async () => {
+ const description = domContext ? await generateAiDescription(domContext) : undefined;
+ await clearStepAiPending(stepId, description);
+ });
+}
+
export function describeUnnarratedSteps(guideId: string, narratedStepIds: readonly string[]): void {
for (const { stepId, domContext } of takeDeferredDescriptions(guideId, narratedStepIds)) {
queueDescription(guideId, async () => {
diff --git a/src/entrypoints/background/voice.ts b/src/entrypoints/background/voice.ts
index 3d8f404..867d7ee 100644
--- a/src/entrypoints/background/voice.ts
+++ b/src/entrypoints/background/voice.ts
@@ -33,7 +33,7 @@ import {
import { narrateRecording, readTranscriptionSettings, type VoiceRecording } from '@/lib/voice-narration';
import { handedOffPcm, voiceStopAction } from '@/lib/voice-recovery';
import { discardDeferred } from './deferred-descriptions';
-import { describeUnnarratedSteps } from './describe-unnarrated';
+import { describeStepNow, describeUnnarratedSteps } from './describe-unnarrated';
const START_TIMEOUT_MS = 8000;
@@ -210,9 +210,15 @@ export async function flushNarrationForStep(guideId: string, stepId: string, tim
const settings = await readTranscriptionSettings();
if (!settings.apiKey) return;
const response = await flushVoiceCapture(guideId, { stepId, timestamp }, settings);
- if (!response.ok) logger.warn('voice: could not narrate the step yet', response);
+ if (!response.ok) {
+ logger.warn('voice: could not narrate the step yet', response);
+ describeStepNow(guideId, stepId);
+ return;
+ }
+ if (!response.flushed) describeStepNow(guideId, stepId);
} catch (error) {
logger.warn('voice: narrating the step while recording failed', error);
+ describeStepNow(guideId, stepId);
}
}