ESPHome  2024.11.3
microphone.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstddef>
4 #include <cstdint>
5 #include <functional>
6 #include <vector>
7 #include "esphome/core/helpers.h"
8 
9 namespace esphome {
10 namespace microphone {
11 
12 enum State : uint8_t {
17 };
18 
19 class Microphone {
20  public:
21  virtual void start() = 0;
22  virtual void stop() = 0;
23  void add_data_callback(std::function<void(const std::vector<int16_t> &)> &&data_callback) {
24  this->data_callbacks_.add(std::move(data_callback));
25  }
26  virtual size_t read(int16_t *buf, size_t len) = 0;
27 
28  bool is_running() const { return this->state_ == STATE_RUNNING; }
29  bool is_stopped() const { return this->state_ == STATE_STOPPED; }
30 
31  protected:
33 
35 };
36 
37 } // namespace microphone
38 } // namespace esphome
void add_data_callback(std::function< void(const std::vector< int16_t > &)> &&data_callback)
Definition: microphone.h:23
CallbackManager< void(const std::vector< int16_t > &)> data_callbacks_
Definition: microphone.h:34
virtual size_t read(int16_t *buf, size_t len)=0
std::string size_t len
Definition: helpers.h:293
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7