mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-10 04:46:07 -08:00
feat(subtitles): add local Japanese subtitle generation (#240)
This commit is contained in:
1 parent
6841a37a22
commit
2831e05124
90 files changed
+4934
-57
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import type { IpcMain, WebContents } from 'electron';
|
||||
import { IPC_CHANNELS } from '../../shared/ipc/contracts';
|
||||
import { isSubtitleGenerationModelId } from '../../shared/subtitle-generation-model-catalog';
|
||||
import type { createSubtitleGenerationRuntime } from './subtitle-generation-runtime';
|
||||
|
||||
export function registerSubtitleGenerationIpc(deps: {
|
||||
ipc: Pick<IpcMain, 'handle'>;
|
||||
isAllowedSender: (sender: WebContents) => boolean;
|
||||
openModal: () => Promise<boolean>;
|
||||
runtime: ReturnType<typeof createSubtitleGenerationRuntime>;
|
||||
}): void {
|
||||
const handlers = [
|
||||
[IPC_CHANNELS.request.requestSubtitleGenerationOpen, () => deps.openModal()],
|
||||
[IPC_CHANNELS.request.getSubtitleGenerationStatus, () => deps.runtime.getStatus()],
|
||||
[
|
||||
IPC_CHANNELS.request.selectSubtitleGenerationModel,
|
||||
(model: unknown) => {
|
||||
if (!isSubtitleGenerationModelId(model))
|
||||
throw new Error('Unknown subtitle generation model.');
|
||||
return deps.runtime.selectModel(model);
|
||||
},
|
||||
],
|
||||
[IPC_CHANNELS.request.startSubtitleGeneration, () => deps.runtime.start()],
|
||||
[IPC_CHANNELS.request.downloadSubtitleGenerationModel, () => deps.runtime.download()],
|
||||
[IPC_CHANNELS.request.downloadSubtitleGenerationVadModel, () => deps.runtime.downloadVad()],
|
||||
[
|
||||
IPC_CHANNELS.request.setSubtitleGenerationVadEnabled,
|
||||
(enabled: unknown) => {
|
||||
if (typeof enabled !== 'boolean')
|
||||
throw new Error('Speech detection selection must be a boolean.');
|
||||
return deps.runtime.setVadEnabled(enabled);
|
||||
},
|
||||
],
|
||||
[IPC_CHANNELS.request.cancelSubtitleGeneration, () => deps.runtime.cancel()],
|
||||
] as const;
|
||||
for (const [channel, handler] of handlers) {
|
||||
deps.ipc.handle(channel, (event, payload: unknown) => {
|
||||
if (!deps.isAllowedSender(event.sender))
|
||||
throw new Error('Subtitle generation is only available from the overlay.');
|
||||
return handler(payload);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user