From 3b83861749112d1fc8c8ee5f57498c2887eebf4a Mon Sep 17 00:00:00 2001 From: an-lee Date: Mon, 24 Jun 2024 14:35:09 +0800 Subject: [PATCH] Feat: customize settings before transcribing (#699) * transcribe with language * avoid using .en model to transcribe un-English audio * save lanuage in transcription/audio/video * may select language when regenerate transcription * may select service when re-generate * refactor transcription form * refactor transcription create form * refactor media loading modal * display ipa per language * refactor ipa mappings * parse subtitle files --- enjoy/src/api/client.ts | 4 +- enjoy/src/i18n/en.json | 5 +- enjoy/src/i18n/zh-CN.json | 5 +- enjoy/src/main/db/handlers/audios-handler.ts | 144 ++++------- .../db/handlers/transcriptions-handler.ts | 37 ++- enjoy/src/main/db/handlers/videos-handler.ts | 115 +++------ enjoy/src/main/db/models/segment.ts | 19 ++ enjoy/src/main/whisper.ts | 59 ++--- enjoy/src/preload.ts | 1 + .../renderer/components/audios/audio-card.tsx | 11 +- enjoy/src/renderer/components/index.ts | 1 + enjoy/src/renderer/components/medias/index.ts | 1 - .../components/medias/media-caption.tsx | 22 +- .../tab-content-translation.tsx | 4 +- .../components/medias/media-loading-modal.tsx | 114 ++++----- .../medias/media-transcription-form.tsx | 127 ---------- .../media-transcription-generate-button.tsx | 44 ++-- .../components/medias/media-transcription.tsx | 6 +- .../components/notes/note-segment.tsx | 17 +- .../components/transcriptions/index.ts | 2 + .../transcription-create-form.tsx | 233 ++++++++++++++++++ .../transcription-edit-button.tsx | 115 +++++++++ .../context/app-settings-provider.tsx | 16 +- .../context/media-player-provider.tsx | 15 +- enjoy/src/renderer/hooks/use-transcribe.tsx | 46 ++-- .../src/renderer/hooks/use-transcriptions.tsx | 37 ++- enjoy/src/types/audio.d.ts | 1 + enjoy/src/types/enjoy-app.d.ts | 1 + enjoy/src/types/segment.d.ts | 9 +- enjoy/src/types/transcription.d.ts | 1 + enjoy/src/types/video.d.ts | 8 +- 31 files changed, 695 insertions(+), 525 deletions(-) delete mode 100644 enjoy/src/renderer/components/medias/media-transcription-form.tsx create mode 100644 enjoy/src/renderer/components/transcriptions/index.ts create mode 100644 enjoy/src/renderer/components/transcriptions/transcription-create-form.tsx create mode 100644 enjoy/src/renderer/components/transcriptions/transcription-edit-button.tsx diff --git a/enjoy/src/api/client.ts b/enjoy/src/api/client.ts index 58664be2..86098387 100644 --- a/enjoy/src/api/client.ts +++ b/enjoy/src/api/client.ts @@ -260,7 +260,9 @@ export class Client { return this.api.post("/api/transcriptions", decamelizeKeys(transcription)); } - syncSegment(segment: Partial>) { + syncSegment( + segment: Partial> + ) { return this.api.post("/api/segments", decamelizeKeys(segment)); } diff --git a/enjoy/src/i18n/en.json b/enjoy/src/i18n/en.json index 61a9d35a..caf67440 100644 --- a/enjoy/src/i18n/en.json +++ b/enjoy/src/i18n/en.json @@ -604,5 +604,8 @@ "referenceText": "Reference text", "inputReferenceTextOrLeaveItBlank": "Input the reference text or leave it blank", "assessing": "Assessing", - "assessedSuccessfully": "Assessed successfully" + "assessedSuccessfully": "Assessed successfully", + "optinal": "Optional", + "uploadTranscriptFile": "Upload transcript file(.txt/.srt/.vtt)", + "onlyTextFileIsSupported": "Only text file is supported" } diff --git a/enjoy/src/i18n/zh-CN.json b/enjoy/src/i18n/zh-CN.json index 2357f331..28925646 100644 --- a/enjoy/src/i18n/zh-CN.json +++ b/enjoy/src/i18n/zh-CN.json @@ -604,5 +604,8 @@ "referenceText": "参考文本", "inputReferenceTextOrLeaveItBlank": "输入参考文本,或者留空", "assessing": "正在评估", - "assessedSuccessfully": "评估成功" + "assessedSuccessfully": "评估成功", + "optinal": "可选", + "uploadTranscriptFile": "上传字幕文件(.txt/.srt/.vtt)", + "onlyTextFileIsSupported": "仅支持文本文件" } diff --git a/enjoy/src/main/db/handlers/audios-handler.ts b/enjoy/src/main/db/handlers/audios-handler.ts index e5060c54..b771ca48 100644 --- a/enjoy/src/main/db/handlers/audios-handler.ts +++ b/enjoy/src/main/db/handlers/audios-handler.ts @@ -11,10 +11,10 @@ const logger = log.scope("db/handlers/audios-handler"); class AudiosHandler { private async findAll( - event: IpcMainEvent, + _event: IpcMainEvent, options: FindOptions> ) { - return Audio.findAll({ + const audios = await Audio.findAll({ order: [["updatedAt", "DESC"]], include: [ { @@ -25,46 +25,30 @@ class AudiosHandler { }, ], ...options, - }) - .then((audios) => { - if (!audios) { - return []; - } - return audios.map((audio) => audio.toJSON()); - }) - .catch((err) => { - event.sender.send("on-notification", { - type: "error", - message: err.message, - }); - }); + }); + + if (!audios) { + return []; + } + return audios.map((audio) => audio.toJSON()); } private async findOne( - event: IpcMainEvent, + _event: IpcMainEvent, where: WhereOptions> ) { - return Audio.findOne({ + const audio = await Audio.findOne({ where: { ...where, }, - }) - .then((audio) => { - if (!audio) return; + }); + if (!audio) return; - if (!audio.isSynced) { - audio.sync().catch(() => {}); - } + if (!audio.isSynced) { + audio.sync().catch(() => {}); + } - return audio.toJSON(); - }) - .catch((err) => { - logger.error(err); - event.sender.send("on-notification", { - type: "error", - message: err.message, - }); - }); + return audio.toJSON(); } private async create( @@ -79,22 +63,15 @@ class AudiosHandler { let file = uri; let source; if (uri.startsWith("http")) { - try { - if (youtubedr.validateYtURL(uri)) { - file = await youtubedr.autoDownload(uri); - } else { - file = await downloader.download(uri, { - webContents: event.sender, - }); - } - if (!file) throw new Error("Failed to download file"); - source = uri; - } catch (err) { - return event.sender.send("on-notification", { - type: "error", - message: t("models.audio.failedToDownloadFile", { file: uri }), + if (youtubedr.validateYtURL(uri)) { + file = await youtubedr.autoDownload(uri); + } else { + file = await downloader.download(uri, { + webContents: event.sender, }); } + if (!file) throw new Error("Failed to download file"); + source = uri; } try { @@ -119,73 +96,42 @@ class AudiosHandler { return audio.toJSON(); } catch (err) { - return event.sender.send("on-notification", { - type: "error", - message: t("models.audio.failedToAdd", { error: err.message }), - }); + logger.error(err); + throw err; } } private async update( - event: IpcMainEvent, + _event: IpcMainEvent, id: string, params: Attributes