From d69bea3b38a1c687042e0aacd3253f5018b999f9 Mon Sep 17 00:00:00 2001 From: ztimson Date: Sat, 13 Dec 2025 22:47:35 -0500 Subject: [PATCH] Fixed ASR whisper models --- package.json | 2 +- src/ai.ts | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 80d6a55..667ec55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/ai-utils", - "version": "0.1.9", + "version": "0.1.10", "description": "AI Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/ai.ts b/src/ai.ts index 074ab5b..35045b0 100644 --- a/src/ai.ts +++ b/src/ai.ts @@ -46,9 +46,6 @@ export class Ai { const m = await this.downloadAsrModel(model); const name = Math.random().toString(36).substring(2, 10) + '-' + path.split('/').pop() + '.txt'; const output = Path.join(this.options.whisper.temp || '/tmp', name); - console.log('model:', this.options.whisper?.model); - console.log(this.whisperModel); - console.log(`rm -f ${output} && ${this.options.whisper.binary} -nt -np -m ${m} -f ${path} -otxt -of ${output}`); await $`rm -f ${output} && ${this.options.whisper.binary} -nt -np -m ${m} -f ${path} -otxt -of ${output}`; return fs.readFile(output, 'utf-8').then(text => text?.trim() || null) .finally(() => fs.rm(output, {force: true}).catch(() => {})); @@ -62,16 +59,14 @@ export class Ai { */ async downloadAsrModel(model?: string): Promise { if(!this.options.whisper?.binary) throw new Error('Whisper not configured'); - let m; - if(model) m = model?.endsWith('.bin') ? model : model + '.bin'; - else m = this.whisperModel.split('/').at(-1); + const m = model ? (model.endsWith('.bin') ? model : model + '.bin') : this.whisperModel.split('/').pop()!; const p = Path.join(this.options.whisper.path, m); if(await fs.stat(p).then(() => true).catch(() => false)) return p; if(!!this.downloads[m]) return this.downloads[m]; this.downloads[m] = fetch(`https://huggingface.co/ggerganov/whisper.cpp/resolve/main/${m}`) .then(resp => resp.arrayBuffer()) .then(arr => Buffer.from(arr)).then(async buffer => { - await fs.writeFile(Path.join((this.options.whisper).path, m), buffer); + await fs.writeFile(p, buffer); delete this.downloads[m]; return p; });