ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
esphome::microphone::MicrophoneSource Class Referencefinal

#include <microphone_source.h>

Public Member Functions

 MicrophoneSource (Microphone *mic, uint8_t bits_per_sample, int32_t gain_factor, bool passive)
 
void add_channel (uint8_t channel)
 Enables a channel to be processed through the callback.
 
template<typename F >
void add_data_callback (F &&data_callback)
 Same callbacks as Microphone::add_data_callback; stream_info is the processed format.
 
void set_gain_factor (int32_t gain_factor)
 
int32_t get_gain_factor ()
 
audio::AudioStreamInfo get_audio_stream_info ()
 Gets the AudioStreamInfo of the data after processing.
 
void start ()
 
void stop ()
 
bool is_passive () const
 
bool is_running () const
 
bool is_stopped () const
 

Protected Member Functions

void process_audio_ (std::span< const uint8_t > data, const audio::AudioStreamInfo &source_info, std::vector< uint8_t > &filtered_data)
 

Protected Attributes

std::shared_ptr< std::vector< uint8_t > > processed_samples_
 
Microphone * mic_
 
std::bitset< 8 > channels_
 
int32_t gain_factor_
 
bool enabled_ {false}
 
bool passive_
 
uint8_t bits_per_sample_
 

Detailed Description

Definition at line 17 of file microphone_source.h.

Constructor & Destructor Documentation

◆ MicrophoneSource()

esphome::microphone::MicrophoneSource::MicrophoneSource ( Microphone * mic,
uint8_t bits_per_sample,
int32_t gain_factor,
bool passive )
inline

Definition at line 37 of file microphone_source.h.

Member Function Documentation

◆ add_channel()

void esphome::microphone::MicrophoneSource::add_channel ( uint8_t channel)
inline

Enables a channel to be processed through the callback.

If the microphone component only has reads from one channel, it is always in channel number 0, regardless if it represents left or right. If the microphone reads from both left and right, channel number 0 and 1 represent the left and right channels respectively.

Parameters
channel0-indexed channel number to enable

Definition at line 47 of file microphone_source.h.

◆ add_data_callback()

template<typename F >
void esphome::microphone::MicrophoneSource::add_data_callback ( F && data_callback)
inline

Same callbacks as Microphone::add_data_callback; stream_info is the processed format.

Definition at line 50 of file microphone_source.h.

◆ get_audio_stream_info()

audio::AudioStreamInfo esphome::microphone::MicrophoneSource::get_audio_stream_info ( )

Gets the AudioStreamInfo of the data after processing.

Returns
audio::AudioStreamInfo with the configured bits per sample, configured channel count, and source microphone's sample rate

Definition at line 19 of file microphone_source.cpp.

◆ get_gain_factor()

int32_t esphome::microphone::MicrophoneSource::get_gain_factor ( )
inline

Definition at line 71 of file microphone_source.h.

◆ is_passive()

bool esphome::microphone::MicrophoneSource::is_passive ( ) const
inline

Definition at line 80 of file microphone_source.h.

◆ is_running()

bool esphome::microphone::MicrophoneSource::is_running ( ) const
inline

Definition at line 81 of file microphone_source.h.

◆ is_stopped()

bool esphome::microphone::MicrophoneSource::is_stopped ( ) const
inline

Definition at line 82 of file microphone_source.h.

◆ process_audio_()

void esphome::microphone::MicrophoneSource::process_audio_ ( std::span< const uint8_t > data,
const audio::AudioStreamInfo & source_info,
std::vector< uint8_t > & filtered_data )
protected

Definition at line 39 of file microphone_source.cpp.

◆ set_gain_factor()

void esphome::microphone::MicrophoneSource::set_gain_factor ( int32_t gain_factor)
inline

Definition at line 70 of file microphone_source.h.

◆ start()

void esphome::microphone::MicrophoneSource::start ( )

Definition at line 24 of file microphone_source.cpp.

◆ stop()

void esphome::microphone::MicrophoneSource::stop ( )

Definition at line 31 of file microphone_source.cpp.

Field Documentation

◆ bits_per_sample_

uint8_t esphome::microphone::MicrophoneSource::bits_per_sample_
protected

Definition at line 95 of file microphone_source.h.

◆ channels_

std::bitset<8> esphome::microphone::MicrophoneSource::channels_
protected

Definition at line 91 of file microphone_source.h.

◆ enabled_

bool esphome::microphone::MicrophoneSource::enabled_ {false}
protected

Definition at line 93 of file microphone_source.h.

◆ gain_factor_

int32_t esphome::microphone::MicrophoneSource::gain_factor_
protected

Definition at line 92 of file microphone_source.h.

◆ mic_

Microphone* esphome::microphone::MicrophoneSource::mic_
protected

Definition at line 90 of file microphone_source.h.

◆ passive_

bool esphome::microphone::MicrophoneSource::passive_
protected

Definition at line 94 of file microphone_source.h.

◆ processed_samples_

std::shared_ptr<std::vector<uint8_t> > esphome::microphone::MicrophoneSource::processed_samples_
protected

Definition at line 88 of file microphone_source.h.


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