From d9860ebfe0102769b054accd9a0a08d24dc49488 Mon Sep 17 00:00:00 2001 From: Aaron Hewitt Date: Thu, 15 Oct 2026 07:37:01 +0100 Subject: [PATCH] Speak the usual way during calls rather than through low-latency audio --- .../utils/output/FailoverTextToSpeech.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/utils/src/main/java/com/google/android/accessibility/utils/output/FailoverTextToSpeech.java b/utils/src/main/java/com/google/android/accessibility/utils/output/FailoverTextToSpeech.java index 703f4b52..a19c4f22 100644 --- a/utils/src/main/java/com/google/android/accessibility/utils/output/FailoverTextToSpeech.java +++ b/utils/src/main/java/com/google/android/accessibility/utils/output/FailoverTextToSpeech.java @@ -1366,11 +1366,11 @@ private int speakInChunks( */ private int ttsSpeak( CharSequence text, int queueMode, Bundle bundle, @Nullable String utteranceId) { - watchForEngineHang(queueMode, utteranceId); @Nullable LowLatencyAudio player = lowLatencyPlayer(); if (player == null || utteranceId == null || TextUtils.isEmpty(text)) { return tts.speak(text, queueMode, bundle, utteranceId); } + watchForEngineHang(queueMode, utteranceId); if (queueMode != QUEUE_ADD) { // The engine flushes its own queue for this queue mode. Every player, since the player for // speech changes with the speech volume setting. @@ -1399,10 +1399,21 @@ private int ttsSpeak( return result; } + /** Whether a phone or voice call has the audio mode. */ + private boolean inCall() { + AudioManager audioManager = context.getSystemService(AudioManager.class); + if (audioManager == null) { + return false; + } + int mode = audioManager.getMode(); + return mode == AudioManager.MODE_IN_CALL || mode == AudioManager.MODE_IN_COMMUNICATION; + } + /** The player for speech, or null if speech should play the usual way. */ private @Nullable LowLatencyAudio lowLatencyPlayer() { if (!lowLatencyAudio || LowLatencyAudio.isMicrophoneInUse() + || inCall() || android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.R || (ttsEngine != null && enginesWithoutFileAudio.contains(ttsEngine))) { return null;