ESPHome 2025.5.0
Loading...
Searching...
No Matches
esphome::microphone::MicrophoneSource Class Reference

#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.
 
void add_data_callback (std::function< void(const std::vector< uint8_t > &)> &&data_callback)
 
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_ (const std::vector< uint8_t > &data, std::vector< uint8_t > &filtered_data)
 

Protected Attributes

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

Detailed Description

Definition at line 18 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 38 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 48 of file microphone_source.h.

◆ add_data_callback()

void esphome::microphone::MicrophoneSource::add_data_callback ( std::function< void(const std::vector< uint8_t > &)> && data_callback)

Definition at line 9 of file microphone_source.cpp.

◆ 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 27 of file microphone_source.cpp.

◆ get_gain_factor()

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

Definition at line 53 of file microphone_source.h.

◆ is_passive()

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

Definition at line 62 of file microphone_source.h.

◆ is_running()

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

Definition at line 63 of file microphone_source.h.

◆ is_stopped()

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

Definition at line 64 of file microphone_source.h.

◆ process_audio_()

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

Definition at line 47 of file microphone_source.cpp.

◆ set_gain_factor()

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

Definition at line 52 of file microphone_source.h.

◆ start()

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

Definition at line 32 of file microphone_source.cpp.

◆ stop()

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

Definition at line 39 of file microphone_source.cpp.

Field Documentation

◆ bits_per_sample_

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

Definition at line 72 of file microphone_source.h.

◆ channels_

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

Definition at line 73 of file microphone_source.h.

◆ enabled_

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

Definition at line 75 of file microphone_source.h.

◆ gain_factor_

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

Definition at line 74 of file microphone_source.h.

◆ mic_

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

Definition at line 71 of file microphone_source.h.

◆ passive_

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

Definition at line 76 of file microphone_source.h.

◆ processed_samples_

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

Definition at line 69 of file microphone_source.h.


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