Set tesseract model
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/ai-utils",
|
"name": "@ztimson/ai-utils",
|
||||||
"version": "0.2.4",
|
"version": "0.2.5",
|
||||||
"description": "AI Utility library",
|
"description": "AI Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
10
src/ai.ts
10
src/ai.ts
@@ -4,14 +4,20 @@ import { Audio } from './audio.ts';
|
|||||||
import {Vision} from './vision.ts';
|
import {Vision} from './vision.ts';
|
||||||
|
|
||||||
export type AiOptions = LLMOptions & {
|
export type AiOptions = LLMOptions & {
|
||||||
|
/** Path to models */
|
||||||
|
path?: string;
|
||||||
|
/** Whisper ASR configuration */
|
||||||
whisper?: {
|
whisper?: {
|
||||||
/** Whisper binary location */
|
/** Whisper binary location */
|
||||||
binary: string;
|
binary: string;
|
||||||
/** Model: `ggml-base.en.bin` */
|
/** Model: `ggml-base.en.bin` */
|
||||||
model: string;
|
model: string;
|
||||||
}
|
}
|
||||||
/** Path to models */
|
/** Tesseract OCR configuration */
|
||||||
path?: string;
|
tesseract?: {
|
||||||
|
/** Model: eng, eng_best, eng_fast */
|
||||||
|
model?: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Ai {
|
export class Ai {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class Vision {
|
|||||||
return {
|
return {
|
||||||
abort: () => { worker?.terminate(); },
|
abort: () => { worker?.terminate(); },
|
||||||
response: new Promise(async res => {
|
response: new Promise(async res => {
|
||||||
worker = await createWorker('eng', 1, {cachePath: this.ai.options.path});
|
worker = await createWorker(this.ai.options.tesseract?.model || 'eng', 2, {cachePath: this.ai.options.path});
|
||||||
const {data} = await worker.recognize(path);
|
const {data} = await worker.recognize(path);
|
||||||
await worker.terminate();
|
await worker.terminate();
|
||||||
res(data.text.trim() || null);
|
res(data.text.trim() || null);
|
||||||
|
|||||||
Reference in New Issue
Block a user