AIToday
Audio & SpeechZenn AI/MLPublished: Oct 26, 2026, 13:00 JST

Capacitor speech plugin bug: @capacitor-community/speech-recognition 7.0.1 fails every other press

Send on LINE
Capacitor speech plugin bug: @capacitor-community/speech-recognition 7.0.1 fails every other press

3 Key Points

  1. What happened

    In an Android app built with Capacitor, the speech button failed every other press with a "Didn't understand, please try again." error in 5 ms, traced to @capacitor-community/speech-recognition 7.0.1 destroying and recreating the SpeechRecognizer each time.

  2. Why it matters

    The plugin's teardown of the recognizer caused the alternating failures, and the fix required patching the plugin itself with patch-package—meaning other apps using the same plugin version may need the same patch to avoid the intermittent failures.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, every morning.

Context & Analysis

The app in question is a self-made travel English shadowing tool that records the user's speech, converts it to text via speech recognition, and scores the match against a model sentence. On PC it used the browser's Web Speech API, but when wrapped as an Android app with Capacitor, the team chose to always use the native Android speech recognizer because Android's WebView exposes webkitSpeechRecognition as present while it does not actually function (Chromium issue 41172064). That decision set the stage for the bug, which lived in the native plugin layer.

The debugging was done by Claude Code, which first read the plugin's Android source and suspected the destroy-and-recreate pattern, but then connected a real device and measured before changing anything. Using adb to attach to the WebView's debug port, it wrapped Capacitor's native call bridge to log per-call response times, and simultaneously captured device logs with adb logcat. The logs showed that 4 ms after start, an error was already being sent, followed by the microphone opening and listening for 5 seconds before ending with "no speech detected"—and the same call received error notifications three times. The plugin's getErrorText() maps unrecognized error codes to the default "Didn't understand, please try again." message, so the exact code was not visible in the pre-fix version.

The patch makes three changes: it creates the SpeechRecognizer only if none exists and otherwise just cancels the previous session; it nulls out the call reference in onError() so the same call is not rejected twice; and it does the same single-settlement in onResults(). One caveat noted is that Android's official documentation says the caller must invoke destroy() when a SpeechRecognizer is no longer needed, and this patch simply stops calling destroy() on each press—the plugin has no other place that calls it. A practical snag during patching on Windows was a "Filename too long" error from npx patch-package, which was resolved by deleting the android/build folder before regenerating the patch.

FAQ
What exactly was causing the every-other-press failure?
The plugin was calling destroy() on the SpeechRecognizer each time start() was invoked, then creating a new one. This teardown sent an error to the new call within 5 ms while the microphone kept listening, producing alternating success and failure.
How was the fix applied?
The fix was a patch-package patch to @capacitor-community/speech-recognition 7.0.1. It reuses a single SpeechRecognizer, cancels the previous session instead of destroying it, and ensures results or errors are returned only once per call.
Did the patched version actually work on a real device?
Yes. After rebuilding the APK with the patch, 6 presses in a row all listened for 3.6–5.1 seconds before returning a result, and no press returned an error in 5 ms.
Send on LINE

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Related Articles

Next articleBlock unveils Dessa, a speech-only AI model