ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
4#include "microphone.h"
5
6#include <cstdint>
7#include <vector>
8
10
12class DataTrigger final : public Trigger<const std::vector<uint8_t> &> {
13 public:
14 explicit DataTrigger(Microphone *parent) {
15 parent->add_data_callback([this](const AudioCapture &capture) {
16 this->data_.assign(capture.data.begin(), capture.data.end());
17 this->trigger(this->data_);
18 });
19 }
20
21 protected:
22 std::vector<uint8_t> data_;
23};
24
25} // namespace esphome::microphone
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Definition automation.h:557
Reuses one vector so x stays valid in automations with a delay.
Definition automation.h:12
DataTrigger(Microphone *parent)
Definition automation.h:14
std::vector< uint8_t > data_
Definition automation.h:22
void add_data_callback(F &&data_callback)
Callbacks take (const AudioCapture &) and run on the microphone's task.
Definition microphone.h:84
std::span< const uint8_t > data
Only valid during the callback.
Definition microphone.h:25