diff --git a/enjoy/src/i18n/en.json b/enjoy/src/i18n/en.json index 30313649..3cd10585 100644 --- a/enjoy/src/i18n/en.json +++ b/enjoy/src/i18n/en.json @@ -317,6 +317,7 @@ "azureSpeechToTextDescription": "Use Azure AI Speech to transcribe. It is a paid service.", "cloudflareAi": "Cloudflare AI", "cloudflareSpeechToTextDescription": "Use Cloudflare AI Worker to transcribe. It is in beta and free for now.", + "openaiSpeechToTextDescription": "Use openAI to transcribe using your own key.", "checkingWhisper": "Checking whisper status", "pleaseDownloadWhisperModelFirst": "Please download whisper model first", "whisperIsWorkingGood": "Whisper is working good", diff --git a/enjoy/src/i18n/zh-CN.json b/enjoy/src/i18n/zh-CN.json index 75710717..866965d6 100644 --- a/enjoy/src/i18n/zh-CN.json +++ b/enjoy/src/i18n/zh-CN.json @@ -316,6 +316,7 @@ "azureSpeechToTextDescription": "使用 Azure AI Speech 进行语音转文本,收费服务", "cloudflareAi": "Cloudflare AI", "cloudflareSpeechToTextDescription": "使用 Cloudflare AI 进行语音转文本,目前免费", + "openaiSpeechToTextDescription": "使用 OpenAI 进行语音转文本(需要 API 密钥)", "checkingWhisper": "正在检查 Whisper", "pleaseDownloadWhisperModelFirst": "请先下载 Whisper 模型", "whisperIsWorkingGood": "Whisper 正常工作", diff --git a/enjoy/src/main/db/handlers/speeches-handler.ts b/enjoy/src/main/db/handlers/speeches-handler.ts index 93e5200b..41935a7e 100644 --- a/enjoy/src/main/db/handlers/speeches-handler.ts +++ b/enjoy/src/main/db/handlers/speeches-handler.ts @@ -3,7 +3,7 @@ import { Speech } from "@main/db/models"; import fs from "fs-extra"; import path from "path"; import settings from "@main/settings"; -import { hashFile } from "@/utils"; +import { hashFile } from "@main/utils"; class SpeechesHandler { private async create( diff --git a/enjoy/src/main/db/handlers/transcriptions-handler.ts b/enjoy/src/main/db/handlers/transcriptions-handler.ts index b4eeda94..c2e54cf3 100644 --- a/enjoy/src/main/db/handlers/transcriptions-handler.ts +++ b/enjoy/src/main/db/handlers/transcriptions-handler.ts @@ -1,7 +1,6 @@ import { ipcMain, IpcMainEvent } from "electron"; import { Transcription, Audio, Video } from "@main/db/models"; -import { WhereOptions, Attributes } from "sequelize"; -import { t } from "i18next"; +import { Attributes } from "sequelize"; import log from "electron-log/main"; const logger = log.scope("db/handlers/transcriptions-handler"); @@ -44,7 +43,7 @@ class TranscriptionsHandler { id: string, params: Attributes ) { - const { result } = params; + const { result, engine, model, state } = params; return Transcription.findOne({ where: { id }, @@ -53,63 +52,7 @@ class TranscriptionsHandler { if (!transcription) { throw new Error("models.transcription.notFound"); } - transcription.update({ result }); - }) - .catch((err) => { - logger.error(err); - event.sender.send("on-notification", { - type: "error", - message: err.message, - }); - }); - } - - private async process( - event: IpcMainEvent, - where: WhereOptions>, - options?: { - force?: boolean; - blob: { - type: string; - arrayBuffer: ArrayBuffer; - }; - } - ) { - const { force = true, blob } = options || {}; - return Transcription.findOne({ - where: { - ...where, - }, - }) - .then((transcription) => { - if (!transcription) { - throw new Error("models.transcription.notFound"); - } - - const interval = setInterval(() => { - event.sender.send("on-notification", { - type: "warning", - message: t("stillTranscribing"), - }); - }, 1000 * 10); - - transcription - .process({ - force, - wavFileBlob: blob, - onProgress: (progress: number) => { - event.sender.send("transcription-on-progress", progress); - }, - }) - .catch((err) => { - event.sender.send("on-notification", { - type: "error", - message: err.message, - }); - }) - .finally(() => { - clearInterval(interval); - }); + transcription.update({ result, engine, model, state }); }) .catch((err) => { logger.error(err); @@ -122,7 +65,6 @@ class TranscriptionsHandler { register() { ipcMain.handle("transcriptions-find-or-create", this.findOrCreate); - ipcMain.handle("transcriptions-process", this.process); ipcMain.handle("transcriptions-update", this.update); } } diff --git a/enjoy/src/main/db/models/audio.ts b/enjoy/src/main/db/models/audio.ts index ce3a2a9b..9f495893 100644 --- a/enjoy/src/main/db/models/audio.ts +++ b/enjoy/src/main/db/models/audio.ts @@ -17,7 +17,7 @@ import { import { Recording, Speech, Transcription, Video } from "@main/db/models"; import settings from "@main/settings"; import { AudioFormats, VideoFormats, WEB_API_URL } from "@/constants"; -import { hashFile } from "@/utils"; +import { hashFile } from "@main/utils"; import path from "path"; import fs from "fs-extra"; import { t } from "i18next"; @@ -191,15 +191,6 @@ export class Audio extends Model