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.

53 lines
2.2 KiB

2 years ago
2 years ago
  1. #include "wakeup_processer.hpp"
  2. using namespace std;
  3. using namespace iflytop;
  4. using namespace core;
  5. #define ORDER_PATH "precise-engine/precise-engine"
  6. // #define WAKEUP_MODULE_PATH "module/wakeup.pb"
  7. #define CHUNK_SIZE "2048"
  8. void WakeupProcesser::initialize(string wakeupmodulepath) {
  9. wakeupProcesser.reset(new MycroftPreciseWapper());
  10. wakeupProcesser->initialize(ORDER_PATH, wakeupmodulepath.c_str(), CHUNK_SIZE);
  11. }
  12. void WakeupProcesser::dumpwakeup_info(float source) {
  13. if (source > 0.9) {
  14. logger->info("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++{}", source);
  15. } else if (source > 0.8) {
  16. logger->info("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ {}", source);
  17. } else if (source > 0.7) {
  18. logger->info("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ {}", source);
  19. } else if (source > 0.6) {
  20. logger->info("++++++++++++++++++++++++++++++++++++++++++++++++++ {}", source);
  21. } else if (source > 0.4) {
  22. logger->info("++++++++++++++++++++++++++++++++++++++++ {}", source);
  23. } else if (source > 0.3) {
  24. logger->info("++++++++++++++++++++++++++++++ {}", source);
  25. } else if (source > 0.2) {
  26. logger->info("++++++++++++++++++++ {}", source);
  27. } else if (source > 0.1) {
  28. logger->info("++++++++++ {}", source);
  29. }
  30. }
  31. void WakeupProcesser::processVoice(uint8_t* voice, size_t voiceLen) {
  32. wakeupProcesser->processVoice(voice, voiceLen);
  33. wakeupProcesser->regWakeupCB([&](float wakeupscore) {
  34. if (!wakeupflag) {
  35. if (wakeupscore > 0.1) {
  36. dumpwakeup_info(wakeupscore);
  37. }
  38. if (!wakeupflag && wakeupscore > 0.60) {
  39. wakeupflag = true;
  40. logger->info("detect wakeup signal {}", wakeupscore);
  41. last_wakeup_timepoint = tu_steady().now();
  42. onWakeupSignal(wakeupscore);
  43. }
  44. } else {
  45. if (wakeupscore < 0.5 && tu_steady().elapsedTimeMs(last_wakeup_timepoint) >= 1500) {
  46. wakeupflag = false;
  47. }
  48. }
  49. });
  50. }