You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
3.0 KiB
71 lines
3.0 KiB
#include "wakeup_processer.hpp"
|
|
using namespace std;
|
|
using namespace iflytop;
|
|
using namespace core;
|
|
|
|
#define WAKEUP_MODULE_INIT_TIMEOUT_S 8
|
|
|
|
void WakeupProcesser::initialize(string precise_engine, string wakeupmodulepath, string chunksize) {
|
|
logger->info("initialize precise_engine:{}, wakeupmodulepath:{}, chunksize:{}", precise_engine, wakeupmodulepath,
|
|
chunksize);
|
|
wakeupProcesser.reset(new MycroftPreciseWapper());
|
|
wakeupProcesser->initialize(precise_engine.c_str(), wakeupmodulepath.c_str(), chunksize.c_str());
|
|
m_chucksize = atoi(chunksize.c_str());
|
|
uint16_t s_zerovoicebuf[m_chucksize] = {0};
|
|
wakeupProcesser->processVoice((uint8_t*)&s_zerovoicebuf[0], m_chucksize * 2);
|
|
wakeupProcesser->processVoice((uint8_t*)&s_zerovoicebuf[0], m_chucksize * 2);
|
|
for (size_t i = 0; i < WAKEUP_MODULE_INIT_TIMEOUT_S; i++) {
|
|
logger->info("wait for wakeup module init {}/{}", i, WAKEUP_MODULE_INIT_TIMEOUT_S);
|
|
sleep(1);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
int WakeupProcesser::getChunkSize() { return m_chucksize; }
|
|
|
|
void WakeupProcesser::dumpwakeup_info(float source) {
|
|
if (source > 0.9) {
|
|
logger->info("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++{}", source);
|
|
} else if (source > 0.8) {
|
|
logger->info("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ {}", source);
|
|
} else if (source > 0.7) {
|
|
logger->info("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ {}", source);
|
|
} else if (source > 0.6) {
|
|
logger->info("++++++++++++++++++++++++++++++++++++++++++++++++++ {}", source);
|
|
} else if (source > 0.4) {
|
|
logger->info("++++++++++++++++++++++++++++++++++++++++ {}", source);
|
|
} else if (source > 0.3) {
|
|
logger->info("++++++++++++++++++++++++++++++ {}", source);
|
|
} else if (source > 0.2) {
|
|
logger->info("++++++++++++++++++++ {}", source);
|
|
} else if (source > 0.1) {
|
|
logger->info("++++++++++ {}", source);
|
|
}
|
|
}
|
|
|
|
void WakeupProcesser::processVoice(uint8_t* voice, size_t voiceLen) {
|
|
if (!voice) return;
|
|
ZCHECK(voiceLen == m_chucksize, "voiceLen != m_chucksize");
|
|
// logger->info("before processVoice {}", voiceLen);
|
|
wakeupProcesser->processVoice(voice, voiceLen);
|
|
// logger->info("end processVoice");
|
|
|
|
wakeupProcesser->regWakeupCB([&](float wakeupscore) {
|
|
if (!wakeupflag) {
|
|
if (wakeupscore > 0.1) {
|
|
dumpwakeup_info(wakeupscore);
|
|
}
|
|
if (!wakeupflag && wakeupscore > 0.60) {
|
|
wakeupflag = true;
|
|
logger->info("detect wakeup signal {}", wakeupscore);
|
|
last_wakeup_timepoint = tu_steady().now();
|
|
onWakeupSignal(wakeupscore);
|
|
}
|
|
} else {
|
|
if (wakeupscore < 0.5 && tu_steady().elapsedTimeMs(last_wakeup_timepoint) >= 1500) {
|
|
wakeupflag = false;
|
|
}
|
|
}
|
|
});
|
|
}
|