inital ai slop code

This commit is contained in:
2025-08-08 18:04:01 +02:00
parent a31d79bb09
commit 512521e9d0
15 changed files with 1855 additions and 0 deletions

31
src/subtitles.ts Normal file
View 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;
}