|
1 |
| -import { exec } from "child_process"; |
| 1 | +import { exec, spawn } from "child_process"; |
2 | 2 | import { app } from "electron";
|
3 | 3 | import path from "path";
|
4 | 4 | import fs from "fs";
|
5 | 5 | import git from "isomorphic-git";
|
6 | 6 | import http from "isomorphic-git/http/node";
|
7 | 7 | import replaceModelSource from "./model-source";
|
8 | 8 | import { isDarwin, isWin32 } from "./utils";
|
| 9 | +import { log } from "console"; |
9 | 10 |
|
10 | 11 | export const getPath = (key?: string) => {
|
11 | 12 | const userDataPath = app.getPath("userData");
|
@@ -170,15 +171,40 @@ export const downloadModelSync = async (model, source) => {
|
170 | 171 | console.log("完成模型下载地址替换", model);
|
171 | 172 | console.log("正在安装 whisper.cpp 模型");
|
172 | 173 | return new Promise((resolve, reject) => {
|
173 |
| - exec(`${shell} "${downShellPath}" ${model}`, (err, stdout) => { |
174 |
| - if (err) { |
175 |
| - reject(err); |
176 |
| - } else { |
177 |
| - resolve('ok') |
178 |
| - } |
179 |
| - }); |
| 174 | + exec(`${shell} "${downShellPath}" ${model}`, (err, stdout) => { |
| 175 | + if (err) { |
| 176 | + reject(err); |
| 177 | + } else { |
| 178 | + resolve('ok') |
| 179 | + } |
| 180 | + }); |
180 | 181 | })
|
181 | 182 | } catch (error) {
|
182 |
| - console.log(error) |
| 183 | + console.log(error) |
183 | 184 | }
|
184 | 185 | };
|
| 186 | + |
| 187 | + |
| 188 | +export async function checkOpanAiWhisper() { |
| 189 | + return new Promise((resolve, reject) => { |
| 190 | + let env = process.env; |
| 191 | + env.PYTHONIOENCODING = 'UTF-8'; |
| 192 | + const childProcess = spawn('whisper', ['-h'], { env: env }); |
| 193 | + childProcess.on('error', (error: { code: string }) => { |
| 194 | + if (error.code === 'ENOENT') { |
| 195 | + resolve(false); |
| 196 | + } else { |
| 197 | + reject(error); |
| 198 | + } |
| 199 | + }); |
| 200 | + childProcess.on('exit', (code) => { |
| 201 | + console.log('code: ', code); |
| 202 | + if (code === 0) { |
| 203 | + console.log('openai whisper ready') |
| 204 | + resolve(true); |
| 205 | + } else { |
| 206 | + resolve(false); |
| 207 | + } |
| 208 | + }); |
| 209 | + }); |
| 210 | +} |
0 commit comments