Skip to content

feat(android): add input_preset to StreamConfig #995

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

TD-Sky
Copy link

@TD-Sky TD-Sky commented Jul 31, 2025

Users can enable AEC (Acoustic Echo Canceler) via setting VOICE_COMMUNICATION for recording audio on Android (refer to here), which is a powerful and important feature for developing Android applications. However, I find no ways to enable this feature in cpal at present. So I add it here.

@wgibbs-rs
Copy link
Member

Looking at the Github Actions results, it seems you left out some platform specific flags. Unfortunately, I can't edit your code, but it may be best to ensure this doesn't fail other systems.

Take a look at this:

MacOS: error[E0433]: failed to resolve: use of unresolved module or unlinked crate "ndk"

Would it be possible to go back and prevent other platforms from attempting to use this code, or fix the cross-platform issues?

@TD-Sky
Copy link
Author

TD-Sky commented Aug 1, 2025

Looking at the Github Actions results, it seems you left out some platform specific flags. Unfortunately, I can't edit your code, but it may be best to ensure this doesn't fail other systems.

Take a look at this:

MacOS: error[E0433]: failed to resolve: use of unresolved module or unlinked crate "ndk"

Would it be possible to go back and prevent other platforms from attempting to use this code, or fix the cross-platform issues?

All fixed.

Copy link
Collaborator

@roderickvd roderickvd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition. If you would take a look at the review comments and add a changelog entry?

@@ -11,6 +11,7 @@ rust-version = "1.70"

[features]
asio = ["asio-sys", "num-traits"] # Only available on Windows. See README for setup instructions.
android-input-preset = ["ndk/api-level-28"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this requires api-level-28 where the normal feature requires api-level-26. That OK?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any conflicts between the features in ndk document and didn't find any errors about api levels when I used the branch of this PR in my own project.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if it works, it works. As it does bump the minimum Android version, it would be a good thing to document. Would you document the feature flag, as well as add an entry to the changelog?

@@ -410,6 +412,8 @@ impl SupportedStreamConfig {
channels: self.channels,
sample_rate: self.sample_rate,
buffer_size: BufferSize::Default,
#[cfg(all(target_os = "android", feature = "android-input-preset"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to rename the feature flag to something more specific like "android-voice-recognition" or "android-aec"? Because it seems like there are more input presets that one could choose, if not today then in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it better to keep the name because AEC is not the only function of the flag.

Copy link
Collaborator

@roderickvd roderickvd Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I was trying to say. Looking at the AudioInputPreset enum there are six variants today. How can we make the feature flag clearly convey which preset gets enabled?

Edit: what would be a good way going forward to support the other variants as well?

@roderickvd roderickvd requested a review from Copilot August 5, 2025 21:16
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Android-specific audio input preset support to enable Acoustic Echo Canceler (AEC) functionality through the VOICE_COMMUNICATION setting. This allows developers to leverage Android's built-in audio preprocessing features for better audio quality in voice applications.

  • Adds input_preset field to StreamConfig with Android-specific feature gating
  • Integrates the preset configuration into the AAudio stream builder
  • Includes necessary feature flag and dependency configuration

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/platform/mod.rs Exports AudioInputPreset type under feature flag
src/lib.rs Adds input_preset field to StreamConfig with default value
src/host/aaudio/mod.rs Integrates input preset into stream builder and includes code cleanup
Cargo.toml Adds android-input-preset feature flag with NDK dependency
Comments suppressed due to low confidence (1)

src/host/aaudio/mod.rs:1

  • This import removal appears unrelated to the input preset feature. Consider separating cleanup changes into a separate commit to keep the feature implementation focused.
use std::cmp;

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.

3 participants