@@ -4,10 +4,14 @@ import fs from 'fs'
44import { MODELS , MODELS_LIST , MODEL_OBJECT } from './constants'
55
66export const constructCommand = ( filePath : string , args : IOptions ) => {
7+ if ( args ?. modelName == undefined ) {
8+ throw new Error ( '[Nodejs-whisper] Error: Provide model name' )
9+ }
10+
711 let anyModelExist = [ ]
812
913 MODELS . forEach ( model => {
10- if ( ! fs . existsSync ( path . join ( __dirname , '..' , 'cpp' , 'whisper.cpp' , 'models' , MODEL_OBJECT [ args . modelName ] ) ) ) {
14+ if ( ! fs . existsSync ( path . join ( __dirname , '..' , 'cpp' , 'whisper.cpp' , 'models' , MODEL_OBJECT [ args ? .modelName ] ) ) ) {
1115 } else {
1216 anyModelExist . push ( model )
1317 }
@@ -20,10 +24,19 @@ export const constructCommand = (filePath: string, args: IOptions) => {
2024
2125 const modelName = MODEL_OBJECT [ args . modelName as keyof typeof MODEL_OBJECT ]
2226
23- if ( MODELS_LIST . indexOf ( args . modelName ) === - 1 ) {
27+ if ( MODELS_LIST . indexOf ( args ? .modelName ) === - 1 ) {
2428 throw new Error ( '[Nodejs-whisper] Error: Model not found' )
2529 }
26- let command = `./main ${ constructOptionsFlags ( args ) } -l auto -m ./models/${ modelName } -f ${ filePath } `
30+
31+ const defaultOutput =
32+ ! args ?. whisperOptions ?. outputInCsv &&
33+ ! args ?. whisperOptions ?. outputInSrt &&
34+ ! args ?. whisperOptions ?. outputInText &&
35+ ! args ?. whisperOptions ?. outputInVtt
36+
37+ let command = `./main ${ constructOptionsFlags ( args ) } ${
38+ defaultOutput && '-osrt'
39+ } -l auto -m ./models/${ modelName } -f ${ filePath } `
2740
2841 return command
2942}
@@ -51,7 +64,7 @@ const constructOptionsFlags = (args: IOptions) => {
5164 if ( args ?. whisperOptions ?. timestamps_length ) {
5265 flag += `-ml ${ args . whisperOptions . timestamps_length } `
5366 }
54- if ( args . whisperOptions . splitOnWord ) {
67+ if ( args ? .whisperOptions ? .splitOnWord ) {
5568 flag += `-sow true `
5669 }
5770 return flag
0 commit comments