Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0172887877 | |||
| 8f89f5e3cf | |||
| 5bd41f8c6a |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/ai-utils",
|
"name": "@ztimson/ai-utils",
|
||||||
"version": "0.6.7",
|
"version": "0.6.9",
|
||||||
"description": "AI Utility library",
|
"description": "AI Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ function combineSpeakerTranscript(chunks: any[], speakers: any[]): string {
|
|||||||
|
|
||||||
parentPort?.on('message', async ({ file, speaker, model, modelDir }) => {
|
parentPort?.on('message', async ({ file, speaker, model, modelDir }) => {
|
||||||
try {
|
try {
|
||||||
|
console.log('worker', file);
|
||||||
if(!whisperPipeline) whisperPipeline = await pipeline('automatic-speech-recognition', `Xenova/${model}`, {cache_dir: modelDir, quantized: true});
|
if(!whisperPipeline) whisperPipeline = await pipeline('automatic-speech-recognition', `Xenova/${model}`, {cache_dir: modelDir, quantized: true});
|
||||||
|
|
||||||
// Prepare audio file (convert to mono channel wave)
|
// Prepare audio file (convert to mono channel wave)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
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) {}
|
||||||
@@ -12,7 +13,7 @@ export class Audio {
|
|||||||
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;
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import { parentPort } from 'worker_threads';
|
|||||||
|
|
||||||
let embedder: any;
|
let embedder: any;
|
||||||
|
|
||||||
parentPort?.on('message', async ({ id, text, model, modelDir }) => {
|
parentPort?.on('message', async ({text, model, modelDir }) => {
|
||||||
if(!embedder) embedder = await pipeline('feature-extraction', 'Xenova/' + model, {quantized: true, cache_dir: modelDir});
|
if(!embedder) embedder = await pipeline('feature-extraction', 'Xenova/' + model, {quantized: true, cache_dir: modelDir});
|
||||||
const output = await embedder(text, { pooling: 'mean', normalize: true });
|
const output = await embedder(text, { pooling: 'mean', normalize: true });
|
||||||
const embedding = Array.from(output.data);
|
const embedding = Array.from(output.data);
|
||||||
parentPort?.postMessage({ id, embedding });
|
parentPort?.postMessage({embedding});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ class LLM {
|
|||||||
worker.on('exit', (code) => {
|
worker.on('exit', (code) => {
|
||||||
if(code !== 0) reject(new Error(`Worker exited with code ${code}`));
|
if(code !== 0) reject(new Error(`Worker exited with code ${code}`));
|
||||||
});
|
});
|
||||||
worker.postMessage({text, model: this.ai.options?.embedder || 'bge-small-en-v1.5', path: this.ai.options.path});
|
worker.postMessage({text, model: this.ai.options?.embedder || 'bge-small-en-v1.5', modelDir: this.ai.options.path});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const chunks = this.chunk(target, maxTokens, overlapTokens);
|
const chunks = this.chunk(target, maxTokens, overlapTokens);
|
||||||
|
|||||||
Reference in New Issue
Block a user