Skip to content

Add microphone support via Web Speech API polyfill#44

Merged
kododake merged 1 commit intokododake:mainfrom
jigneshbhavani:feature/voice-search-polyfill
Mar 9, 2026
Merged

Add microphone support via Web Speech API polyfill#44
kododake merged 1 commit intokododake:mainfrom
jigneshbhavani:feature/voice-search-polyfill

Conversation

@jigneshbhavani
Copy link
Copy Markdown
Contributor

Problem

YouTube voice search (and any site using webkitSpeechRecognition) doesn't work in AABrowser. Android WebView does not support the Web Speech API (Chromium issue #40417848), so voice search fails silently with no way to enable it via WebView settings.

Solution

Inject a JavaScript polyfill on every page load that defines window.webkitSpeechRecognition and delegates to Android's native SpeechRecognizer via a JavascriptInterface. This is the standard approach used by other Android browsers facing the same limitation.

Changes

  • AndroidManifest.xml — Add RECORD_AUDIO and MODIFY_AUDIO_SETTINGS permissions
  • SpeechRecognitionBridge.kt — New class: exposes _SpeechBridge JS interface; contains the polyfill JS that implements webkitSpeechRecognition; bridges events (result, error, start, end, etc.) back to the page via evaluateJavascript
  • ConfiguredWebView.kt — Inject polyfill in onPageFinished; grant RESOURCE_AUDIO_CAPTURE in onPermissionRequest; route audio-capture requests through the activity for runtime permission; restore onReceivedHttpError to show error.html for 4xx/5xx errors
  • MainActivity.kt — Handle RECORD_AUDIO runtime permission flow; manage SpeechRecognitionBridge lifecycle (setup in setupUi, destroyed in onDestroy)

Testing

  1. Open YouTube in AABrowser
  2. Tap the mic icon in the search bar
  3. Grant microphone permission when prompted
  4. Speak — results should populate the search field

Google Search voice input (getUserMedia path) continues to work as before.

@jigneshbhavani
Copy link
Copy Markdown
Contributor Author

@kododake I found this repo from an Instagram reel about running YouTube and similar apps on Android Auto. I tried it out and really liked the app.
One thing I noticed was that YouTube didn’t have voice search support. Since voice input is pretty important while driving, I thought I’d try adding it myself.
So this PR is my attempt at implementing basic voice search for YouTube or other apps. I haven't tried all the apps though

@kododake kododake merged commit f606fe1 into kododake:main Mar 9, 2026
@kododake
Copy link
Copy Markdown
Owner

kododake commented Mar 9, 2026

@jigneshbhavani
Thank you so much for adding microphone support!
This is a huge improvement for an in-car browser app, as it enables voice interaction.

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.

2 participants