Skip to content

Add Android input preset selection - #45

Merged
alnitak merged 2 commits into
alnitak:mainfrom
Avejack:feat/android-input-preset
May 13, 2026
Merged

Add Android input preset selection#45
alnitak merged 2 commits into
alnitak:mainfrom
Avejack:feat/android-input-preset

Conversation

@Avejack

@Avejack Avejack commented May 13, 2026

Copy link
Copy Markdown
Contributor

Closes #44

Summary

This adds a small Android-specific capture input preset option to Recorder.init:

await Recorder.instance.init(
  androidInputPreset: AndroidInputPreset.voiceCommunication,
);

The default remains unchanged: if androidInputPreset is omitted/null, miniaudio leaves the Android input preset unset and the plugin keeps the previous platform-default behavior.

Changes

  • Add public AndroidInputPreset enum with the common AAudio/OpenSL-backed presets:
    • generic
    • camcorder
    • voiceRecognition
    • voiceCommunication
    • unprocessed
  • Extend the Dart init path and native FFI init ABI with an Android preset integer.
  • Map the value on Android to both:
    • deviceConfig.aaudio.inputPreset
    • deviceConfig.opensl.recordingPreset
  • Keep non-Android platforms, including web, as documented no-ops.
  • Add a small Android-only selector in the example app for manual comparison.
  • Update README/API docs and add an Unreleased changelog entry.
  • Add focused tests for stable enum values and null/default mapping.

Validation

Automated checks run locally:

  • dart analyze -> no issues found
  • flutter analyze --no-pub example -> no issues found
  • flutter test --no-pub test/android_input_preset_test.dart -> all tests passed
  • cmake -S src -B /tmp/flutter_recorder_build && cmake --build /tmp/flutter_recorder_build -> native target built successfully
  • git diff --check -> clean

Manual Android testing:

  • Tested on Lenovo TB328FU.
  • Compared the current default path against voiceRecognition, voiceCommunication, camcorder, and unprocessed.
  • voiceCommunication produced the needed louder/fuller speech capture on this device, while the default remains unchanged for existing users.

Scope

This intentionally does not add a larger audio_session integration. audio_session remains useful for session/focus/route management, but Android input preset selection needs to be passed to miniaudio's capture config before device initialization.

@Avejack

Avejack commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Added a follow-up stabilization commit after device testing on Lenovo TB328FU.

The original AAudio voiceCommunication path could intermittently fail ma_device_start() even though Android moved the stream to STARTED immediately afterward. The follow-up commit routes the Android default-device voiceCommunication preset through OpenSL, which supports the same VOICE_COMMUNICATION recording preset and avoids the observed AAudio state-transition race on this OEM path.

Additional validation after the follow-up commit:

  • dart analyze -> no issues found
  • flutter analyze --no-pub example -> no issues found
  • flutter test --no-pub test/android_input_preset_test.dart -> all tests passed
  • cmake -S src -B /tmp/flutter_recorder_build && cmake --build /tmp/flutter_recorder_build -> native target built successfully
  • Manual Android repeat test on Lenovo TB328FU: voiceCommunication with repeated init -> start -> deinit now starts reliably.

@alnitak

alnitak commented May 13, 2026

Copy link
Copy Markdown
Owner

Thanks a lot @Avejack! This PR is much appreciated.

I didn't know about mic presets. I tried this and it works great. I found that on my Samsung Galaxy S22, using voiceRecognition and unprocessed, the mic volume is louder, but this depends, I think, on the brand manufacturer.

I should give this repo more consideration. If you find any other features or fixes, please feel free to make new PRs :).

LGTM, merging and releasing an update.

@alnitak
alnitak merged commit bcaf41b into alnitak:main May 13, 2026
1 check passed
@Avejack
Avejack deleted the feat/android-input-preset branch July 9, 2026 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Android input presets for capture initialization

2 participants