2025-05-31 22:21:03 +08:00
|
|
|
#ifndef ESP_WAKE_WORD_H
|
|
|
|
|
#define ESP_WAKE_WORD_H
|
2024-10-03 06:39:22 +08:00
|
|
|
|
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
|
#include <freertos/task.h>
|
|
|
|
|
#include <freertos/event_groups.h>
|
|
|
|
|
|
2025-05-31 22:21:03 +08:00
|
|
|
#include <esp_wn_iface.h>
|
|
|
|
|
#include <esp_wn_models.h>
|
|
|
|
|
#include <model_path.h>
|
2024-11-05 20:15:00 +08:00
|
|
|
|
2024-10-03 06:39:22 +08:00
|
|
|
#include <list>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <functional>
|
2024-11-14 23:15:43 +08:00
|
|
|
#include <mutex>
|
|
|
|
|
#include <condition_variable>
|
2024-10-03 06:39:22 +08:00
|
|
|
|
2025-03-30 09:07:08 +08:00
|
|
|
#include "audio_codec.h"
|
2025-05-31 22:21:03 +08:00
|
|
|
#include "wake_word.h"
|
2024-10-03 06:39:22 +08:00
|
|
|
|
2025-05-31 22:21:03 +08:00
|
|
|
class EspWakeWord : public WakeWord {
|
2024-10-03 06:39:22 +08:00
|
|
|
public:
|
2025-05-31 22:21:03 +08:00
|
|
|
EspWakeWord();
|
|
|
|
|
~EspWakeWord();
|
2024-10-03 06:39:22 +08:00
|
|
|
|
2025-03-30 09:07:08 +08:00
|
|
|
void Initialize(AudioCodec* codec);
|
2024-12-04 02:12:20 +08:00
|
|
|
void Feed(const std::vector<int16_t>& data);
|
2024-11-25 00:59:03 +08:00
|
|
|
void OnWakeWordDetected(std::function<void(const std::string& wake_word)> callback);
|
2024-10-03 06:39:22 +08:00
|
|
|
void StartDetection();
|
|
|
|
|
void StopDetection();
|
|
|
|
|
bool IsDetectionRunning();
|
2025-03-30 09:07:08 +08:00
|
|
|
size_t GetFeedSize();
|
2024-10-03 06:39:22 +08:00
|
|
|
void EncodeWakeWordData();
|
2024-12-04 02:12:20 +08:00
|
|
|
bool GetWakeWordOpus(std::vector<uint8_t>& opus);
|
2024-11-25 00:59:03 +08:00
|
|
|
const std::string& GetLastDetectedWakeWord() const { return last_detected_wake_word_; }
|
2024-10-03 06:39:22 +08:00
|
|
|
|
|
|
|
|
private:
|
2025-05-31 22:21:03 +08:00
|
|
|
esp_wn_iface_t *wakenet_iface_ = nullptr;
|
|
|
|
|
model_iface_data_t *wakenet_data_ = nullptr;
|
|
|
|
|
srmodel_list_t *wakenet_model_ = nullptr;
|
2024-10-03 06:39:22 +08:00
|
|
|
EventGroupHandle_t event_group_;
|
2025-03-30 09:07:08 +08:00
|
|
|
AudioCodec* codec_ = nullptr;
|
2024-10-03 06:39:22 +08:00
|
|
|
|
2025-05-31 22:21:03 +08:00
|
|
|
std::function<void(const std::string& wake_word)> wake_word_detected_callback_;
|
|
|
|
|
std::string last_detected_wake_word_;
|
2024-10-03 06:39:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|