Remove model id on c++ side constructor, use index as storepath
This commit is contained in:
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
BIN
Vosklet.wasm
BIN
Vosklet.wasm
Binary file not shown.
@@ -14,13 +14,13 @@ EMSCRIPTEN_BINDINGS() {
|
||||
.value("ANSWER_VERY_LONG", VOSK_EP_ANSWER_VERY_LONG);
|
||||
|
||||
class_<CommonModel>("CommonModel")
|
||||
.constructor<int, bool, std::string, std::string, int, int>(return_value_policy::take_ownership())
|
||||
.constructor<int, bool, int, int>(return_value_policy::take_ownership())
|
||||
.function("findWord", &CommonModel::findWord);
|
||||
|
||||
class_<Recognizer>("Recognizer")
|
||||
.constructor<int, float, CommonModel*>(return_value_policy::take_ownership())
|
||||
.constructor<int, float, CommonModel*, CommonModel*>(return_value_policy::take_ownership())
|
||||
.constructor<int, float, CommonModel*, std::string, int>(return_value_policy::take_ownership())
|
||||
.constructor<int, float, CommonModel*, const std::string&, int>(return_value_policy::take_ownership())
|
||||
.function("safeDelete", &Recognizer::safeDelete)
|
||||
.function("acceptWaveform", &Recognizer::acceptWaveform)
|
||||
.function("reset", &Recognizer::reset)
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
#include "CommonModel.h"
|
||||
|
||||
CommonModel::CommonModel(int index, bool normalMdl, std::string storepath, std::string id, int tarStart, int tarSize) :
|
||||
normalMdl{normalMdl}, index{index},
|
||||
storepath{std::move(storepath)},
|
||||
id{std::move(id)}
|
||||
CommonModel::CommonModel(int index, bool normalMdl, int tarStart, int tarSize) :
|
||||
normalMdl{normalMdl}, index{index}
|
||||
{
|
||||
globalPool.exec([this, tarStart, tarSize]{
|
||||
extractAndLoad(reinterpret_cast<unsigned char*>(tarStart), tarSize);
|
||||
});
|
||||
}
|
||||
void CommonModel::extractAndLoad(unsigned char* tar, int tarSize) {
|
||||
int res{untar(tar, tarSize, storepath)};
|
||||
std::string storepath{'/' + std::to_string(index)};
|
||||
int res{untar(tar, tarSize, storepath.c_str())};
|
||||
free(tar);
|
||||
switch(res) {
|
||||
case IncorrectFormat:
|
||||
|
||||
@@ -6,12 +6,10 @@
|
||||
struct CommonModel {
|
||||
bool normalMdl;
|
||||
int index;
|
||||
std::string storepath;
|
||||
std::string id;
|
||||
std::variant<VoskModel*, VoskSpkModel*> mdl;
|
||||
|
||||
void extractAndLoad(unsigned char* tarStart, int tarSize);
|
||||
int findWord(std::string word);
|
||||
CommonModel(int index, bool normalMdl, std::string storepath, std::string id, int tarStart, int tarSize);
|
||||
CommonModel(int index, bool normalMdl, int tarStart, int tarSize);
|
||||
~CommonModel();
|
||||
};
|
||||
@@ -9,7 +9,7 @@ EM_JS(void, fireEv, (int idx, int typeIdx, const char* content), {
|
||||
}));
|
||||
else self.postMessage([idx, typeIdx, content]);
|
||||
});
|
||||
int untar(unsigned char* tar, int tarSize, const std::string& storepath) {
|
||||
int untar(unsigned char* tar, int tarSize, const char* storepath) {
|
||||
if(std::memcmp(tar + 257, "ustar", 5)) return IncorrectFormat;
|
||||
size_t size{};
|
||||
std::string path;
|
||||
|
||||
14
src/Util.h
14
src/Util.h
@@ -8,12 +8,6 @@
|
||||
#include "emscripten/console.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
struct AudioData {
|
||||
float* data;
|
||||
int len;
|
||||
AudioData(int start, int len) : data{reinterpret_cast<float*>(start)}, len{len} {}
|
||||
};
|
||||
enum Event {
|
||||
// Shared
|
||||
status,
|
||||
@@ -30,6 +24,12 @@ enum UntarStatus {
|
||||
FailedWrite,
|
||||
FailedClose
|
||||
};
|
||||
struct AudioData {
|
||||
float* data;
|
||||
int len;
|
||||
AudioData(int start, int len) : data{reinterpret_cast<float*>(start)}, len{len} {}
|
||||
};
|
||||
|
||||
#ifndef MAX_WORKERS
|
||||
#define MAX_WORKERS 1
|
||||
#endif
|
||||
@@ -43,6 +43,6 @@ struct WorkerPool {
|
||||
};
|
||||
extern "C" void fireEv(int idx, int typeIdx, const char* content = nullptr);
|
||||
|
||||
int untar(unsigned char* tar, int tarSize, const std::string& storepath);
|
||||
int untar(unsigned char* tar, int tarSize, const char* storepath);
|
||||
|
||||
extern WorkerPool globalPool;
|
||||
@@ -92,7 +92,7 @@ class CommonModel extends EventTarget {
|
||||
tar = tar.data;
|
||||
let tarStart = _malloc(tar.byteLength);
|
||||
HEAPU8.set(new Uint8Array(tar), tarStart);
|
||||
mdl.obj = new Module['CommonModel'](objs.length - 1, normalMdl, '/' + storepath, id, tarStart, tar.byteLength);
|
||||
mdl.obj = new Module['CommonModel'](objs.length - 1, normalMdl, tarStart, tar.byteLength);
|
||||
}, { once: true });
|
||||
storageWorker.postMessage({
|
||||
url: url,
|
||||
|
||||
Reference in New Issue
Block a user