ESP32-S3 吊坠设备固件,集成火山引擎 RTC 语音助手、蓝牙配网、 VEML7700 环境光传感器驱动及石头同频匹配交友功能。 VEML7700 驱动: - 基于 ESP-IDF i2c_master API 实现,复用项目 I2cDevice 基类 - 支持 ALS + White 双通道、自动量程、Vishay 非线性校正 - 3 次采样取中位数过滤偶发异常 石头同频匹配算法(双维度): - 维度1:光谱比值 ALS/White(石头固有光学特征,不随光照强度变化) - 维度2:亮度等级(5级对数划分,排除极端环境差异) - 比值阈值 15%,实测同石头姿势变化波动 1.6%~9.6%,安全余量充足 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
72 lines
2.2 KiB
C++
72 lines
2.2 KiB
C++
#ifndef CUSTOM_WAKE_WORD_H
|
|
#define CUSTOM_WAKE_WORD_H
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/task.h>
|
|
#include <freertos/event_groups.h>
|
|
|
|
#include <esp_afe_sr_models.h>
|
|
#include <esp_afe_sr_iface.h>
|
|
#include <esp_nsn_models.h>
|
|
#include <esp_wn_iface.h>
|
|
#include <esp_wn_models.h>
|
|
#include <esp_mn_iface.h>
|
|
#include <esp_mn_models.h>
|
|
|
|
#include <list>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <functional>
|
|
#include <mutex>
|
|
#include <condition_variable>
|
|
|
|
#include "audio_codec.h"
|
|
#include "wake_word.h"
|
|
#include <opus_encoder.h>
|
|
|
|
class CustomWakeWord : public WakeWord {
|
|
public:
|
|
CustomWakeWord();
|
|
~CustomWakeWord();
|
|
|
|
bool Initialize(AudioCodec* codec) override;
|
|
void Feed(const std::vector<int16_t>& data) override;
|
|
void OnWakeWordDetected(std::function<void(const std::string& wake_word)> callback) override;
|
|
void Start() override;
|
|
void Stop() override;
|
|
bool IsRunning() override;
|
|
size_t GetFeedSize() override;
|
|
void EncodeWakeWordData() override;
|
|
bool GetWakeWordOpus(std::vector<uint8_t>& opus) override;
|
|
const std::string& GetLastDetectedWakeWord() const override { return last_detected_wake_word_; }
|
|
|
|
private:
|
|
esp_afe_sr_iface_t* afe_iface_ = nullptr;
|
|
esp_afe_sr_data_t* afe_data_ = nullptr;
|
|
srmodel_list_t *models = nullptr;
|
|
|
|
// multinet 相关成员变量
|
|
esp_mn_iface_t* multinet_ = nullptr;
|
|
model_iface_data_t* multinet_model_data_ = nullptr;
|
|
char* mn_name_ = nullptr;
|
|
|
|
char* wakenet_model_ = NULL;
|
|
std::vector<std::string> wake_words_;
|
|
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_;
|
|
|
|
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_;
|
|
std::mutex wake_word_mutex_;
|
|
std::condition_variable wake_word_cv_;
|
|
|
|
void StoreWakeWordData(const int16_t* data, size_t size);
|
|
void AudioDetectionTask();
|
|
};
|
|
|
|
#endif |