esp_wake_word.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef ESP_WAKE_WORD_H
  2. #define ESP_WAKE_WORD_H
  3. #include <freertos/FreeRTOS.h>
  4. #include <freertos/task.h>
  5. #include <freertos/event_groups.h>
  6. #include <esp_wn_iface.h>
  7. #include <esp_wn_models.h>
  8. #include <model_path.h>
  9. #include <list>
  10. #include <string>
  11. #include <vector>
  12. #include <functional>
  13. #include <mutex>
  14. #include <condition_variable>
  15. #include "audio_codec.h"
  16. #include "wake_word.h"
  17. class EspWakeWord : public WakeWord {
  18. public:
  19. EspWakeWord();
  20. ~EspWakeWord();
  21. bool Initialize(AudioCodec* codec);
  22. void Feed(const std::vector<int16_t>& data);
  23. void OnWakeWordDetected(std::function<void(const std::string& wake_word)> callback);
  24. void Start();
  25. void Stop();
  26. size_t GetFeedSize();
  27. void EncodeWakeWordData();
  28. bool GetWakeWordOpus(std::vector<uint8_t>& opus);
  29. const std::string& GetLastDetectedWakeWord() const { return last_detected_wake_word_; }
  30. private:
  31. esp_wn_iface_t *wakenet_iface_ = nullptr;
  32. model_iface_data_t *wakenet_data_ = nullptr;
  33. srmodel_list_t *wakenet_model_ = nullptr;
  34. EventGroupHandle_t event_group_;
  35. AudioCodec* codec_ = nullptr;
  36. std::function<void(const std::string& wake_word)> wake_word_detected_callback_;
  37. std::string last_detected_wake_word_;
  38. };
  39. #endif