From 6ad5f20725c08e30a321654b107bdea74d6c29ca Mon Sep 17 00:00:00 2001 From: Michael Gorini Date: Thu, 4 Sep 2025 09:22:06 +0200 Subject: [PATCH] fix whisper download --- RecorderService.ts | 8 +++++--- settings.ts | 38 +++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/RecorderService.ts b/RecorderService.ts index c99b08b..4fbcc07 100644 --- a/RecorderService.ts +++ b/RecorderService.ts @@ -588,10 +588,12 @@ export class RecorderService { const lang = (whisperLanguage || "auto").trim(); if (lang && lang !== "auto") { args.push("-l", lang); } - // Parametri anti-loop per chunk + // Parametri anti-loop + accuratezza args.push("--max-context", "128", "--entropy-thold", "2.4", "--logprob-thold", "-1.0", "--max-len", "0"); - args.push("--max-context", "128", "--entropy-thold", "2.4", "--logprob-thold", "-1.0", "--max-len", "0"); - args.push("--best-of", "1", "--no-timestamps", "--word-thold", "0.01"); + // Beam search per maggiore accuratezza (più lento) + args.push("-bs", "5"); + // Manteniamo i timestamp (niente --no-timestamps) per aiutare il decoder + args.push("--word-thold", "0.01"); // Output su file temporaneo const tempTxtPath = chunkPath.replace(/\.mp3$/i, ".txt"); diff --git a/settings.ts b/settings.ts index 9036a20..4bf02d6 100644 --- a/settings.ts +++ b/settings.ts @@ -531,11 +531,13 @@ export class ResonanceSettingTab extends PluginSettingTab { private async downloadModelPreset(): Promise { const preset = this.settings.whisperModelPreset || 'medium'; - const url = preset === 'small' - ? 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.bin' + const fileName = preset === 'small' + ? 'ggml-small.bin' : preset === 'large' - ? 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large.bin' - : 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium.bin'; + ? 'ggml-large-v3.bin' + : 'ggml-medium.bin'; + const baseUrl = 'https://huggingface.co/ggerganov/whisper.cpp/resolve/main/'; + const url = `${baseUrl}${fileName}?download=true`; const path = (window as any).require('path'); const fs = (window as any).require('fs'); @@ -546,19 +548,25 @@ export class ResonanceSettingTab extends PluginSettingTab { if (!modelsDir) throw new Error('Set the repo folder first or provide a model path'); try { fs.mkdirSync(modelsDir, { recursive: true }); } catch {} - const outFile = path.join(modelsDir, url.split('/').pop()); + const outFile = path.join(modelsDir, fileName); await new Promise((resolve, reject) => { - const file = fs.createWriteStream(outFile); - https.get(url, (res: any) => { - if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { - https.get(res.headers.location, (res2: any) => res2.pipe(file).on('finish', resolve)).on('error', reject); - } else if (res.statusCode === 200) { - res.pipe(file).on('finish', resolve); - } else { - reject(new Error('HTTP ' + res.statusCode)); - } - }).on('error', reject); + const follow = (u: string, depth: number) => { + if (depth > 5) return reject(new Error('Too many redirects')); + https.get(u, (res: any) => { + if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { + const next = res.headers.location.startsWith('http') ? res.headers.location : new URL(res.headers.location, u).toString(); + return follow(next, depth + 1); + } + if (res.statusCode === 200) { + const file = fs.createWriteStream(outFile); + res.pipe(file).on('finish', resolve).on('error', reject); + } else { + reject(new Error('HTTP ' + res.statusCode)); + } + }).on('error', reject); + }; + follow(url, 0); }); return outFile;