@codearcade/subtitle-generator 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/init/index.js +67 -36
- package/package.json +1 -1
package/init/index.js
CHANGED
|
@@ -92,49 +92,80 @@ const init = async () => {
|
|
|
92
92
|
// Windows Setup
|
|
93
93
|
const binaryDest = path.join(whisperDir, "whisper-cli.exe");
|
|
94
94
|
if (!fs.existsSync(binaryDest)) {
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
95
|
+
console.log("Detecting Windows architecture...");
|
|
96
|
+
const arch = os.arch(); // Usually 'x64', 'ia32', or 'arm64'
|
|
97
|
+
|
|
98
|
+
let zipName;
|
|
99
|
+
|
|
100
|
+
if (arch === "x64") {
|
|
101
|
+
zipName = "whisper-bin-x64.zip";
|
|
102
|
+
} else if (arch === "ia32") {
|
|
103
|
+
zipName = "whisper-bin-Win32.zip";
|
|
104
|
+
} else if (arch === "arm64") {
|
|
105
|
+
// Windows ARM can emulate x64 executables
|
|
106
|
+
console.log(
|
|
107
|
+
"ARM64 architecture detected. Using x64 binary via Windows emulation...",
|
|
108
|
+
);
|
|
109
|
+
zipName = "whisper-bin-x64.zip";
|
|
110
|
+
} else {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`Unsupported Windows architecture: ${arch}. Whisper.cpp does not provide pre-compiled binaries for this system.`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// https://github.com/ggml-org/whisper.cpp/releases/download/v1.8.4/whisper-bin-Win32.zip
|
|
117
|
+
// https://github.com/ggml-org/whisper.cpp/releases/v1.8.4/download/whisper-bin-Win32.zip
|
|
118
|
+
|
|
119
|
+
const zipUrl = `https://github.com/ggml-org/whisper.cpp/releases/download/v1.8.4/${zipName}`;
|
|
98
120
|
const zipPath = path.join(whisperDir, "whisper.zip");
|
|
99
121
|
|
|
100
|
-
await downloadFile(zipUrl, zipPath,
|
|
122
|
+
await downloadFile(zipUrl, zipPath, `Whisper Windows Binary (${arch})`);
|
|
101
123
|
|
|
102
124
|
console.log("Extracting binary...");
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
fs.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
// Use PowerShell instead of tar to avoid the Windows bsdtar decompression bug
|
|
128
|
+
execSync(
|
|
129
|
+
`powershell -command "Expand-Archive -Force -LiteralPath '${zipPath}' -DestinationPath '${whisperDir}'"`,
|
|
130
|
+
{ stdio: "inherit" },
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
// 1. Move everything out of the "Release" folder
|
|
134
|
+
const possibleReleaseDir = path.join(whisperDir, "Release");
|
|
135
|
+
|
|
136
|
+
if (fs.existsSync(possibleReleaseDir)) {
|
|
137
|
+
const files = fs.readdirSync(possibleReleaseDir);
|
|
138
|
+
|
|
139
|
+
for (const file of files) {
|
|
140
|
+
fs.renameSync(
|
|
141
|
+
path.join(possibleReleaseDir, file),
|
|
142
|
+
path.join(whisperDir, file),
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
// Delete the now-empty Release folder
|
|
146
|
+
fs.rmdirSync(possibleReleaseDir);
|
|
119
147
|
}
|
|
120
|
-
// Delete the now-empty Release folder
|
|
121
|
-
fs.rmdirSync(possibleReleaseDir);
|
|
122
|
-
}
|
|
123
148
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
149
|
+
// 2. Rename extracted main.exe to match our wrapper expectations
|
|
150
|
+
const extractedMain = path.join(whisperDir, "main.exe");
|
|
151
|
+
if (fs.existsSync(extractedMain)) {
|
|
152
|
+
fs.renameSync(extractedMain, binaryDest);
|
|
153
|
+
} else {
|
|
154
|
+
console.error("Warning: Could not find main.exe after extraction.");
|
|
155
|
+
}
|
|
131
156
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
157
|
+
// 3. Clean up the zip file
|
|
158
|
+
if (fs.existsSync(zipPath)) {
|
|
159
|
+
fs.unlinkSync(zipPath);
|
|
160
|
+
}
|
|
136
161
|
|
|
137
|
-
|
|
162
|
+
console.log(`Whisper binary setup complete for Windows (${arch}).`);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.error(
|
|
165
|
+
"Extraction failed. Please ensure PowerShell is available.",
|
|
166
|
+
error.message,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
138
169
|
} else {
|
|
139
170
|
console.log("Whisper binary already exists for Windows.");
|
|
140
171
|
}
|
|
@@ -151,7 +182,7 @@ const init = async () => {
|
|
|
151
182
|
if (!fs.existsSync(repoDir)) {
|
|
152
183
|
// Shallow clone to save time and bandwidth
|
|
153
184
|
execSync(
|
|
154
|
-
`git clone --depth 1 https://github.com/
|
|
185
|
+
`git clone --depth 1 https://github.com/ggml-org/whisper.cpp.git "${repoDir}"`,
|
|
155
186
|
{ stdio: "inherit" },
|
|
156
187
|
);
|
|
157
188
|
}
|