Fixed ASR whisper models
All checks were successful
Publish Library / Build NPM Project (push) Successful in 30s
Publish Library / Tag Version (push) Successful in 7s

This commit is contained in:
2025-12-13 22:47:35 -05:00
parent af4b09173c
commit d69bea3b38
2 changed files with 3 additions and 8 deletions

View File

@@ -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<string> {
if(!this.options.whisper?.binary) throw new Error('Whisper not configured');
let m;
if(model) m = model?.endsWith('.bin') ? model : model + '.bin';
else m = <string>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((<any>this.options.whisper).path, m), buffer);
await fs.writeFile(p, buffer);
delete this.downloads[m];
return p;
});