inital ai slop code
This commit is contained in:
31
src/subtitles.ts
Normal file
31
src/subtitles.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
function toSrtTime(seconds: number): string {
|
||||
const date = new Date(0);
|
||||
date.setSeconds(seconds);
|
||||
const timeString = date.toISOString().substr(11, 12);
|
||||
return timeString.replace(".", ",");
|
||||
}
|
||||
|
||||
export function createSrt(storyName: string, chunks: string[], chunkDurations: number[]): string {
|
||||
const srtPath = path.resolve("stories", storyName, "subtitles.srt");
|
||||
let srtContent = "";
|
||||
let currentTime = 0;
|
||||
|
||||
for (let i = 0; i < chunks.length; i++) {
|
||||
const chunk = chunks[i];
|
||||
const duration = chunkDurations[i];
|
||||
const startTime = toSrtTime(currentTime);
|
||||
const endTime = toSrtTime(currentTime + duration);
|
||||
|
||||
srtContent += `${i + 1}\n`;
|
||||
srtContent += `${startTime} --> ${endTime}\n`;
|
||||
srtContent += `${chunk}\n\n`;
|
||||
|
||||
currentTime += duration;
|
||||
}
|
||||
|
||||
fs.writeFileSync(srtPath, srtContent);
|
||||
return srtPath;
|
||||
}
|
Reference in New Issue
Block a user