From f3df12d59d24fd48c33cc6a39685fc3e39ba020e Mon Sep 17 00:00:00 2001 From: Aaron Hewitt Date: Thu, 8 Oct 2026 12:41:10 +0100 Subject: [PATCH] Don't complete speech a second time when the engine reports stopping after an interrupt --- .../utils/output/SpeechControllerImpl.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/utils/src/main/java/com/google/android/accessibility/utils/output/SpeechControllerImpl.java b/utils/src/main/java/com/google/android/accessibility/utils/output/SpeechControllerImpl.java index c4597f54..d94e5daf 100644 --- a/utils/src/main/java/com/google/android/accessibility/utils/output/SpeechControllerImpl.java +++ b/utils/src/main/java/com/google/android/accessibility/utils/output/SpeechControllerImpl.java @@ -2225,6 +2225,18 @@ private boolean isAssistantPlaying() { * @see #handleSpeechStarting() */ private void handleSpeechCompleted(int status) { + if (!mIsSpeaking) { + // Speech already completed, such as when an interrupt completes the current item and the + // engine then reports that it stopped. Audio focus was released then, and observers told, + // except that a pause that stopped the speech is only known now. + if (status == STATUS_PAUSE) { + for (SpeechController.Observer observer : observers) { + observer.onSpeechPaused(); + } + } + return; + } + for (SpeechController.Observer observer : observers) { if (status == STATUS_PAUSE) { observer.onSpeechPaused(); @@ -2242,10 +2254,6 @@ private void handleSpeechCompleted(int status) { } } - if (!mIsSpeaking) { - LogUtils.e(TAG, "Completed speech while already completed!"); - } - mIsSpeaking = false; }