Skip to content

Commit 8503184

Browse files
committed
feat: Send audioStreamEnd event for Google Live API when audio stops
- Add sendGoogleAudioStreamEnd() method to RealtimeSessionManager - Call it when audio capture stops in RealtimeAudioInputManager - This signals Google to flush buffered audio instead of waiting for more - Improves responsiveness when microphone is muted or robot starts speaking
1 parent adf7560 commit 8503184

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

app/src/main/java/ch/fhnw/pepper_realtime/manager/RealtimeAudioInputManager.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ class RealtimeAudioInputManager(
150150
}
151151
captureThread = null
152152

153+
// For Google Live API: Send audioStreamEnd to flush buffered audio
154+
// This signals to Google that the audio stream is paused/ended
155+
if (isGoogleProvider && sessionManager.isConnected) {
156+
sessionManager.sendGoogleAudioStreamEnd()
157+
}
158+
153159
cleanup()
154160
Log.i(TAG, "Audio capture stopped")
155161
}

app/src/main/java/ch/fhnw/pepper_realtime/network/RealtimeSessionManager.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,29 @@ class RealtimeSessionManager @Inject constructor() {
290290

291291
// ==================== GOOGLE LIVE API METHODS ====================
292292

293+
/**
294+
* Send audioStreamEnd event to Google Live API.
295+
* Should be called when audio input is paused for more than ~1 second,
296+
* e.g., when microphone is muted or when transitioning away from LISTENING state.
297+
* This signals to Google to flush any buffered audio and process it.
298+
*
299+
* @return true if sent successfully
300+
*/
301+
fun sendGoogleAudioStreamEnd(): Boolean {
302+
return try {
303+
val payload = JSONObject().apply {
304+
put("realtimeInput", JSONObject().apply {
305+
put("audioStreamEnd", true)
306+
})
307+
}
308+
Log.d(TAG, "Sending Google audioStreamEnd")
309+
send(payload.toString())
310+
} catch (e: Exception) {
311+
Log.e(TAG, "Error sending Google audioStreamEnd", e)
312+
false
313+
}
314+
}
315+
293316
/**
294317
* Send an image/video frame to Google Live API via realtimeInput.video.
295318
* This is the streaming format that adds to context WITHOUT triggering a response.

0 commit comments

Comments
 (0)