ASR logging
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/ai-utils",
|
"name": "@ztimson/ai-utils",
|
||||||
"version": "0.1.12",
|
"version": "0.1.13",
|
||||||
"description": "AI Utility library",
|
"description": "AI Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export class Ai {
|
|||||||
this.llm = new LLM(this, options);
|
this.llm = new LLM(this, options);
|
||||||
if(this.options.whisper?.binary) {
|
if(this.options.whisper?.binary) {
|
||||||
this.whisperModel = this.options.whisper?.model.endsWith('.bin') ? this.options.whisper?.model : this.options.whisper?.model + '.bin';
|
this.whisperModel = this.options.whisper?.model.endsWith('.bin') ? this.options.whisper?.model : this.options.whisper?.model + '.bin';
|
||||||
|
console.log('constructor: ' + this.options.whisper.model + ' -> ' + this.whisperModel);
|
||||||
this.downloadAsrModel();
|
this.downloadAsrModel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,6 +45,8 @@ export class Ai {
|
|||||||
const m = await this.downloadAsrModel(model);
|
const m = await this.downloadAsrModel(model);
|
||||||
const name = Math.random().toString(36).substring(2, 10) + '-' + path.split('/').pop() + '.txt';
|
const name = Math.random().toString(36).substring(2, 10) + '-' + path.split('/').pop() + '.txt';
|
||||||
const output = Path.join(this.options.whisper.temp || '/tmp', name);
|
const output = Path.join(this.options.whisper.temp || '/tmp', name);
|
||||||
|
console.log('ASR: ' + this.options.whisper.model + ' -> ' + 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}`;
|
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)
|
return fs.readFile(output, 'utf-8').then(text => text?.trim() || null)
|
||||||
.finally(() => fs.rm(output, {force: true}).catch(() => {}));
|
.finally(() => fs.rm(output, {force: true}).catch(() => {}));
|
||||||
@@ -59,7 +62,11 @@ export class Ai {
|
|||||||
if(!this.options.whisper?.binary) throw new Error('Whisper not configured');
|
if(!this.options.whisper?.binary) throw new Error('Whisper not configured');
|
||||||
if(!model.endsWith('.bin')) model += '.bin';
|
if(!model.endsWith('.bin')) model += '.bin';
|
||||||
const p = Path.join(this.options.whisper.path, model);
|
const p = Path.join(this.options.whisper.path, model);
|
||||||
if(await fs.stat(p).then(() => true).catch(() => false)) return p;
|
console.log('Download: ' + p);
|
||||||
|
if(await fs.stat(p).then(() => true).catch(() => false)) {
|
||||||
|
console.log('Exists!');
|
||||||
|
return p;
|
||||||
|
}
|
||||||
if(!!this.downloads[model]) return this.downloads[model];
|
if(!!this.downloads[model]) return this.downloads[model];
|
||||||
this.downloads[model] = fetch(`https://huggingface.co/ggerganov/whisper.cpp/resolve/main/${model}`)
|
this.downloads[model] = fetch(`https://huggingface.co/ggerganov/whisper.cpp/resolve/main/${model}`)
|
||||||
.then(resp => resp.arrayBuffer())
|
.then(resp => resp.arrayBuffer())
|
||||||
|
|||||||
Reference in New Issue
Block a user