fix recording
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
@@ -458,5 +458,6 @@
|
||||
"preparingAudio": "正在准备音频",
|
||||
"preparingVideo": "正在准备视频",
|
||||
"itMayTakeAWhileToPrepareForTheFirstLoad": "首次加载可能需要一些时间,请耐心等候",
|
||||
"loadingTranscription": "正在加载语音文本"
|
||||
"loadingTranscription": "正在加载语音文本",
|
||||
"cannotFindMicrophone": "无法找到麦克风"
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<HTMLDivElement>();
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user