-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
processAudio.ts
28 lines (26 loc) · 925 Bytes
/
processAudio.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import ffmpeg from "fluent-ffmpeg";
import ffmpegInstaller from "@ffmpeg-installer/ffmpeg";
import { join } from "path";
import { workingDir } from "./util";
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
export function processAudio(inputPath: string): Promise<string> {
const fileName = inputPath.split("/").pop() ?? "";
const fileNameWithoutExtension = fileName.split(".")[0];
const outputPath = join(
workingDir, "from-video", `${Date.now()}-${fileNameWithoutExtension}.wav`,
);
return new Promise((resolve, reject) => {
ffmpeg(inputPath)
.audioChannels(1) // Set to mono
.format("s16le") // Set format to s16le (16-bit signed little-endian)
.audioFrequency(16000) // Set audio frequency to 16kHz
.format("wav")
.on("end", () => {
resolve(outputPath);
})
.on("error", (err) => {
reject("Error: " + err);
})
.save(outputPath);
});
}