mirror of
https://github.com/78/xiaozhi-esp32.git
synced 2026-01-14 01:07:30 +08:00
* Adapt boards to v2 partition tables * fix esp log error * fix display style * reset emotion after download assets * fix compiling * update assets default url * Add user only tools * Add image cache * smaller cache and buffer, more heap * use MAIN_EVENT_CLOCK_TICK to avoid audio glitches * bump to 2.0.0 * fix compiling errors --------- Co-authored-by: Xiaoxia <terrence.huang@tenclass.com>
59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
#ifndef CUSTOM_WAKE_WORD_H
|
|
#define CUSTOM_WAKE_WORD_H
|
|
|
|
#include <esp_attr.h>
|
|
#include <esp_mn_iface.h>
|
|
#include <esp_mn_models.h>
|
|
#include <model_path.h>
|
|
|
|
#include <deque>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <functional>
|
|
#include <mutex>
|
|
#include <condition_variable>
|
|
#include <atomic>
|
|
|
|
#include "audio_codec.h"
|
|
#include "wake_word.h"
|
|
|
|
class CustomWakeWord : public WakeWord {
|
|
public:
|
|
CustomWakeWord();
|
|
~CustomWakeWord();
|
|
|
|
bool Initialize(AudioCodec* codec, srmodel_list_t* models_list);
|
|
void Feed(const std::vector<int16_t>& data);
|
|
void OnWakeWordDetected(std::function<void(const std::string& wake_word)> callback);
|
|
void Start();
|
|
void Stop();
|
|
size_t GetFeedSize();
|
|
void EncodeWakeWordData();
|
|
bool GetWakeWordOpus(std::vector<uint8_t>& opus);
|
|
const std::string& GetLastDetectedWakeWord() const { return last_detected_wake_word_; }
|
|
|
|
private:
|
|
// multinet 相关成员变量
|
|
esp_mn_iface_t* multinet_ = nullptr;
|
|
model_iface_data_t* multinet_model_data_ = nullptr;
|
|
srmodel_list_t *models_ = nullptr;
|
|
char* mn_name_ = nullptr;
|
|
|
|
std::function<void(const std::string& wake_word)> wake_word_detected_callback_;
|
|
AudioCodec* codec_ = nullptr;
|
|
std::string last_detected_wake_word_;
|
|
std::atomic<bool> running_ = false;
|
|
|
|
TaskHandle_t wake_word_encode_task_ = nullptr;
|
|
StaticTask_t* wake_word_encode_task_buffer_ = nullptr;
|
|
StackType_t* wake_word_encode_task_stack_ = nullptr;
|
|
std::deque<std::vector<int16_t>> wake_word_pcm_;
|
|
std::deque<std::vector<uint8_t>> wake_word_opus_;
|
|
std::mutex wake_word_mutex_;
|
|
std::condition_variable wake_word_cv_;
|
|
|
|
void StoreWakeWordData(const std::vector<int16_t>& data);
|
|
};
|
|
|
|
#endif
|