From 31ee35e1f73ce16b4242fce1e4f045bd6b173aae Mon Sep 17 00:00:00 2001 From: msqr1 Date: Mon, 5 Feb 2024 23:12:41 -0800 Subject: [PATCH] Tried closure compiler, but it doesn't reduce the size as much as expected, and it breaks many things. Tried -Oz, but it only reduces 200kb. --- .gitignore | 3 ++- README.md | 2 +- src/genericModel.cc | 19 +++++++++---------- src/processor.js | 1 - 4 files changed, 12 insertions(+), 13 deletions(-) delete mode 100644 src/processor.js diff --git a/.gitignore b/.gitignore index 7612359..b0c96ab 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ libarchive .vscode clapack-wasm openfst -emsdk \ No newline at end of file +emsdk +devel \ No newline at end of file diff --git a/README.md b/README.md index 8350dfb..2c95bb6 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Browser-recognizer needs the Emscripten WASMFS' OPFS to store its model, IDBFS w | ```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 | | ```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! | +| ```cleanUp()``` | A convenience 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 | diff --git a/src/genericModel.cc b/src/genericModel.cc index f688a27..28f7fc7 100644 --- a/src/genericModel.cc +++ b/src/genericModel.cc @@ -28,10 +28,13 @@ bool genericModel::checkModel() { } void genericModel::afterFetch() { thrd.setTask1([this](){ - if(!extractModel()) { - fireEv("_continue", "Unable to extract model and delete .tzst file", index); + if(!extractModel() && fs::remove("/opfs/m0dEl.tzst",tank)) { + fs::current_path("/opfs"); + fs::remove_all(storepath); + fireEv("_continue", "Unable to extract model", index); return; } + fs::remove("/opfs/m0dEl.tzst",tank); std::ofstream idFile("id"); if(!idFile.is_open()) { fs::current_path("/opfs"); @@ -41,17 +44,13 @@ void genericModel::afterFetch() { } idFile << id; idFile.close(); - char a[3] {}; - int fd = open("./conf/model.conf", O_RDONLY); - read(fd, a, 3); - emscripten_console_log(a); - close(fd); + // I wanna give up on this thing so bad... std::ifstream is("./conf/model.conf"); emscripten_console_logf("%d", is.good()); emscripten_console_logf("%d", is.bad()); emscripten_console_logf("%d", is.eof()); emscripten_console_logf("%d", is.fail()); - + is.close(); //load(false); }); } @@ -68,9 +67,9 @@ bool genericModel::extractModel() { // Strip first component, keep relative path path = "." + path.substr(path.find("/")); archive_entry_set_pathname(entry, path.c_str()); + archive_read_extract(src, entry, ARCHIVE_EXTRACT_UNLINK | ARCHIVE_EXTRACT_NO_AUTODIR); if(archive_errno(src) != 0) return false; - archive_read_extract(src, entry, ARCHIVE_EXTRACT_UNLINK); } archive_read_free(src); - return fs::remove("/opfs/m0dEl.tzst",tank); + return true; } \ No newline at end of file diff --git a/src/processor.js b/src/processor.js deleted file mode 100644 index b27d1ad..0000000 --- a/src/processor.js +++ /dev/null @@ -1 +0,0 @@ -// A copy and pass processor