Skip to content
Snippets Groups Projects
Unverified Commit fab74037 authored by Timothy Carambat's avatar Timothy Carambat Committed by GitHub
Browse files

Prevent collector crash when blocked by CDN (#3373)

resolves #3365
parent df166eb6
No related branches found
No related tags found
No related merge requests found
...@@ -153,9 +153,9 @@ class LocalWhisper { ...@@ -153,9 +153,9 @@ class LocalWhisper {
try { try {
// Convert ESM to CommonJS via import so we can load this library. // Convert ESM to CommonJS via import so we can load this library.
const pipeline = (...args) => const pipeline = (...args) =>
import("@xenova/transformers").then(({ pipeline }) => import("@xenova/transformers").then(({ pipeline }) => {
pipeline(...args) return pipeline(...args);
); });
return await pipeline("automatic-speech-recognition", this.model, { return await pipeline("automatic-speech-recognition", this.model, {
cache_dir: this.cacheDir, cache_dir: this.cacheDir,
...(!fs.existsSync(this.modelPath) ...(!fs.existsSync(this.modelPath)
...@@ -173,16 +173,22 @@ class LocalWhisper { ...@@ -173,16 +173,22 @@ class LocalWhisper {
: {}), : {}),
}); });
} catch (error) { } catch (error) {
this.#log("Failed to load the native whisper model:", error); let errMsg = error.message;
throw error; if (errMsg.includes("Could not locate file")) {
errMsg =
"The native whisper model failed to download from the huggingface.co CDN. Your internet connection may be unstable or blocked by Huggingface.co - you will need to download the model manually and place it in the storage/models folder to use local Whisper transcription.";
}
this.#log(
`Failed to load the native whisper model: ${errMsg}`,
error.stack
);
throw new Error(errMsg);
} }
} }
async processFile(fullFilePath, filename) { async processFile(fullFilePath, filename) {
try { try {
const transcriberPromise = new Promise((resolve) =>
this.client().then((client) => resolve(client))
);
const audioDataPromise = new Promise((resolve) => const audioDataPromise = new Promise((resolve) =>
this.#convertToWavAudioData(fullFilePath).then((audioData) => this.#convertToWavAudioData(fullFilePath).then((audioData) =>
resolve(audioData) resolve(audioData)
...@@ -190,7 +196,7 @@ class LocalWhisper { ...@@ -190,7 +196,7 @@ class LocalWhisper {
); );
const [audioData, transcriber] = await Promise.all([ const [audioData, transcriber] = await Promise.all([
audioDataPromise, audioDataPromise,
transcriberPromise, this.client(),
]); ]);
if (!audioData) { if (!audioData) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment