2024-10-03 06:39:22 +08:00
|
|
|
#ifndef AUDIO_PROCESSOR_H
|
|
|
|
|
#define 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>
|
|
|
|
|
|
|
|
|
|
class AudioProcessor {
|
|
|
|
|
public:
|
|
|
|
|
AudioProcessor();
|
|
|
|
|
~AudioProcessor();
|
|
|
|
|
|
2024-10-24 09:53:08 +08:00
|
|
|
void Initialize(int channels, bool reference);
|
2024-12-04 02:12:20 +08:00
|
|
|
void Input(const std::vector<int16_t>& data);
|
2024-10-03 06:39:22 +08:00
|
|
|
void Start();
|
|
|
|
|
void Stop();
|
|
|
|
|
bool IsRunning();
|
|
|
|
|
void OnOutput(std::function<void(std::vector<int16_t>&& data)> callback);
|
2025-03-22 06:09:12 +08:00
|
|
|
void OnVadStateChange(std::function<void(bool speaking)> callback);
|
2024-10-03 06:39:22 +08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
EventGroupHandle_t event_group_ = nullptr;
|
2025-03-22 06:09:12 +08:00
|
|
|
esp_afe_sr_iface_t* afe_iface_ = nullptr;
|
|
|
|
|
esp_afe_sr_data_t* afe_data_ = nullptr;
|
2024-10-03 06:39:22 +08:00
|
|
|
std::vector<int16_t> input_buffer_;
|
|
|
|
|
std::function<void(std::vector<int16_t>&& data)> output_callback_;
|
2025-03-22 06:09:12 +08:00
|
|
|
std::function<void(bool speaking)> vad_state_change_callback_;
|
2024-10-24 09:53:08 +08:00
|
|
|
int channels_;
|
|
|
|
|
bool reference_;
|
2025-03-22 06:09:12 +08:00
|
|
|
bool is_speaking_ = false;
|
2024-10-03 06:39:22 +08:00
|
|
|
|
|
|
|
|
void AudioProcessorTask();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|