Files
xiaozhi-esp32/main/audio_processing/esp_wake_word.h

50 lines
1.3 KiB
C
Raw Normal View History

#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>
#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
#include "audio_codec.h"
#include "wake_word.h"
2024-10-03 06:39:22 +08:00
class EspWakeWord : public WakeWord {
2024-10-03 06:39:22 +08:00
public:
EspWakeWord();
~EspWakeWord();
2024-10-03 06:39:22 +08:00
void Initialize(AudioCodec* codec);
void Feed(const std::vector<int16_t>& data);
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();
size_t GetFeedSize();
2024-10-03 06:39:22 +08:00
void EncodeWakeWordData();
bool GetWakeWordOpus(std::vector<uint8_t>& opus);
const std::string& GetLastDetectedWakeWord() const { return last_detected_wake_word_; }
2024-10-03 06:39:22 +08:00
private:
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_;
AudioCodec* codec_ = nullptr;
2024-10-03 06:39:22 +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