From 1422f4135582abdd408773d077e0508643f1d473 Mon Sep 17 00:00:00 2001 From: iceberg53 Date: Wed, 31 Jan 2024 17:43:27 +0100 Subject: [PATCH 1/3] Add instructions on how to install gen-subs Add explicitly the shell command to run for installing gen-subs to make it easier for those new to the nodejs ecosystem. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index bcfb8b4..4616368 100644 --- a/README.md +++ b/README.md @@ -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: From e7d7b6217207eff3e11d4986a4bc1d9f995531e7 Mon Sep 17 00:00:00 2001 From: iceberg53 Date: Sat, 10 Feb 2024 10:38:56 +0100 Subject: [PATCH 2/3] Added local typescript dependency --- package.json | 3 ++- pnpm-lock.yaml | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d93f9d3..e9e0a54 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7cf820e..112b479 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,6 +32,9 @@ dependencies: subtitle: specifier: ^4.2.1 version: 4.2.1 + typescript: + specifier: ^5.3.3 + version: 5.3.3 vosk: specifier: ^0.3.39 version: 0.3.39 @@ -69,7 +72,7 @@ devDependencies: version: 3.1.0 tsup: specifier: ^8.0.0 - version: 8.0.0 + version: 8.0.0(typescript@5.3.3) packages: @@ -1894,7 +1897,7 @@ packages: /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} - /tsup@8.0.0: + /tsup@8.0.0(typescript@5.3.3): resolution: {integrity: sha512-9rOGn8LsFn2iAg2pCB1jnH7ygVuGjlzIomjw0jKXUxAii3iL5cXgm0jZMPKfFH1bSAjQovJ1DUVPSw+oDuIu8A==} engines: {node: '>=18'} hasBin: true @@ -1927,6 +1930,7 @@ packages: source-map: 0.8.0-beta.0 sucrase: 3.34.0 tree-kill: 1.2.2 + typescript: 5.3.3 transitivePeerDependencies: - supports-color - ts-node @@ -1937,6 +1941,11 @@ packages: engines: {node: '>=10'} dev: false + /typescript@5.3.3: + resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} + engines: {node: '>=14.17'} + hasBin: true + /undici-types@5.26.5: resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} From f1b82491c00e8d48b56ca5d3d378422e5f2d04ad Mon Sep 17 00:00:00 2001 From: iceberg53 Date: Sat, 10 Feb 2024 12:33:53 +0100 Subject: [PATCH 3/3] Fix issue #8 : FFMPEG exit with code 1 - Invalid argument This commit mainly replaces the use of custom string manipulation by functions from the path module from node ( path.basename(), path.resolve(), path.extname(), ...) . It's done to account for Windows OS file paths ("C:\\folder\\subfolder\\file.ext") which are different from POSIX ones ("/home/user/folder/file.ext") . That difference led to file names with character sequences that caused an error when calling ffmpeg. --- actions/for.ts | 3 ++- extractAudio.ts | 5 +++-- processAudio.ts | 5 +++-- splitFilePath.ts | 4 +++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/actions/for.ts b/actions/for.ts index 0408e0d..92bafea 100644 --- a/actions/for.ts +++ b/actions/for.ts @@ -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"; @@ -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() diff --git a/extractAudio.ts b/extractAudio.ts index 3d8b60e..4316316 100644 --- a/extractAudio.ts +++ b/extractAudio.ts @@ -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 { 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", diff --git a/processAudio.ts b/processAudio.ts index 5f326df..9859ed7 100644 --- a/processAudio.ts +++ b/processAudio.ts @@ -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 { - 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`, ); diff --git a/splitFilePath.ts b/splitFilePath.ts index 9c60c07..7fbfd15 100644 --- a/splitFilePath.ts +++ b/splitFilePath.ts @@ -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");