Updataes?
All checks were successful
Publish Library / Build NPM Project (push) Successful in 26s
Publish Library / Tag Version (push) Successful in 5s

This commit is contained in:
2026-02-12 20:14:00 -05:00
parent ad1ee48763
commit e4399e1b7b
4 changed files with 12 additions and 15 deletions

View File

@@ -1,18 +1,18 @@
import {Worker} from 'worker_threads';
import path from 'node:path';
import Path from 'node:path';
import {AbortablePromise, Ai} from './ai.ts';
import {canDiarization} from './asr.ts';
export class Audio {
constructor(private ai: Ai) {}
asr(filepath: string, options: { model?: string; speaker?: boolean } = {}): AbortablePromise<string | null> {
asr(file: string, options: { model?: string; speaker?: boolean } = {}): AbortablePromise<string | null> {
const { model = this.ai.options.asr || 'whisper-base', speaker = false } = options;
let aborted = false;
const abort = () => { aborted = true; };
const p = new Promise<string | null>((resolve, reject) => {
const worker = new Worker(path.join(import.meta.dirname, 'asr.js'));
const worker = new Worker(Path.join(import.meta.dirname, 'asr.js'));
const handleMessage = ({ text, warning, error }: any) => {
worker.terminate();
if(aborted) return;
@@ -31,7 +31,7 @@ export class Audio {
worker.on('exit', (code) => {
if(code !== 0 && !aborted) reject(new Error(`Worker exited with code ${code}`));
});
worker.postMessage({path: filepath, model, speaker, torchHome: this.ai.options.path,});
worker.postMessage({file, model, speaker, modelDir: this.ai.options.path});
});
return Object.assign(p, { abort });
}