Fixed ASR whisper models
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/ai-utils",
|
"name": "@ztimson/ai-utils",
|
||||||
"version": "0.1.9",
|
"version": "0.1.10",
|
||||||
"description": "AI Utility library",
|
"description": "AI Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -46,9 +46,6 @@ 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('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}`;
|
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(() => {}));
|
||||||
@@ -62,16 +59,14 @@ export class Ai {
|
|||||||
*/
|
*/
|
||||||
async downloadAsrModel(model?: string): Promise<string> {
|
async downloadAsrModel(model?: string): Promise<string> {
|
||||||
if(!this.options.whisper?.binary) throw new Error('Whisper not configured');
|
if(!this.options.whisper?.binary) throw new Error('Whisper not configured');
|
||||||
let m;
|
const m = model ? (model.endsWith('.bin') ? model : model + '.bin') : this.whisperModel.split('/').pop()!;
|
||||||
if(model) m = model?.endsWith('.bin') ? model : model + '.bin';
|
|
||||||
else m = <string>this.whisperModel.split('/').at(-1);
|
|
||||||
const p = Path.join(this.options.whisper.path, m);
|
const p = Path.join(this.options.whisper.path, m);
|
||||||
if(await fs.stat(p).then(() => true).catch(() => false)) return p;
|
if(await fs.stat(p).then(() => true).catch(() => false)) return p;
|
||||||
if(!!this.downloads[m]) return this.downloads[m];
|
if(!!this.downloads[m]) return this.downloads[m];
|
||||||
this.downloads[m] = fetch(`https://huggingface.co/ggerganov/whisper.cpp/resolve/main/${m}`)
|
this.downloads[m] = fetch(`https://huggingface.co/ggerganov/whisper.cpp/resolve/main/${m}`)
|
||||||
.then(resp => resp.arrayBuffer())
|
.then(resp => resp.arrayBuffer())
|
||||||
.then(arr => Buffer.from(arr)).then(async buffer => {
|
.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];
|
delete this.downloads[m];
|
||||||
return p;
|
return p;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user