Some bug fixes and change in pattern
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
using namespace emscripten;
|
||||
EMSCRIPTEN_BINDINGS() {
|
||||
function("setLogLevel", &vosk_set_log_level, allow_raw_pointers());
|
||||
class_<model, base<genericModel>>("__model__")
|
||||
class_<model>("__model__")
|
||||
.constructor<std::string, std::string, std::string, int>(allow_raw_pointers());
|
||||
|
||||
class_<spkModel, base<genericModel>>("__spkModel__")
|
||||
class_<spkModel>("__spkModel__")
|
||||
.constructor<std::string, std::string, std::string, const int>(allow_raw_pointers());
|
||||
|
||||
class_<recognizer, base<genericObj>>("__recognizer__")
|
||||
class_<recognizer>("__recognizer__")
|
||||
.constructor<model*, int, int>(allow_raw_pointers())
|
||||
.function("start", &recognizer::start, allow_raw_pointers())
|
||||
.function("stop", &recognizer::stop, allow_raw_pointers())
|
||||
|
||||
@@ -34,12 +34,15 @@ bool genericModel::loadModel() {
|
||||
fireEv("error", "Unable to fetch model");
|
||||
return false;
|
||||
}
|
||||
if(!extractModel(".")) {
|
||||
if(!extractModel()) {
|
||||
fireEv("error", "Unable to extract model");
|
||||
return false;
|
||||
}
|
||||
fs::remove("opfs/model.tzst");
|
||||
if(!checkModel()) {
|
||||
fireEv("error", "Model URL contains invalid model files");
|
||||
fs::remove_all(".");
|
||||
return false;
|
||||
}
|
||||
std::ofstream idFile("id");
|
||||
if(!idFile.is_open()) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
|
||||
#include <vosk_api.h>
|
||||
#include <archive.h>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
class Model extends EventTarget{
|
||||
constructor(url, storepath, id) {
|
||||
constructor() {
|
||||
super()
|
||||
this.obj = (async () => {
|
||||
return new Module.__model__(url, storepath, id, __genericObj__.objects.length)
|
||||
})()
|
||||
}
|
||||
init(url, storepath, id) {
|
||||
this.obj = new Module.__model__(url, storepath, id, __genericObj__.objects.length);
|
||||
__genericObj__.objects.push(this)
|
||||
}
|
||||
delete() {
|
||||
|
||||
@@ -1,57 +1,39 @@
|
||||
class Recognizer extends EventTarget {
|
||||
constructor(model) {
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
init(model) {
|
||||
ctx = new (AudioContext || webkitAudioContext)()
|
||||
this.obj = (async () => {
|
||||
new Module.__recognizer__(model.obj,ctx.sampleRate,__genericObj__.objects.length)
|
||||
})()
|
||||
__genericObj__.objects.push(this)
|
||||
new Module.__recognizer__(model.obj,ctx.sampleRate,__genericObj__.objects.length)
|
||||
ctx.close()
|
||||
return this;
|
||||
__genericObj__.objects.push(this)
|
||||
}
|
||||
start() {
|
||||
this.obj.then(() => {
|
||||
this.obj.start()
|
||||
})
|
||||
}
|
||||
stop() {
|
||||
this.obj.then(() => {
|
||||
this.obj.stop()
|
||||
})
|
||||
}
|
||||
delete() {
|
||||
this.obj.then(() => {
|
||||
this.obj.deinit()
|
||||
this.obj.delete()
|
||||
})
|
||||
}
|
||||
setWords(words) {
|
||||
this.obj.then(() => {
|
||||
this.obj.setWords(words)
|
||||
})
|
||||
}
|
||||
setPartialWords(partialWords) {
|
||||
this.obj.then(() => {
|
||||
this.obj.setPartialWords(partialWords)
|
||||
})
|
||||
}
|
||||
setGrm(grm) {
|
||||
this.obj.then(() => {
|
||||
this.obj.setGrm(grm)
|
||||
})
|
||||
}
|
||||
setSpkModel(model) {
|
||||
this.obj.then(() => {
|
||||
this.obj.setSpkModel(model.obj)
|
||||
})
|
||||
}
|
||||
setNLSML(nlsml) {
|
||||
this.obj.then(() => {
|
||||
this.obj.setNLSML(nlsml)
|
||||
})
|
||||
}
|
||||
setMaxAlternatives(alts) {
|
||||
this.obj.then(() => {
|
||||
this.obj.setMaxAlternatives(alts)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
class SpkModel extends EventTarget{
|
||||
constructor(url, storepath, id) {
|
||||
constructor() {
|
||||
super()
|
||||
this.obj = (async () => {
|
||||
return new Module.__spkModel__(url, storepath, id, __genericObj__.objects.length)
|
||||
})()
|
||||
}
|
||||
init(url, storepath, id) {
|
||||
this.obj = new Module.__spkModel__(url, storepath, id, __genericObj__.objects.length)
|
||||
__genericObj__.objects.push(this)
|
||||
}
|
||||
delete() {
|
||||
this.obj.then(() => {
|
||||
this.obj.delete()
|
||||
})
|
||||
this.obj.delete()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user