Repository navigation
fix(SpeechRecognizer): keep Android recognizer reusable after stop - #26693
morning4coffe-dev wants to merge 1 commit into
Conversation
StopRecognitionAsync destroyed the native recognizer, so the instance could not recognize again. Stop listening only, and destroy on Dispose.
|
Claude finished @morning4coffe-dev's task in 26s —— View job Review summaryVerdict: ship (with two minor, non-blocking suggestions).
Validation evidence
Cross-cutting notes
|
|
Tick the box to add this pull request to the merge queue (same as
|
| // StopListening ends audio capture and still delivers the final results. Destroy is | ||
| // reserved for Dispose: calling it here left the instance unable to recognize again. |
There was a problem hiding this comment.
Nit (code-style): the second line narrates change history ("calling it here left the instance unable to recognize again"). Per .claude/rules/code-style.md, comments should state the present reason only; git carries the history. Suggest a single line:
| // StopListening ends audio capture and still delivers the final results. Destroy is | |
| // reserved for Dispose: calling it here left the instance unable to recognize again. | |
| // StopListening ends capture but still delivers final results; Destroy is reserved for Dispose. |
| { | ||
| _speechRecognizer?.Destroy(); | ||
| _speechRecognizer?.Dispose(); | ||
| _speechRecognizer = null; |
There was a problem hiding this comment.
Since Dispose() now nulls _speechRecognizer, RecognizeTaskAsync (lines 57-58) dereferences it without a null check. Calling RecognizeAsync() after Dispose() will now throw a NullReferenceException instead of an ObjectDisposedException-style failure. Consider an ObjectDisposedException.ThrowIf(_speechRecognizer is null, this) at the start of RecognizeTaskAsync. This is defensive hardening only; the root-cause lifecycle fix (Destroy only in Dispose) is correct.
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
GitHub Issue: closes #26692
PR Type:
🐞 Bugfix
What changed? 🚀
On Android,
SpeechRecognizer.StopRecognitionAsync()calledDestroy()on the nativeAndroid.Speech.SpeechRecognizer, so the instance could not recognize again.Dispose()never destroyed it.StopRecognitionAsync()now only callsStopListening(). That ends audio capture and still delivers the final results through the listener.Dispose()callsDestroy()before disposing the native recognizer, and clears the field.Validation: compile only (
Uno.WinRT.netcoremobilefornet10.0-android). Not run on a device or emulator.PR Checklist ✅
SpeechRecognizerTestssample covers stop and restart manually.Screenshots Compare Test Runresults.