Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ https://github.com/TejasQ/gen-subs/assets/9947422/bc8df523-b62a-4123-a62d-2df178
- 🎧 **Multi-modal** - Supports both audio and video files and generates subtitles for each.
- 📊 **Multi-model** - Choose from a variety of machine learning models ranging from 40MB to >2GB in size. The larger the model, the more accurate the subtitles, but smaller models are also quite capable.

## Installation

To install gen-subs globally, run the following command :

```bash
npm i -g gen-subs
```

It's also possible to install it on a per project basis by omitting the -g flag.

## Usage

You can generate subtitles for any video using the following command:
Expand Down
3 changes: 2 additions & 1 deletion actions/for.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join } from "path";
import path from "path";
import { lstat, readdir, writeFile } from "fs/promises";
import { mkdirp } from "mkdirp";
import ora from "ora";
Expand All @@ -24,7 +25,7 @@ type Options = {
};

export async function forAction(relativeTarget: string, options: Options) {
const target = relativeTarget.startsWith('/') ? relativeTarget : join(process.cwd(), relativeTarget);
const target = path.resolve(relativeTarget);
const { pathWithoutExtension, fileName } = splitFilePath(target);
const format = (options.format ?? "srt").toLowerCase()

Expand Down
1 change: 1 addition & 0 deletions createTextFromAudioFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const createTextFromAudioFile = (
results.push(result);
}
}
results.push(recognizer.finalResult());
spinner.clear();
recognizer.free();
model.free();
Expand Down
5 changes: 3 additions & 2 deletions extractAudio.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import ffmpeg from "fluent-ffmpeg";
import ffmpegInstaller from "@ffmpeg-installer/ffmpeg";
import { join } from "path";
import path from "path";
import { workingDir } from "./util";

ffmpeg.setFfmpegPath(ffmpegInstaller.path);

export function extractAudio(filePath: string): Promise<string> {
return new Promise((resolve, reject) => {
const fileName = filePath.split("/").pop() ?? "";
const fileNameWithoutExtension = fileName.split(".")[0];
const fileName = path.basename(filePath);
const fileNameWithoutExtension = path.basename(filePath , path.extname(fileName));
const extractedAudioTarget = join(
workingDir,
"from-video",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
"inquirer": "^9.2.12",
"mkdirp": "^3.0.1",
"ora": "^7.0.1",
"rimraf": "^5.0.5",
"subtitle": "^4.2.1",
"typescript": "^5.3.3",
"vosk": "^0.3.39",
"wav": "^1.0.2",
"rimraf": "^5.0.5",
"yauzl": "^2.10.0"
},
"devDependencies": {
Expand Down
13 changes: 11 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions processAudio.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import ffmpeg from "fluent-ffmpeg";
import ffmpegInstaller from "@ffmpeg-installer/ffmpeg";
import { join } from "path";
import path 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 fileName = path.basename(inputPath);
const fileNameWithoutExtension = path.basename(inputPath , path.extname(fileName));
const outputPath = join(
workingDir, "from-video", `${Date.now()}-${fileNameWithoutExtension}.wav`,
);
Expand Down
4 changes: 3 additions & 1 deletion splitFilePath.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import path from "path";

export function splitFilePath(filePath: string) {
// Extract the base name (the last part of the path)
const baseName = filePath.split("/").pop();
const baseName = path.basename(filePath);;

if (!baseName) throw new Error("Invalid file path");

Expand Down