feat: implement electron-based audio transcription service with whisper integration and srt processing
This commit is contained in:
+39
-1
@@ -1,9 +1,9 @@
|
||||
"use strict";
|
||||
const electron = require("electron");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const utils = require("@electron-toolkit/utils");
|
||||
const child_process = require("child_process");
|
||||
const fs = require("fs");
|
||||
const iconv = require("iconv-lite");
|
||||
const icon = path.join(__dirname, "../../resources/icon.png");
|
||||
const BIN_PATH = electron.app.isPackaged ? path.join(process.resourcesPath, "bin") : path.join(electron.app.getAppPath(), "bin");
|
||||
@@ -231,6 +231,44 @@ function createWindow() {
|
||||
electron.ipcMain.on("open-explorer", (event, path2) => {
|
||||
electron.shell.showItemInFolder(path2);
|
||||
});
|
||||
electron.ipcMain.handle("read-srt", async (event, filePath) => {
|
||||
try {
|
||||
const content = fs.readFileSync(filePath, "utf-8");
|
||||
return content;
|
||||
} catch (error) {
|
||||
console.error("Read SRT Error:", error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
electron.ipcMain.handle("save-srt", async (event, { filePath, content }) => {
|
||||
try {
|
||||
fs.writeFileSync(filePath, content, "utf-8");
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error("Save SRT Error:", error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
electron.ipcMain.handle("select-file", async (event, filters) => {
|
||||
const { dialog } = require("electron");
|
||||
const result = await dialog.showOpenDialog({
|
||||
properties: ["openFile"],
|
||||
filters: filters || []
|
||||
});
|
||||
if (result.canceled) return null;
|
||||
return result.filePaths[0];
|
||||
});
|
||||
electron.ipcMain.handle("optimize-srt", async (event, filePath) => {
|
||||
try {
|
||||
const content = fs.readFileSync(filePath, "utf-8");
|
||||
const optimized = fixSrt(content);
|
||||
fs.writeFileSync(filePath, optimized, "utf-8");
|
||||
return { success: true, content: optimized };
|
||||
} catch (error) {
|
||||
console.error("Optimize SRT Error:", error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
}
|
||||
electron.app.whenReady().then(() => {
|
||||
utils.electronApp.setAppUserModelId("com.voicext.app");
|
||||
|
||||
@@ -7,7 +7,11 @@ const api = {
|
||||
onTranscriptionProgress: (callback) => electron.ipcRenderer.on("transcription-progress", (_, progress) => callback(progress)),
|
||||
onTranscriptionData: (callback) => electron.ipcRenderer.on("transcription-data", (_, data) => callback(data)),
|
||||
detectHardware: () => electron.ipcRenderer.invoke("detect-hardware"),
|
||||
openExplorer: (path) => electron.ipcRenderer.send("open-explorer", path)
|
||||
openExplorer: (path) => electron.ipcRenderer.send("open-explorer", path),
|
||||
readSrt: (filePath) => electron.ipcRenderer.invoke("read-srt", filePath),
|
||||
saveSrt: (filePath, content) => electron.ipcRenderer.invoke("save-srt", { filePath, content }),
|
||||
selectFile: (filters) => electron.ipcRenderer.invoke("select-file", filters),
|
||||
optimizeSrt: (filePath) => electron.ipcRenderer.invoke("optimize-srt", filePath)
|
||||
};
|
||||
if (process.contextIsolated) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user