audio worker fix
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/ai-utils",
|
"name": "@ztimson/ai-utils",
|
||||||
"version": "0.6.8",
|
"version": "0.6.9",
|
||||||
"description": "AI Utility library",
|
"description": "AI Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
|
import {fileURLToPath} from 'url';
|
||||||
import {Worker} from 'worker_threads';
|
import {Worker} from 'worker_threads';
|
||||||
import Path from 'node:path';
|
|
||||||
import {AbortablePromise, Ai} from './ai.ts';
|
import {AbortablePromise, Ai} from './ai.ts';
|
||||||
import {canDiarization} from './asr.ts';
|
import {canDiarization} from './asr.ts';
|
||||||
|
import {dirname, join} from 'path';
|
||||||
|
|
||||||
export class Audio {
|
export class Audio {
|
||||||
constructor(private ai: Ai) {}
|
constructor(private ai: Ai) {}
|
||||||
|
|
||||||
asr(file: string, options: { model?: string; speaker?: boolean } = {}): AbortablePromise<string | null> {
|
asr(file: string, options: { model?: string; speaker?: boolean } = {}): AbortablePromise<string | null> {
|
||||||
console.log('audio', file);
|
|
||||||
const { model = this.ai.options.asr || 'whisper-base', speaker = false } = options;
|
const { model = this.ai.options.asr || 'whisper-base', speaker = false } = options;
|
||||||
let aborted = false;
|
let aborted = false;
|
||||||
const abort = () => { aborted = true; };
|
const abort = () => { aborted = true; };
|
||||||
|
|
||||||
const p = new Promise<string | null>((resolve, reject) => {
|
const p = new Promise<string | null>((resolve, reject) => {
|
||||||
const worker = new Worker(Path.join(import.meta.dirname, 'asr.js'));
|
const worker = new Worker(join(dirname(fileURLToPath(import.meta.url)), 'asr.js'));
|
||||||
const handleMessage = ({ text, warning, error }: any) => {
|
const handleMessage = ({ text, warning, error }: any) => {
|
||||||
worker.terminate();
|
worker.terminate();
|
||||||
if(aborted) return;
|
if(aborted) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user