ESPHome  2024.11.3
Public Member Functions | Protected Attributes
esphome::speaker::Speaker Class Referenceabstract

#include <speaker.h>

Inheritance diagram for esphome::speaker::Speaker:
esphome::i2s_audio::I2SAudioSpeaker

Public Member Functions

virtual size_t play (const uint8_t *data, size_t length, TickType_t ticks_to_wait)
 Plays the provided audio data. More...
 
virtual size_t play (const uint8_t *data, size_t length)=0
 Plays the provided audio data. More...
 
size_t play (const std::vector< uint8_t > &data)
 
virtual void start ()=0
 
virtual void stop ()=0
 
virtual void finish ()
 
virtual bool has_buffered_data () const =0
 
bool is_running () const
 
bool is_stopped () const
 
virtual void set_volume (float volume)
 
float get_volume ()
 
virtual void set_mute_state (bool mute_state)
 
bool get_mute_state ()
 
void set_audio_dac (audio_dac::AudioDac *audio_dac)
 
void set_audio_stream_info (const audio::AudioStreamInfo &audio_stream_info)
 

Protected Attributes

State state_ {STATE_STOPPED}
 
audio::AudioStreamInfo audio_stream_info_
 
float volume_ {1.0f}
 
bool mute_state_ {false}
 
audio_dac::AudioDacaudio_dac_ {nullptr}
 

Detailed Description

Definition at line 28 of file speaker.h.

Member Function Documentation

◆ finish()

virtual void esphome::speaker::Speaker::finish ( )
inlinevirtual

Reimplemented in esphome::i2s_audio::I2SAudioSpeaker.

Definition at line 57 of file speaker.h.

◆ get_mute_state()

bool esphome::speaker::Speaker::get_mute_state ( )
inline

Definition at line 88 of file speaker.h.

◆ get_volume()

float esphome::speaker::Speaker::get_volume ( )
inline

Definition at line 74 of file speaker.h.

◆ has_buffered_data()

virtual bool esphome::speaker::Speaker::has_buffered_data ( ) const
pure virtual

◆ is_running()

bool esphome::speaker::Speaker::is_running ( ) const
inline

Definition at line 61 of file speaker.h.

◆ is_stopped()

bool esphome::speaker::Speaker::is_stopped ( ) const
inline

Definition at line 62 of file speaker.h.

◆ play() [1/3]

virtual size_t esphome::speaker::Speaker::play ( const uint8_t *  data,
size_t  length,
TickType_t  ticks_to_wait 
)
inlinevirtual

Plays the provided audio data.

If the speaker component doesn't implement this method, it falls back to the play method without this parameter.

Parameters
dataAudio data in the format specified by set_audio_stream_info method.
lengthThe length of the audio data in bytes.
ticks_to_waitThe FreeRTOS ticks to wait before writing as much data as possible to the ring buffer.
Returns
The number of bytes that were actually written to the speaker's internal buffer.

Reimplemented in esphome::i2s_audio::I2SAudioSpeaker.

Definition at line 37 of file speaker.h.

◆ play() [2/3]

virtual size_t esphome::speaker::Speaker::play ( const uint8_t *  data,
size_t  length 
)
pure virtual

Plays the provided audio data.

If the audio stream is not the default defined in "esphome/core/audio.h" and the speaker component implements it, then this should be called after calling set_audio_stream_info.

Parameters
dataAudio data in the format specified by set_audio_stream_info method.
lengthThe length of the audio data in bytes.
Returns
The number of bytes that were actually written to the speaker's internal buffer.

Implemented in esphome::i2s_audio::I2SAudioSpeaker.

◆ play() [3/3]

size_t esphome::speaker::Speaker::play ( const std::vector< uint8_t > &  data)
inline

Definition at line 50 of file speaker.h.

◆ set_audio_dac()

void esphome::speaker::Speaker::set_audio_dac ( audio_dac::AudioDac audio_dac)
inline

Definition at line 91 of file speaker.h.

◆ set_audio_stream_info()

void esphome::speaker::Speaker::set_audio_stream_info ( const audio::AudioStreamInfo audio_stream_info)
inline

Definition at line 94 of file speaker.h.

◆ set_mute_state()

virtual void esphome::speaker::Speaker::set_mute_state ( bool  mute_state)
inlinevirtual

Reimplemented in esphome::i2s_audio::I2SAudioSpeaker.

Definition at line 76 of file speaker.h.

◆ set_volume()

virtual void esphome::speaker::Speaker::set_volume ( float  volume)
inlinevirtual

Reimplemented in esphome::i2s_audio::I2SAudioSpeaker.

Definition at line 66 of file speaker.h.

◆ start()

virtual void esphome::speaker::Speaker::start ( )
pure virtual

◆ stop()

virtual void esphome::speaker::Speaker::stop ( )
pure virtual

Field Documentation

◆ audio_dac_

audio_dac::AudioDac* esphome::speaker::Speaker::audio_dac_ {nullptr}
protected

Definition at line 105 of file speaker.h.

◆ audio_stream_info_

audio::AudioStreamInfo esphome::speaker::Speaker::audio_stream_info_
protected

Definition at line 100 of file speaker.h.

◆ mute_state_

bool esphome::speaker::Speaker::mute_state_ {false}
protected

Definition at line 102 of file speaker.h.

◆ state_

State esphome::speaker::Speaker::state_ {STATE_STOPPED}
protected

Definition at line 99 of file speaker.h.

◆ volume_

float esphome::speaker::Speaker::volume_ {1.0f}
protected

Definition at line 101 of file speaker.h.


The documentation for this class was generated from the following file: