ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
sound_level.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32
4
9
11
12namespace esphome::sound_level {
13
14class SoundLevelComponent final : public Component {
15 SUB_SENSOR(peak)
16 SUB_SENSOR(rms)
17
18 public:
19 void dump_config() override;
20 void setup() override;
21 void loop() override;
22
23 float get_setup_priority() const override { return setup_priority::AFTER_CONNECTION; }
24
25 void set_measurement_duration(uint32_t measurement_duration_ms) {
26 this->measurement_duration_ms_ = measurement_duration_ms;
27 }
28 void set_microphone_source(microphone::MicrophoneSource *microphone_source) {
29 this->microphone_source_ = microphone_source;
30 }
31
33 void start();
34
36 void stop();
37
38 protected:
42 bool start_();
43
45 void stop_();
46
48
49 std::unique_ptr<audio::RingBufferAudioSource> audio_source_;
50 std::weak_ptr<ring_buffer::RingBuffer> ring_buffer_;
51
52 int32_t squared_peak_{0};
55
57};
58
59} // namespace esphome::sound_level
60
61#endif
virtual void dump_config()
std::weak_ptr< ring_buffer::RingBuffer > ring_buffer_
Definition sound_level.h:50
microphone::MicrophoneSource * microphone_source_
Definition sound_level.h:47
void stop_()
Internal start command that, if necessary, allocates a ring buffer and a zero-copy RingBufferAudioSou...
std::unique_ptr< audio::RingBufferAudioSource > audio_source_
Definition sound_level.h:49
constexpr float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
Definition component.h:57
static void uint32_t