@@ -61,6 +61,11 @@ export const install = (event, source) => {
61
61
url : repoUrl ,
62
62
singleBranch : true ,
63
63
depth : 1 ,
64
+ onProgress : ( res ) => {
65
+ if ( res . total ) {
66
+ event . sender . send ( "installWhisperProgress" , res . phase , res . loaded / res . total ) ;
67
+ }
68
+ } ,
64
69
} )
65
70
. then ( ( res ) => {
66
71
if ( checkWhisperInstalled ( ) ) {
@@ -80,50 +85,6 @@ export const install = (event, source) => {
80
85
} ) ;
81
86
} ;
82
87
83
- export const downModel = async (
84
- event ,
85
- whisperModel ,
86
- source = "hf-mirror.com" ,
87
- ) => {
88
- const { modelsPath } = getPath ( ) ;
89
- const modelName = whisperModel ?. toLowerCase ( ) ;
90
- const modelPath = path . join ( modelsPath , `ggml-${ modelName } .bin` ) ;
91
- if ( fs . existsSync ( modelPath ) ) return ;
92
- if ( ! checkWhisperInstalled ( ) ) {
93
- event . sender . send ( "message" , "whisper.cpp 未下载,请先下载 whisper.cpp" ) ;
94
- }
95
- try {
96
- let downShellPath ;
97
- let shell : string ;
98
- if ( isDarwin ( ) ) {
99
- downShellPath = path . join ( modelsPath , "download-ggml-model.sh" ) ;
100
- shell = "bash" ;
101
- } else if ( isWin32 ( ) ) {
102
- downShellPath = path . join ( modelsPath , "download-ggml-model.cmd" ) ;
103
- shell = "cmd.exe /c" ;
104
- } else {
105
- throw Error ( "platform does not support! " ) ;
106
- }
107
- await replaceModelSource ( `${ downShellPath } ` , source ) ;
108
- console . log ( "完成模型下载地址替换" , modelName ) ;
109
- console . log ( "正在安装 whisper.cpp 模型" ) ;
110
- exec ( `${ shell } "${ downShellPath } " ${ modelName } ` , ( err , stdout ) => {
111
- if ( err ) {
112
- event . sender . send ( "message" , err ) ;
113
- } else {
114
- event . sender . send ( "message" , `模型 ${ modelName } 下载完成` ) ;
115
- }
116
- event . sender . send ( "downModelComplete" , ! err ) ;
117
- event . sender . send ( "getSystemInfoComplete" , {
118
- whisperInstalled : checkWhisperInstalled ( ) ,
119
- modelsInstalled : getModelsInstalled ( ) ,
120
- } ) ;
121
- } ) ;
122
- } catch ( error ) {
123
- event . sender . send ( "message" , error ) ;
124
- }
125
- } ;
126
-
127
88
export const makeWhisper = ( event ) => {
128
89
const { whisperPath, mainPath } = getPath ( ) ;
129
90
if ( fs . existsSync ( mainPath ) || isWin32 ( ) ) {
@@ -133,6 +94,7 @@ export const makeWhisper = (event) => {
133
94
if ( ! checkWhisperInstalled ( ) ) {
134
95
event . sender . send ( "message" , "whisper.cpp 未下载,请先下载 whisper.cpp" ) ;
135
96
}
97
+ event . sender . send ( "beginMakeWhisper" , true ) ;
136
98
exec ( `make -C "${ whisperPath } "` , ( err , stdout ) => {
137
99
if ( err ) {
138
100
event . sender . send ( "message" , err ) ;
@@ -168,22 +130,23 @@ export const downloadModelSync = async (model, source, onProcess) => {
168
130
try {
169
131
let downShellPath ;
170
132
let shell : string ;
133
+ let args = [ ] ;
171
134
if ( isDarwin ( ) ) {
172
135
downShellPath = path . join ( modelsPath , "download-ggml-model.sh" ) ;
173
136
shell = "bash" ;
137
+ args = [ `${ downShellPath } ` , `${ model } ` ] ;
174
138
} else if ( isWin32 ( ) ) {
175
139
downShellPath = path . join ( modelsPath , "download-ggml-model.cmd" ) ;
176
- shell = "cmd.exe /c" ;
140
+ shell = "cmd" ;
141
+ args = [ `/c` , `${ downShellPath } ` , `${ model } ` ] ;
177
142
} else {
178
143
throw Error ( "platform does not support! " ) ;
179
144
}
180
145
await replaceModelSource ( `${ downShellPath } ` , source ) ;
181
146
console . log ( "完成模型下载地址替换" , model ) ;
182
147
console . log ( "正在安装 whisper.cpp 模型" ) ;
183
148
try {
184
- await runCommand ( `${ shell } ` , [ `${ downShellPath } ` , `${ model } ` ] , ( data ) =>
185
- onProcess ( data ) ,
186
- ) ;
149
+ await runCommand ( `${ shell } ` , args , ( data ) => onProcess ( data ) ) ;
187
150
} catch ( error ) {
188
151
await deleteModel ( model ) ;
189
152
throw error ;
0 commit comments