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: 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/createTextFromAudioFile.ts b/createTextFromAudioFile.ts index 09ca2b2..14ac2e1 100644 --- a/createTextFromAudioFile.ts +++ b/createTextFromAudioFile.ts @@ -62,6 +62,7 @@ export const createTextFromAudioFile = ( results.push(result); } } + results.push(recognizer.finalResult()); spinner.clear(); recognizer.free(); model.free(); 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/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==} 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");