-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetCaptions.ts
More file actions
37 lines (27 loc) · 982 Bytes
/
getCaptions.ts
File metadata and controls
37 lines (27 loc) · 982 Bytes
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
29
30
31
32
33
34
35
36
37
"use server"
import { toCaptions, transcribe } from "@remotion/install-whisper-cpp";
import path from "path";
import fs from "fs";
export async function getCaptions(audioPath: string) {
const inputPath = path.isAbsolute(audioPath)
? audioPath
: path.join(process.cwd(), audioPath);
const whisperCppOutput = await transcribe({
inputPath,
whisperPath: path.join(process.cwd(), "whisper.cpp"),
whisperCppVersion: "1.5.5",
model: "medium.en",
tokenLevelTimestamps: true,
});
const { captions } = toCaptions({ whisperCppOutput });
const fileName = `captions-${Date.now()}.json`;
const captionsDir = path.join(process.cwd(), "remotion/captions");
if (!fs.existsSync(captionsDir)) {
fs.mkdirSync(captionsDir, { recursive: true });
}
const captionsPath = path.join(captionsDir, fileName);
fs.writeFileSync(captionsPath, JSON.stringify(captions, null, 2));
return {
captionsPath: `remotion/captions/${fileName}`,
};
}