Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(stt): only mark an extraction timeout unreadable when nothing was read

Etienne Lescotbbeb37f390c9
diff --git a/electron/stt/extractAudio.test.ts b/electron/stt/extractAudio.test.ts
index 5ed99608c..c437b1ae9 100644
--- a/electron/stt/extractAudio.test.ts
+++ b/electron/stt/extractAudio.test.ts
@@ -125,6 +125,31 @@ describe("extractMono16kPcm", () => {
}
});
+ it("reports a timeout AFTER audio came out as a plain stall, not unreadable media", async () => {
+ // The file was readable; pointing the user at folder access would be wrong.
+ vi.useFakeTimers();
+ try {
+ const child = fakeChild();
+ spawnMock.mockReturnValue(child);
+ const promise = extractMono16kPcm("/Users/me/Downloads/a.mp4");
+ const settled = promise.then(
+ () => {
+ throw new Error("expected a rejection");
+ },
+ (error: Error) => error,
+ );
+ child.stdout.write(f32le([0.5]));
+ await vi.advanceTimersByTimeAsync(60_000);
+ const error = await settled;
+ expect(error).not.toBeInstanceOf(MediaUnreadableError);
+ expect(error.message).not.toContain(STT_MEDIA_UNREADABLE);
+ expect(error.message).toBe("ffmpeg timed out after 60000ms on /Users/me/Downloads/a.mp4");
+ expect(child.kill).toHaveBeenCalledWith("SIGKILL");
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
it("keeps the samples when ffmpeg exits non-zero AFTER writing audio", async () => {
// A truncated file still yields usable audio; throwing it away would lose a
// transcript over a trailing byte.
diff --git a/electron/stt/extractAudio.ts b/electron/stt/extractAudio.ts
index bf86f4cb6..28dd9f177 100644
--- a/electron/stt/extractAudio.ts
+++ b/electron/stt/extractAudio.ts
@@ -121,9 +121,15 @@ export async function extractMono16kPcm(
const timer = setTimeout(() => {
child.kill("SIGKILL");
+ // Only a hang before the first byte says the file could not be opened (a
+ // pending macOS folder-access prompt produces exactly that, issue #968). Once
+ // audio has come out the media was readable, and the stall is ffmpeg's.
+ const nothingRead = total === 0 && carry === null;
finish(() =>
reject(
- new MediaUnreadableError(filePath, `ffmpeg timed out after ${EXTRACT_TIMEOUT_MS}ms`),
+ nothingRead
+ ? new MediaUnreadableError(filePath, `ffmpeg timed out after ${EXTRACT_TIMEOUT_MS}ms`)
+ : new Error(`ffmpeg timed out after ${EXTRACT_TIMEOUT_MS}ms on ${filePath}`),
),
);
}, EXTRACT_TIMEOUT_MS);