From 47315aa1e4f78c0336344441dd04156c6e21519f Mon Sep 17 00:00:00 2001 From: an-lee Date: Tue, 20 Feb 2024 07:02:43 +0800 Subject: [PATCH] fix recording --- enjoy/src/i18n/en.json | 3 +- enjoy/src/i18n/zh-CN.json | 3 +- enjoy/src/main/window.ts | 1 + .../src/renderer/components/record-button.tsx | 32 +++++-------------- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/enjoy/src/i18n/en.json b/enjoy/src/i18n/en.json index 028c73d1..9b3e2acb 100644 --- a/enjoy/src/i18n/en.json +++ b/enjoy/src/i18n/en.json @@ -459,5 +459,6 @@ "preparingAudio": "Preparing audio", "preparingVideo": "Preparing video", "itMayTakeAWhileToPrepareForTheFirstLoad": "It may take a while to prepare for the first load. Please be patient.", - "loadingTranscription": "Loading transcription" + "loadingTranscription": "Loading transcription", + "cannotFindMicrophone": "Cannot find microphone" } diff --git a/enjoy/src/i18n/zh-CN.json b/enjoy/src/i18n/zh-CN.json index d639838b..f107379b 100644 --- a/enjoy/src/i18n/zh-CN.json +++ b/enjoy/src/i18n/zh-CN.json @@ -458,5 +458,6 @@ "preparingAudio": "正在准备音频", "preparingVideo": "正在准备视频", "itMayTakeAWhileToPrepareForTheFirstLoad": "首次加载可能需要一些时间,请耐心等候", - "loadingTranscription": "正在加载语音文本" + "loadingTranscription": "正在加载语音文本", + "cannotFindMicrophone": "无法找到麦克风" } diff --git a/enjoy/src/main/window.ts b/enjoy/src/main/window.ts index af5f3db5..705e0b6a 100644 --- a/enjoy/src/main/window.ts +++ b/enjoy/src/main/window.ts @@ -381,6 +381,7 @@ ${log} if (process.platform === "darwin") { const status = systemPreferences.getMediaAccessStatus(mediaType); + logger.debug("system-preferences-media-access", status); if (status !== "granted") { const result = await systemPreferences.askForMediaAccess(mediaType); return result; diff --git a/enjoy/src/renderer/components/record-button.tsx b/enjoy/src/renderer/components/record-button.tsx index 49f0ee38..3b4853f3 100644 --- a/enjoy/src/renderer/components/record-button.tsx +++ b/enjoy/src/renderer/components/record-button.tsx @@ -7,7 +7,6 @@ import WaveSurfer from "wavesurfer.js"; import { cn } from "@renderer/lib/utils"; import { RadialProgress, toast } from "@renderer/components/ui"; import { useHotkeys } from "react-hotkeys-hook"; -import { fetchFile } from "@ffmpeg/util"; export const RecordButton = (props: { className?: string; @@ -118,26 +117,6 @@ const RecordButtonPopover = (props: { onRecordEnd: (blob: Blob, duration: number) => void; }) => { const containerRef = useRef(); - const { ffmpeg } = useContext(AppSettingsProviderContext); - - const transcode = async (blob: Blob) => { - const input = `input.${blob.type.split("/")[1]}`; - const output = input.replace(/\.[^/.]+$/, ".wav"); - await ffmpeg.writeFile(input, await fetchFile(blob)); - await ffmpeg.exec([ - "-i", - input, - "-ar", - "16000", - "-ac", - "1", - "-c:a", - "pcm_s16le", - output, - ]); - const data = await ffmpeg.readFile(output); - return new Blob([data], { type: "audio/wav" }); - }; useEffect(() => { if (!containerRef.current) return; @@ -159,13 +138,18 @@ const RecordButtonPopover = (props: { record.on("record-end", async (blob: Blob) => { const duration = Date.now() - startAt; - const output = await transcode(blob); - props.onRecordEnd(output, duration); + props.onRecordEnd(blob, duration); }); RecordPlugin.getAvailableAudioDevices() .then((devices) => devices.find((d) => d.kind === "audioinput")) - .then((device) => record.startRecording({ deviceId: device.deviceId })); + .then((device) => { + if (device) { + record.startRecording({ deviceId: device.deviceId }); + } else { + toast.error(t("cannotFindMicrophone")); + } + }); return () => { record.stopRecording();