Skip to content

Commit

Permalink
fix: fix uuidv4 error on electron main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
zcf0508 committed Sep 23, 2023
1 parent 7da5913 commit b3c6967
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/main/ffmpeg/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as fs from "fs"
import os from "os";
import path from "path";
import { v4 as uuidv4 } from "uuid";
import { spawn } from "child_process"
import readline from "readline"
import { secondToTimestamp } from "~~/utils"
Expand Down Expand Up @@ -32,7 +31,7 @@ export function getAudio(
"ffmpeg",
[
"-i", safePath(video), "-y",
"-vn", "-acodec", "pcm_s16le", "-ac", "1", "-ar", "8000",
"-vn", "-acodec", "pcm_s16le", "-ac", "1", "-ar", "16000",
exportPath,
],
)
Expand Down Expand Up @@ -130,14 +129,14 @@ function _ffmpegSlice(file: string, start: string, end: string) {
}
return new Promise<ReturnType<Vad>[0] & {file: string}>((resolve, reject) => {

const id = uuidv4()
const id = Math.random().toString(36).slice(2)
const exportPath = `${tempDir}/${id}.wav`
const p = spawn(
"ffmpeg",
[
"-i", safePath(file), "-y",
"-ss", secondToTimestamp(start),
"-t", secondToTimestamp(Number(end) - Number(start)),
"-t", secondToTimestamp((Number(end) - Number(start)).toFixed(6)),
"-c:a", "pcm_s16le",
exportPath,
],
Expand Down Expand Up @@ -178,4 +177,4 @@ export async function slice(file: string, times: ReturnType<Vad>) {
})
},
}
}
}

0 comments on commit b3c6967

Please sign in to comment.