Remove model after load to save space
This commit is contained in:
2
API.md
2
API.md
@@ -55,7 +55,7 @@ cd Vosklet/src &&
|
||||
```
|
||||
| Option | Description | Default value |
|
||||
|---|---|---|
|
||||
| MAX_MEMORY | Set max memory, valid suffixes: kb, mb, gb, tb or none (bytes) | ```375mb```, 300mb as [recommended](https://alphacephei.com/vosk/models) plus 75mb typical uncompressed model size (loaded to memory) |
|
||||
| MAX_MEMORY | Set max memory, valid suffixes: kb, mb, gb, tb or none (bytes) | ```375mb```, 300mb as [recommended](https://alphacephei.com/vosk/models) |
|
||||
| MAX_THREADS | Set the max number of threads (>=1), this should be equal to the number of model or speaker model that is used in the program | ```1``` (1 recognizer, 1 model, 0 speaker model) |
|
||||
| JOBS | Set the number of jobs (threads) when building | ```$(nproc)``` |
|
||||
| EMSDK | Set EMSDK's path (will install EMSDK in root folder if unset) | ```../emsdk``` |
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -7,24 +7,9 @@ VOSK=$(realpath vosk) &&
|
||||
OPENFST=$(realpath openfst) &&
|
||||
LIBARCHIVE=$(realpath libarchive) &&
|
||||
CLAPACK_WASM=$(realpath clapack-wasm) &&
|
||||
|
||||
MAX_MEMORY=${MAX_MEMORY:-375mb} &&
|
||||
MAX_THREADS=${MAX_THREADS:-1} &&
|
||||
EMSDK=${EMSDK:-$(realpath emsdk)} &&
|
||||
|
||||
if [ ! -d $EMSDK ]; then
|
||||
echo "Invalid EMSDK path"
|
||||
exit 1
|
||||
fi
|
||||
if [ $MAX_THREADS -lt 1 ]; then
|
||||
echo "MAX_THREAD must be greater than or equal to 1" &&
|
||||
exit 1
|
||||
fi
|
||||
if ! [[ $MAX_MEMORY =~ ^[0-9]+([kmgt]b)?$ ]]; then
|
||||
echo "MAX_MEMORY valid suffixes are kb, mb, gb, tb, none (bytes)" &&
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MAX_MEMORY=${MAX_MEMORY:-300mb}
|
||||
MAX_THREADS=${MAX_THREADS:-1}
|
||||
EMSDK=${EMSDK:-$(realpath ../emsdk)}
|
||||
. $EMSDK/emsdk_env.sh &&
|
||||
|
||||
cd $SRC &&
|
||||
|
||||
@@ -21,7 +21,7 @@ void genericModel::extractAndLoad(int tarStart, int tarSize) {
|
||||
break;
|
||||
}
|
||||
path = archive_entry_pathname(entry);
|
||||
path = storepath + path.generic_string().substr(path.generic_string().find("/"));
|
||||
path = storepath + path.string().substr(path.string().find("/"));
|
||||
if(!path.has_extension()) {
|
||||
fs::create_directory(path);
|
||||
continue;
|
||||
@@ -39,12 +39,12 @@ void genericModel::extractAndLoad(int tarStart, int tarSize) {
|
||||
}
|
||||
}
|
||||
free(reinterpret_cast<void*>(tarStart));
|
||||
fs::remove(storepath + "/README");
|
||||
archive_read_free(src);
|
||||
if(normalMdl) mdl = vosk_model_new(storepath.c_str());
|
||||
else vosk_spk_model_new(storepath.c_str());
|
||||
if(normalMdl ? std::get<0>(mdl) == nullptr : std::get<1>(mdl) == nullptr) fireEv(index, "Unable to load model for recognition");
|
||||
else fireEv(index, "0");
|
||||
fs::remove_all(storepath);
|
||||
};
|
||||
std::thread t{[this](){
|
||||
func();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <vosk_api.h>
|
||||
#include <emscripten/console.h>
|
||||
#include <archive.h>
|
||||
#include <archive_entry.h>
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
Reference in New Issue
Block a user