Skip to content

Commit 606d5be

Browse files
committed
Merge branch 'fix-paths' into ci-integraton-and-fixes
2 parents 8c5c50c + 3e23840 commit 606d5be

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

src/WhisperHelper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path'
22

33
import fs from 'fs'
4-
import { MODELS, MODELS_LIST, MODEL_OBJECT } from './constants'
4+
import { MODELS_LIST, MODEL_OBJECT, WHISPER_CPP_PATH, WHISPER_CPP_MAIN_PATH } from './constants'
55
import { IOptions } from '.'
66

77
export const constructCommand = (filePath: string, args: IOptions): string => {
@@ -15,7 +15,7 @@ export const constructCommand = (filePath: string, args: IOptions): string => {
1515
errors.push(`[Nodejs-whisper] Error: Enter a valid model name. Available models are: ${MODELS_LIST.join(', ')}`)
1616
}
1717

18-
const modelPath = path.join(__dirname, '..', 'cpp', 'whisper.cpp', 'models', MODEL_OBJECT[args.modelName])
18+
const modelPath = path.join(WHISPER_CPP_PATH, 'models', MODEL_OBJECT[args.modelName])
1919
if (!fs.existsSync(modelPath)) {
2020
errors.push(
2121
'[Nodejs-whisper] Error: Model file does not exist. Please ensure the model is downloaded and correctly placed.'
@@ -27,7 +27,7 @@ export const constructCommand = (filePath: string, args: IOptions): string => {
2727
}
2828

2929
const modelName = MODEL_OBJECT[args.modelName as keyof typeof MODEL_OBJECT]
30-
let command = `./main ${constructOptionsFlags(args)} -l ${args.whisperOptions?.language ? args.whisperOptions?.language : 'auto'} -m "./models/${modelName}" -f "${filePath}"`
30+
let command = `${WHISPER_CPP_MAIN_PATH} ${constructOptionsFlags(args)} -l ${args.whisperOptions?.language ? args.whisperOptions?.language : 'auto'} -m "./models/${modelName}" -f "${filePath}"`
3131

3232
return command
3333
}

src/autoDownloadModel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path'
22
import shell from 'shelljs'
33
import fs from 'fs'
4-
import { MODELS_LIST, MODELS } from './constants'
4+
import { MODEL_OBJECT, MODELS_LIST, WHISPER_CPP_PATH } from './constants'
55

66
export default async function autoDownloadModel(
77
logger = console,
@@ -19,9 +19,9 @@ export default async function autoDownloadModel(
1919
}
2020

2121
try {
22-
const modelDirectory = path.join(__dirname, '..', 'cpp', 'whisper.cpp', 'models')
22+
const modelDirectory = path.join(WHISPER_CPP_PATH, 'models')
2323
shell.cd(modelDirectory)
24-
const modelAlreadyExist = fs.existsSync(path.join(modelDirectory, autoDownloadModelName))
24+
const modelAlreadyExist = fs.existsSync(path.join(modelDirectory, MODEL_OBJECT[autoDownloadModelName]))
2525

2626
if (modelAlreadyExist) {
2727
logger.debug(`[Nodejs-whisper] ${autoDownloadModel} already exist. Skipping download.`)

src/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from 'path'
2+
13
export const MODELS_LIST = [
24
'tiny',
35
'tiny.en',
@@ -41,3 +43,6 @@ export const MODEL_OBJECT = {
4143
}
4244

4345
export const DEFAULT_MODEL = 'tiny.en'
46+
47+
export const WHISPER_CPP_PATH = path.join(__dirname, '..', 'cpp', 'whisper.cpp')
48+
export const WHISPER_CPP_MAIN_PATH = './build/bin/whisper-cli'

src/downloadModel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import path from 'path'
66
import shell from 'shelljs'
77
import readlineSync from 'readline-sync'
8-
import { MODELS_LIST, DEFAULT_MODEL, MODELS } from './constants'
8+
import { MODELS_LIST, DEFAULT_MODEL, MODELS, WHISPER_CPP_PATH, MODEL_OBJECT } from './constants'
99
import fs from 'fs'
1010

1111
const askForModel = async (logger = console): Promise<string> => {
@@ -48,12 +48,12 @@ const askIfUserWantToUseCuda = async (logger = console) => {
4848

4949
async function downloadModel(logger = console) {
5050
try {
51-
shell.cd(path.join(__dirname, '..', './cpp/whisper.cpp/models'))
51+
shell.cd(path.join(WHISPER_CPP_PATH, 'models'))
5252

5353
let anyModelExist = []
5454

5555
MODELS.forEach(model => {
56-
if (!fs.existsSync(path.join(__dirname, '..', `./cpp/whisper.cpp/models/${model}`))) {
56+
if (!fs.existsSync(path.join(WHISPER_CPP_PATH, 'models', MODEL_OBJECT[model]))) {
5757
} else {
5858
anyModelExist.push(model)
5959
}

src/whisper.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import fs from 'fs'
2-
import path from 'path'
31
import shell from 'shelljs'
4-
import { MODELS } from './constants'
2+
import { WHISPER_CPP_PATH, WHISPER_CPP_MAIN_PATH } from './constants'
53

6-
const WHISPER_CPP_PATH = path.join(__dirname, '..', 'cpp', 'whisper.cpp')
7-
const WHISPER_CPP_MAIN_PATH = './main'
84
const projectDir = process.cwd()
95

106
export interface IShellOptions {

0 commit comments

Comments
 (0)