Skip to content

Commit c10542c

Browse files
fix(android): restore Talk replies and honor stt-tts voices (#150175)
Stop restarting native speech recognition at end of speech, which could cancel the pending transcript before chat.send. Leave restart handling with the existing result and error callbacks. Honor talk.realtime.mode=stt-tts by selecting the existing native recognition, Gateway chat, and talk.speak pipeline, using the configured Talk speech provider and voice while preserving realtime defaults. Add regression coverage for premature recognition restarts and explicit stt-tts selection. Fixes #150105 Fixes #150104 Co-authored-by: IWhatsskill <[email protected]>
1 parent afc27e7 commit c10542c

4 files changed

Lines changed: 58 additions & 11 deletions

File tree

‎apps/android/app/src/main/java/ai/openclaw/app/voice/TalkModeGatewayConfig.kt‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ internal object TalkModeGatewayConfigParser {
5050
speechLocale = normalizeSpeechLocaleTag(talk?.get("speechLocale").asStringOrNull()),
5151
interruptOnSpeech = talk?.get("interruptOnSpeech").asBooleanOrNull(),
5252
silenceTimeoutMs = resolvedSilenceTimeoutMs(talk),
53+
// gateway-relay carries only realtime sessions; stt-tts runs as native Talk
54+
// (device STT, chat.send, talk.speak) so the configured Talk voice is used.
5355
realtimeRelayModelSupported =
54-
realtimeClientHints?.get("gatewayRelaySupported").asBooleanOrNull()
55-
?: isAndroidRealtimeRelayModelSupported(realtimeModel),
56+
realtime?.get("mode").asStringOrNull() != "stt-tts" &&
57+
(
58+
realtimeClientHints?.get("gatewayRelaySupported").asBooleanOrNull()
59+
?: isAndroidRealtimeRelayModelSupported(realtimeModel)
60+
),
5661
)
5762
}
5863

‎apps/android/app/src/main/java/ai/openclaw/app/voice/TalkModeManager.kt‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,15 +3246,10 @@ class TalkModeManager internal constructor(
32463246

32473247
override fun onBufferReceived(buffer: ByteArray?) {}
32483248

3249-
override fun onEndOfSpeech() =
3250-
withCurrentRecognition(owner, captureId) {
3251-
if (activePttCaptureId != null) return@withCurrentRecognition
3252-
// Don't restart while a transcript is being processed — the recognizer
3253-
// competing for audio resources kills AudioTrack PCM playback.
3254-
if (listeningMode) {
3255-
scheduleRestart()
3256-
}
3257-
}
3249+
// onResults/onError always follow end of speech and own the restart. Restarting here
3250+
// cancels the session before its final hypothesis, and the cancel's ERROR_CLIENT clears
3251+
// listening, so checkSilence never sends the transcript.
3252+
override fun onEndOfSpeech() {}
32583253

32593254
override fun onError(error: Int) =
32603255
withCurrentRecognition(owner, captureId) {

‎apps/android/app/src/test/java/ai/openclaw/app/voice/TalkModeConfigParsingTest.kt‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ class TalkModeConfigParsingTest {
119119
assertTrue(TalkModeGatewayConfigParser.parse(relayCapable).realtimeRelayModelSupported)
120120
}
121121

122+
@Test
123+
fun routesSttTtsModeToNativeTalkEvenWhenRelayIsSupported() {
124+
val sttTts =
125+
json
126+
.parseToJsonElement(
127+
"""{"talk":{"realtime":{"mode":"stt-tts","model":"gpt-realtime-2.1"}},"clientHints":{"realtime":{"gatewayRelaySupported":true}}}""",
128+
).jsonObject
129+
val explicitRealtime =
130+
json
131+
.parseToJsonElement(
132+
"""{"talk":{"realtime":{"mode":"realtime"}},"clientHints":{"realtime":{"gatewayRelaySupported":true}}}""",
133+
).jsonObject
134+
135+
// gateway-relay carries only realtime sessions, so stt-tts must use device STT plus talk.speak.
136+
assertFalse(TalkModeGatewayConfigParser.parse(sttTts).realtimeRelayModelSupported)
137+
assertTrue(TalkModeGatewayConfigParser.parse(explicitRealtime).realtimeRelayModelSupported)
138+
}
139+
122140
@Test
123141
fun gatesAndroidRealtimeRelayFromProviderLevelModel() {
124142
val providerLevelBrowserOnly =

‎apps/android/app/src/test/java/ai/openclaw/app/voice/TalkModeManagerTest.kt‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,35 @@ class TalkModeManagerTest {
10491049
}
10501050
}
10511051

1052+
@Test
1053+
fun nativeTalkKeepsRecognitionOpenFromEndOfSpeechUntilResults() =
1054+
runBlocking {
1055+
withNativeTalk { proof, sends ->
1056+
val recognizer = currentRecognizer()
1057+
val session = recognizer.lastRecognizerIntent
1058+
recognizer.triggerOnReadyForSpeech(Bundle())
1059+
// Google's recognizer delivers the final hypothesis as a partial at end of speech and
1060+
// reports onResults only when the session closes, after the Talk silence window.
1061+
recognizer.triggerOnPartialResults(recognitionResults("Synthetic end-of-speech phrase"))
1062+
recognizer.triggerOnEndOfSpeech()
1063+
advanceTalkSilence(proof)
1064+
awaitTalkWork(proof) { sends.isNotEmpty() }
1065+
1066+
assertSame(
1067+
"End of speech must not cancel and restart the session before its results arrive",
1068+
session,
1069+
recognizer.lastRecognizerIntent,
1070+
)
1071+
assertTrue(
1072+
sends
1073+
.single()
1074+
.getValue("message")
1075+
.jsonPrimitive.content
1076+
.endsWith("Synthetic end-of-speech phrase"),
1077+
)
1078+
}
1079+
}
1080+
10521081
@Test
10531082
fun nativeStopThenStartKeepsReplacementAndRejectsRetiredResults() =
10541083
runBlocking {

0 commit comments

Comments
 (0)