Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions electron/electron-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,6 @@ interface Window {
projectState: unknown;
logs: string[];
}) => Promise<{ success: boolean; path?: string; canceled?: boolean; error?: string }>;
generateSubtitles: (
videoPath: string,
lang?: string,
) => Promise<{
success: boolean;
subtitles?: Array<{ id: string; startMs: number; endMs: number; text: string }>;
error?: string;
}>;
};
}

Expand Down
61 changes: 1 addition & 60 deletions electron/ipc/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ChildProcessWithoutNullStreams, execFile, spawn } from "node:child_process";
import { type ChildProcessWithoutNullStreams, spawn } from "node:child_process";
import { EventEmitter } from "node:events";
import { constants as fsConstants } from "node:fs";
import fs from "node:fs/promises";
Expand Down Expand Up @@ -3073,65 +3073,6 @@ export function registerIpcHandlers(
},
);

ipcMain.handle("generate-subtitles", async (_, videoPath: string, lang = "pt") => {
const scriptPath = path.join(app.getAppPath(), "scripts", "extract-subtitles.mjs");
try {
await fs.access(scriptPath);
} catch {
return { success: false, error: "extract-subtitles.mjs script not found" };
}

const nodeBin = process.env.NODE_BINARY || (process.platform === "win32" ? "node.exe" : "node");

return new Promise<{
success: boolean;
subtitles?: Array<{ id: string; startMs: number; endMs: number; text: string }>;
error?: string;
}>((resolve) => {
const child = execFile(
nodeBin,
[scriptPath, videoPath, "--json", "--lang", lang],
{
maxBuffer: 10 * 1024 * 1024,
timeout: 300_000,
cwd: app.getAppPath(),
},
(error, stdout, stderr) => {
if (error) {
console.error("Subtitle generation error:", stderr || error.message);
resolve({ success: false, error: error.message });
return;
}
try {
const jsonStart = stdout.indexOf("{");
const jsonEnd = stdout.lastIndexOf("}");
if (jsonStart === -1 || jsonEnd === -1) {
resolve({ success: false, error: "No JSON output from script" });
return;
}
const config = JSON.parse(stdout.slice(jsonStart, jsonEnd + 1));
const items = config?.subtitles?.items ?? [];
const FPS = 30;
const subtitles = items.map(
(item: { text: string; startFrame: number; endFrame: number }, idx: number) => ({
id: `sub-${idx + 1}`,
startMs: Math.round((item.startFrame / FPS) * 1000),
endMs: Math.round((item.endFrame / FPS) * 1000),
text: item.text,
}),
);
resolve({ success: true, subtitles });
} catch (parseError) {
resolve({ success: false, error: `Failed to parse output: ${String(parseError)}` });
}
},
);
child.stderr?.on("data", (data) => {
console.log("[subtitle-gen]", String(data).trim());
});
});
});

registerNativeBridgeHandlers({
getPlatform: () => process.platform,
getCurrentProjectPath: () => currentProjectPath,
Expand Down
3 changes: 0 additions & 3 deletions electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,6 @@ contextBridge.exposeInMainWorld("electronAPI", {
}) => {
return ipcRenderer.invoke("save-diagnostic", payload);
},
generateSubtitles: (videoPath: string, lang?: string) => {
return ipcRenderer.invoke("generate-subtitles", videoPath, lang ?? "pt");
},
setMicrophoneExpanded: (expanded: boolean) => {
ipcRenderer.send("hud:setMicrophoneExpanded", expanded);
},
Expand Down
16 changes: 1 addition & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@
"vite": "^7.3.2",
"vite-plugin-electron": "^0.29.1",
"vite-plugin-electron-renderer": "^0.14.6",
"vitest": "^4.1.4",
"wavefile": "^11.0.0"
"vitest": "^4.1.4"
},
"main": "dist-electron/main.js",
"lint-staged": {
Expand Down
Loading
Loading