custom_wake_word.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef CUSTOM_WAKE_WORD_H
  2. #define CUSTOM_WAKE_WORD_H
  3. #include <freertos/FreeRTOS.h>
  4. #include <freertos/task.h>
  5. #include <freertos/event_groups.h>
  6. #include <esp_afe_sr_models.h>
  7. #include <esp_afe_sr_iface.h>
  8. #include <esp_nsn_models.h>
  9. #include <esp_wn_iface.h>
  10. #include <esp_wn_models.h>
  11. #include <esp_mn_iface.h>
  12. #include <esp_mn_models.h>
  13. #include <list>
  14. #include <string>
  15. #include <vector>
  16. #include <functional>
  17. #include <mutex>
  18. #include <condition_variable>
  19. #include "audio_codec.h"
  20. #include "wake_word.h"
  21. class CustomWakeWord : public WakeWord {
  22. public:
  23. CustomWakeWord();
  24. ~CustomWakeWord();
  25. bool Initialize(AudioCodec* codec);
  26. void Feed(const std::vector<int16_t>& data);
  27. void OnWakeWordDetected(std::function<void(const std::string& wake_word)> callback);
  28. void Start();
  29. void Stop();
  30. size_t GetFeedSize();
  31. void EncodeWakeWordData();
  32. bool GetWakeWordOpus(std::vector<uint8_t>& opus);
  33. const std::string& GetLastDetectedWakeWord() const { return last_detected_wake_word_; }
  34. private:
  35. esp_afe_sr_iface_t* afe_iface_ = nullptr;
  36. esp_afe_sr_data_t* afe_data_ = nullptr;
  37. srmodel_list_t *models = nullptr;
  38. // multinet 相关成员变量
  39. esp_mn_iface_t* multinet_ = nullptr;
  40. model_iface_data_t* multinet_model_data_ = nullptr;
  41. char* mn_name_ = nullptr;
  42. char* wakenet_model_ = NULL;
  43. std::vector<std::string> wake_words_;
  44. EventGroupHandle_t event_group_;
  45. std::function<void(const std::string& wake_word)> wake_word_detected_callback_;
  46. AudioCodec* codec_ = nullptr;
  47. std::string last_detected_wake_word_;
  48. TaskHandle_t wake_word_encode_task_ = nullptr;
  49. StaticTask_t wake_word_encode_task_buffer_;
  50. StackType_t* wake_word_encode_task_stack_ = nullptr;
  51. std::list<std::vector<int16_t>> wake_word_pcm_;
  52. std::list<std::vector<uint8_t>> wake_word_opus_;
  53. std::mutex wake_word_mutex_;
  54. std::condition_variable wake_word_cv_;
  55. void StoreWakeWordData(const int16_t* data, size_t size);
  56. void AudioDetectionTask();
  57. };
  58. #endif