2025-04-29 18:17:08 +08:00
|
|
|
#ifndef AFE_AUDIO_PROCESSOR_H
|
|
|
|
|
#define AFE_AUDIO_PROCESSOR_H
|
|
|
|
|
|
|
|
|
|
#include <esp_afe_sr_models.h>
|
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
|
#include <freertos/task.h>
|
|
|
|
|
#include <freertos/event_groups.h>
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
|
|
#include "audio_processor.h"
|
|
|
|
|
#include "audio_codec.h"
|
|
|
|
|
|
|
|
|
|
class AfeAudioProcessor : public AudioProcessor {
|
|
|
|
|
public:
|
|
|
|
|
AfeAudioProcessor();
|
|
|
|
|
~AfeAudioProcessor();
|
|
|
|
|
|
2025-09-04 15:41:28 +08:00
|
|
|
void Initialize(AudioCodec* codec, int frame_duration_ms, srmodel_list_t* models_list) override;
|
2025-07-20 03:57:36 +08:00
|
|
|
void Feed(std::vector<int16_t>&& data) override;
|
2025-04-29 18:17:08 +08:00
|
|
|
void Start() override;
|
|
|
|
|
void Stop() override;
|
|
|
|
|
bool IsRunning() override;
|
|
|
|
|
void OnOutput(std::function<void(std::vector<int16_t>&& data)> callback) override;
|
|
|
|
|
void OnVadStateChange(std::function<void(bool speaking)> callback) override;
|
|
|
|
|
size_t GetFeedSize() override;
|
2025-05-27 14:58:49 +08:00
|
|
|
void EnableDeviceAec(bool enable) override;
|
2025-04-29 18:17:08 +08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
EventGroupHandle_t event_group_ = nullptr;
|
|
|
|
|
esp_afe_sr_iface_t* afe_iface_ = nullptr;
|
|
|
|
|
esp_afe_sr_data_t* afe_data_ = nullptr;
|
|
|
|
|
std::function<void(std::vector<int16_t>&& data)> output_callback_;
|
|
|
|
|
std::function<void(bool speaking)> vad_state_change_callback_;
|
|
|
|
|
AudioCodec* codec_ = nullptr;
|
2025-07-20 03:57:36 +08:00
|
|
|
int frame_samples_ = 0;
|
2025-04-29 18:17:08 +08:00
|
|
|
bool is_speaking_ = false;
|
2025-07-20 03:57:36 +08:00
|
|
|
std::vector<int16_t> output_buffer_;
|
2025-04-29 18:17:08 +08:00
|
|
|
|
|
|
|
|
void AudioProcessorTask();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|