Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ac3036000 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/ai-utils",
|
"name": "@ztimson/ai-utils",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"description": "AI Utility library",
|
"description": "AI Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -14,9 +14,13 @@ export class Vision {
|
|||||||
let worker: any;
|
let worker: any;
|
||||||
const p = (async () => {
|
const p = (async () => {
|
||||||
worker = await createWorker(this.ai.options.ocr || 'eng', 2, {cachePath: this.ai.options.path});
|
worker = await createWorker(this.ai.options.ocr || 'eng', 2, {cachePath: this.ai.options.path});
|
||||||
const {data} = await worker.recognize(path);
|
worker.setParameters({}).catch(() => {}); // force error handler attachment
|
||||||
await worker.terminate();
|
return await new Promise<string | null>((res, rej) => {
|
||||||
return data.text.trim() || null;
|
worker.on?.('error', rej); // catch worker-level throws
|
||||||
|
worker.recognize(path)
|
||||||
|
.then(({data}: any) => res(data.text.trim() || null))
|
||||||
|
.catch(rej);
|
||||||
|
});
|
||||||
})().finally(() => worker?.terminate());
|
})().finally(() => worker?.terminate());
|
||||||
return Object.assign(p, {abort: () => worker?.terminate()});
|
return Object.assign(p, {abort: () => worker?.terminate()});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user