Make naming convention consistent, and synchronize code

This commit is contained in:
msqr1
2024-01-16 23:25:24 -08:00
parent ab8d869dd9
commit c7b380bece
19 changed files with 203 additions and 152 deletions

View File

@@ -1,34 +1,31 @@
#include "./recognizer.h"
void Recognizer::start() {
void recognizer::start() {
controller.test_and_set(std::memory_order_relaxed);
controller.notify_all();
}
void Recognizer::stop() {
void recognizer::stop() {
controller.clear(std::memory_order_relaxed);
controller.notify_all();
}
void Recognizer::deinit() {
void recognizer::deinit() {
done.test_and_set(std::memory_order_relaxed);
done.notify_all();
stop();
}
Recognizer::Recognizer(Model* model, int sampleRate, int index) : GenericObj(index) {
recognizer::recognizer(model* mdl, int sampleRate, int index) : genericObj(index) {
mic = alcCaptureOpenDevice("Emscripten OpenAL capture",sampleRate, AL_FORMAT_MONO16, 22480);
if(alcGetError(mic) != 0) {
fireEv("error", "Unable to initialize microphone");
return;
}
std::thread t{[this](Model* model, int sampleRate) {
recognizer = vosk_recognizer_new(model->model,static_cast<float>(sampleRate));
if(recognizer == nullptr) {
fireEv("error", "Unable to construct recognizer");
return;
}
main();
}, model, sampleRate};
t.detach();
rec = vosk_recognizer_new(mdl->mdl,static_cast<float>(sampleRate));
if(rec == nullptr) {
fireEv("error", "Unable to construct recognizer");
return;
}
main();
}
void Recognizer::main() {
void recognizer::main() {
char buffer[22480];
int sample{};
fireEv("ready");
@@ -38,12 +35,12 @@ void Recognizer::main() {
while(controller.test()) {
alcGetIntegerv(mic, ALC_CAPTURE_SAMPLES, sizeof(int), &sample);
alcCaptureSamples(mic, buffer, sample);
switch(vosk_recognizer_accept_waveform(recognizer, buffer, 22480)) {
switch(vosk_recognizer_accept_waveform(rec, buffer, 22480)) {
case 0:
fireEv("result", vosk_recognizer_result(recognizer));
fireEv("result", vosk_recognizer_result(rec));
break;
case 1:
fireEv("partialResult", vosk_recognizer_partial_result(recognizer));
fireEv("partialResult", vosk_recognizer_partial_result(rec));
break;
default:
fireEv("error", "Recognition result error");
@@ -51,24 +48,24 @@ void Recognizer::main() {
}
alcCaptureStop(mic);
}
vosk_recognizer_free(recognizer);
vosk_recognizer_free(rec);
alcCaptureCloseDevice(mic);
}
void Recognizer::setGrm(const std::string& grm) {
vosk_recognizer_set_grm(recognizer, grm.c_str());
void recognizer::setGrm(const std::string& grm) {
vosk_recognizer_set_grm(rec, grm.c_str());
}
void Recognizer::setSpkModel(SpkModel* model) {
vosk_recognizer_set_spk_model(recognizer,model->model);
void recognizer::setSpkModel(spkModel* mdl) {
vosk_recognizer_set_spk_model(rec, mdl->mdl);
}
void Recognizer::setWords(bool words) {
vosk_recognizer_set_words(recognizer,words);
void recognizer::setWords(bool words) {
vosk_recognizer_set_words(rec,words);
}
void Recognizer::setPartialWords(bool partialWords) {
vosk_recognizer_set_partial_words(recognizer, partialWords);
void recognizer::setPartialWords(bool partialWords) {
vosk_recognizer_set_partial_words(rec, partialWords);
}
void Recognizer::setNLSML(bool nlsml) {
vosk_recognizer_set_nlsml(recognizer, nlsml);
void recognizer::setNLSML(bool nlsml) {
vosk_recognizer_set_nlsml(rec, nlsml);
}
void Recognizer::setMaxAlternatives(int alts) {
vosk_recognizer_set_max_alternatives(recognizer, alts);
void recognizer::setMaxAlternatives(int alts) {
vosk_recognizer_set_max_alternatives(rec, alts);
}