audio_processor.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef AUDIO_PROCESSOR_H
  2. #define AUDIO_PROCESSOR_H
  3. #include <esp_afe_sr_models.h>
  4. #include <freertos/FreeRTOS.h>
  5. #include <freertos/task.h>
  6. #include <freertos/event_groups.h>
  7. #include <string>
  8. #include <vector>
  9. #include <functional>
  10. class AudioProcessor {
  11. public:
  12. AudioProcessor();
  13. ~AudioProcessor();
  14. void Initialize(int channels, bool reference);
  15. void Input(const std::vector<int16_t>& data);
  16. void Start();
  17. void Stop();
  18. bool IsRunning();
  19. void OnOutput(std::function<void(std::vector<int16_t>&& data)> callback);
  20. void OnVadStateChange(std::function<void(bool speaking)> callback);
  21. private:
  22. EventGroupHandle_t event_group_ = nullptr;
  23. esp_afe_sr_iface_t* afe_iface_ = nullptr;
  24. esp_afe_sr_data_t* afe_data_ = nullptr;
  25. std::vector<int16_t> input_buffer_;
  26. std::function<void(std::vector<int16_t>&& data)> output_callback_;
  27. std::function<void(bool speaking)> vad_state_change_callback_;
  28. int channels_;
  29. bool reference_;
  30. bool is_speaking_ = false;
  31. void AudioProcessorTask();
  32. };
  33. #endif