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

60 lines
1.7 KiB
C
Raw Normal View History

#ifndef AFE_WAKE_WORD_H
#define AFE_WAKE_WORD_H
2024-10-03 06:39:22 +08:00
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/event_groups.h>
2024-11-05 20:15:00 +08:00
#include <esp_afe_sr_models.h>
#include <esp_nsn_models.h>
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 AfeWakeWord : public WakeWord {
2024-10-03 06:39:22 +08:00
public:
AfeWakeWord();
~AfeWakeWord();
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_afe_sr_iface_t* afe_iface_ = nullptr;
esp_afe_sr_data_t* afe_data_ = nullptr;
2024-10-03 06:39:22 +08:00
char* wakenet_model_ = NULL;
std::vector<std::string> wake_words_;
2024-10-03 06:39:22 +08:00
EventGroupHandle_t event_group_;
std::function<void(const std::string& wake_word)> wake_word_detected_callback_;
AudioCodec* codec_ = nullptr;
std::string last_detected_wake_word_;
2024-10-03 06:39:22 +08:00
TaskHandle_t wake_word_encode_task_ = nullptr;
StaticTask_t wake_word_encode_task_buffer_;
StackType_t* wake_word_encode_task_stack_ = nullptr;
std::list<std::vector<int16_t>> wake_word_pcm_;
std::list<std::vector<uint8_t>> wake_word_opus_;
2024-11-14 23:15:43 +08:00
std::mutex wake_word_mutex_;
std::condition_variable wake_word_cv_;
2024-10-03 06:39:22 +08:00
void StoreWakeWordData(const int16_t* data, size_t size);
2024-10-03 06:39:22 +08:00
void AudioDetectionTask();
};
#endif