1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-07 04:13:47 +01:00

[audio, microphone] - Allow MicrophoneSource to passively capture/optimization (#8732)

This commit is contained in:
Kevin Ahrendt
2025-05-09 16:54:33 -05:00
committed by GitHub
parent 8399d894c1
commit bec9d91419
4 changed files with 50 additions and 33 deletions

View File

@@ -162,13 +162,22 @@ def final_validate_microphone_source_schema(
return _validate_audio_compatability
async def microphone_source_to_code(config):
async def microphone_source_to_code(config, passive=False):
"""Creates a MicrophoneSource variable for codegen.
Setting passive to true makes the MicrophoneSource never start/stop the microphone, but only receives audio when another component has actively started the Microphone. If false, then the microphone needs to be explicitly started/stopped.
Args:
config (Schema): Created with `microphone_source_schema` specifying bits per sample, channels, and gain factor
passive (bool): Enable passive mode for the MicrophoneSource
"""
mic = await cg.get_variable(config[CONF_MICROPHONE])
mic_source = cg.new_Pvariable(
config[CONF_ID],
mic,
config[CONF_BITS_PER_SAMPLE],
config[CONF_GAIN_FACTOR],
passive,
)
for channel in config[CONF_CHANNELS]:
cg.add(mic_source.add_channel(channel))