From 0ad8f60672df1719003b389d964a3f5b5e2d7ef8 Mon Sep 17 00:00:00 2001 From: msqr1 Date: Mon, 5 Feb 2024 17:46:03 -0800 Subject: [PATCH] Update documentation --- README.md | 9 +++++---- src/pre.js | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 899d386..8350dfb 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,9 @@ Browser-recognizer require SharedArrayBuffer to share thread's data, so these re If you can't set them, you may use a HACKY workaround at *src/addCOI.js*. ## Origin Private Filesystem (OPFS) -Browser-recognizer needs the Emscripten WASMFS' OPFS to store its model, IDBFS was considered, but discarded because there is no direct way to read from IDBFS to C++ without copying to MEMFS. To be safe, always: +Browser-recognizer needs the Emscripten WASMFS' OPFS to store its model, IDBFS was considered, but dropped because there is no direct way to read from IDBFS to C++ without copying to MEMFS (basically RAM). For safety with this, always: - Try catch ```window.loadBR()``` to to check for OPFS availability. -- Check if there is enough space for **model + compressed model** before calling makeModel via ```navigator.storage.estimate()``` +- Check if there is enough space via ```navigator.storage.estimate()``` for **model + compressed model** before calling makeModel # API interface ## JS ```window``` object @@ -37,7 +37,8 @@ Browser-recognizer needs the Emscripten WASMFS' OPFS to store its model, IDBFS w | ```Promise makeModel(path: string, url: string, id: string)```

```Promise makeSpkModel(path: string, url: string, id: string)``` | Make a ```Model``` or ```SpkModel```
- If **path** contains valid model files and **id** is the same, there will not be a fetch from **url**.
- If **path** doesn't contain valid model files, or if it contains valid model files but **id** is different, there will be a fetch from **url**, and the model is stored with **id**. | | ```Promise makeRecognizer(model: Model, sampleRate: float)``` | Make a ```Recognizer```, it will use **model**'s thread if it's the first user of **model**, else it will use a new thread. | ```setLogLevel(lvl: int)``` | Set Vosk's log level (default: ```0```: Info)
```-2```: Error
```-1```: Warning
```1```: Verbose
```2```: More verbose
```3```: Debug | -| ```cleanUp()``` | A convenient function that call ```delete()``` on all objects and revoke all Blob URLs. | +| ```revokeURLs()``` | Revoke the Blob URLs of pthread worker and worklet processor | +| ```cleanUp()``` | A convenient function that call ```revokeURLs()``` and ```delete()``` on all objects and . You should put this at the end of your program! | ## ```Recognizer``` object | Function signature | Description | @@ -72,6 +73,6 @@ cd Browser-recognizer && # TODO: - Fix libarchive extract closing issue - setSpkModel avoid spawning extra thread -- Top level await in usage +- Top level await in API usage - Write examples - Balance code size and speed diff --git a/src/pre.js b/src/pre.js index d63034d..24bed13 100644 --- a/src/pre.js +++ b/src/pre.js @@ -1,8 +1,11 @@ let objs = [] -Module.cleanUp = () => { - objs.forEach(obj => obj.delete()) +Module.revokeURLs = () => { URL.revokeObjectURL(pthreadUrl) URL.revokeObjectURL(processorUrl) +} +Module.cleanUp = () => { + objs.forEach(obj => obj.delete()) + Module.revokeURLs() } class Recognizer extends EventTarget { constructor() {