ESPHome  2024.10.2
speaker.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstddef>
4 #include <cstdint>
5 #include <vector>
6 
7 namespace esphome {
8 namespace speaker {
9 
10 enum State : uint8_t {
15 };
16 
17 class Speaker {
18  public:
19  virtual size_t play(const uint8_t *data, size_t length) = 0;
20  size_t play(const std::vector<uint8_t> &data) { return this->play(data.data(), data.size()); }
21 
22  virtual void start() = 0;
23  virtual void stop() = 0;
24  // In compare between *STOP()* and *FINISH()*; *FINISH()* will stop after emptying the play buffer,
25  // while *STOP()* will break directly.
26  // When finish() is not implemented on the plateform component it should just do a normal stop.
27  virtual void finish() { this->stop(); }
28 
29  virtual bool has_buffered_data() const = 0;
30 
31  bool is_running() const { return this->state_ == STATE_RUNNING; }
32  bool is_stopped() const { return this->state_ == STATE_STOPPED; }
33 
34  protected:
36 };
37 
38 } // namespace speaker
39 } // namespace esphome
virtual size_t play(const uint8_t *data, size_t length)=0
bool is_running() const
Definition: speaker.h:31
virtual void finish()
Definition: speaker.h:27
virtual bool has_buffered_data() const =0
bool is_stopped() const
Definition: speaker.h:32
size_t play(const std::vector< uint8_t > &data)
Definition: speaker.h:20
virtual void start()=0
uint16_t length
Definition: tt21100.cpp:12
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
virtual void stop()=0