Fixed ASR whisper models
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user