Skip to content

Commit 8f5c8bf

Browse files
committed
feat: add modelsname check and logs
1 parent 8fc0a73 commit 8f5c8bf

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodejs-whisper",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "Node bindings for OpenAI's Whisper. Optimized for CPU.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/WhisperHelper.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ export const constructCommand = (filePath: string, args: IOptions) => {
88
throw new Error('[Nodejs-whisper] Error: Provide model name')
99
}
1010

11+
const isValidModelName = MODELS_LIST.findIndex(model => model == args.modelName)
12+
13+
if (isValidModelName == -1) {
14+
console.log('[Nodejs-whisper] Error: Enter a valid model name')
15+
console.log('[Nodejs-whisper] Available models are:\n', MODELS_LIST)
16+
process.exit(1)
17+
}
18+
1119
let anyModelExist = []
1220

1321
MODELS.forEach(model => {

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface IOptions {
1212

1313
export async function nodewhisper(filePath: string, options: IOptions) {
1414
checkIfFileExists(filePath)
15+
console.log(`[Nodejs-whisper] Transcribing file: ${filePath}\n`)
1516
await downloadModel()
1617

1718
const outputFilePath = await convertToWavType(filePath)

src/utils.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import fs from 'fs'
22
import path from 'path'
33
import shell from 'shelljs'
4-
export const checkIfFileExists = (filePath: string) => {
5-
fs.access(filePath, fs.constants.F_OK, err => {
6-
if (err) {
7-
console.error(`[Nodejs-whisper] Error: No such file or directory: ${filePath}\n`)
8-
process.exit(1)
9-
}
10-
})
4+
5+
export const checkIfFileExists = async (filePath: string) => {
6+
const isExist = fs.existsSync(filePath)
7+
8+
if (!isExist) {
9+
console.error(`[Nodejs-whisper] Error: No such file : ${filePath}\n`)
10+
process.exit(1)
11+
}
1112
}
1213

1314
export const convertToWavType = async (inputFilePath: string) => {
@@ -19,9 +20,9 @@ export const convertToWavType = async (inputFilePath: string) => {
1920
)
2021

2122
if (fileExtension !== 'wav') {
22-
console.warn('[Nodejs-whisper] Warning: Unsupported audio format.')
23+
console.warn('[Nodejs-whisper] Warning: Unsupported audio format.\n')
2324
console.log('[Nodejs-whisper] Converting audio to wav File Type...\n')
24-
const command = `ffmpeg -i ${inputFilePath} -ar 16000 -ac 1 -c:a pcm_s16le ${outputFilePath}.wav`
25+
const command = `ffmpeg -nostats -loglevel 0 -i ${inputFilePath} -ar 16000 -ac 1 -c:a pcm_s16le ${outputFilePath}.wav`
2526

2627
shell.exec(command)
2728
return `${outputFilePath}.wav`

0 commit comments

Comments
 (0)