[audio, microphone] - Allow MicrophoneSource to passively capture/optimization #8732
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this implement/fix?
Adds support for a MicrophoneSource to passively capture microphone audio. In this mode, it doesn't ever start or stop the parent microphone, but instead only receives audio when a separate MicrophoneSource is actively capturing. For example, a sensor that computes the sound loudness of the microphone could be put in passive mode. It will only receive audio and compute loudness measurements if another component is simultaneously reading from the mic (e.g., mWW or VA). This avoids having to carefully manage the microphone state on devices without duplex audio support.
I chose to make this a separate argument for the
microphone_source_to_code
method instead of exposing it as a configuration option. My thought process is the component using it should be consciously setting this mode, since its behavior is quite a bit different than something like the bits per sample setting. I am not fixed on this design decision, so I can add it as part of themicrophone_source_schema
.Also this PR moves packing a Q31 sample into the
audio
component as an inline function. Using this speeds up the MicrophoneSource processing by about 15%.Types of changes
Related issue or feature (if applicable): not applicable
Pull request in esphome-docs with documentation (if applicable): not applicable
Test Environment
Example entry for
config.yaml
:# Example config.yaml
Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: