8000 [audio, microphone] - Allow MicrophoneSource to passively capture/optimization by kahrendt · Pull Request #8732 · esphome/esphome · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 9, 2025

Conversation

kahrendt
Copy link
Contributor
@kahrendt kahrendt commented May 9, 2025

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 the microphone_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

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable): not applicable

Pull request in esphome-docs with documentation (if applicable): not applicable

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# Example config.yaml

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@codecov-commenter
Copy link
codecov-commenter commented May 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.65%. Comparing base (4d8b5ed) to head (ca4e39e).
Report is 2509 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8732      +/-   ##
==========================================
+ Coverage   53.70%   56.65%   +2.94%     
==========================================
  Files          50       50              
  Lines        9408     9924     +516     
  Branches     1654     1340     -314     
==========================================
+ Hits         5053     5622     +569     
+ Misses       4056     3954     -102     
- Partials      299      348      +49     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kahrendt kahrendt marked this pull request as ready for review May 9, 2025 15:50
@kahrendt kahrendt requested a review from jesserockz as a code owner May 9, 2025 15:50
@probot-esphome
Copy link
probot-esphome bot commented May 9, 2025

Hey there @jesserockz, mind taking a look at this pull request as it has been labeled with an integration (microphone) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@kbx81 kbx81 merged commit bec9d91 into esphome:dev May 9, 2025
45 of 57 checks passed
juanboro pushed a commit to juanboro/esphome that referenced this pull request May 10, 2025
@kahrendt kahrendt deleted the mic-passive branch May 11, 2025 11:59
@jesserockz jesserockz mentioned this pull request May 13, 2025
@jesserockz jesserockz mentioned this pull request May 21, 2025
sa-crespo pushed a commit to sa-crespo/esphome that referenced this pull request May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0