@@ -95,7 +95,8 @@ internal constructor(
95
95
*/
96
96
@RequiresPermission(RECORD_AUDIO )
97
97
public suspend fun startAudioConversation (
98
- functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )? = null
98
+ functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )? = null,
99
+ enableInterruptions : Boolean? = null,
99
100
) {
100
101
101
102
val context = firebaseApp.applicationContext
@@ -120,7 +121,7 @@ internal constructor(
120
121
121
122
recordUserAudio()
122
123
processModelResponses(functionCallHandler)
123
- listenForModelPlayback()
124
+ listenForModelPlayback(enableInterruptions )
124
125
}
125
126
}
126
127
@@ -375,22 +376,26 @@ internal constructor(
375
376
*
376
377
* Launched asynchronously on [scope].
377
378
*/
378
- private fun listenForModelPlayback () {
379
+ private fun listenForModelPlayback (enableInterruptions : Boolean? = null ) {
379
380
scope.launch {
380
381
while (isActive) {
381
382
val playbackData = playBackQueue.poll()
382
383
if (playbackData == null ) {
383
384
// The model playback queue is complete, so we can continue recording
384
385
// TODO(b/408223520): Conditionally resume when param is added
385
- audioHelper?.resumeRecording()
386
+ if (enableInterruptions != true ) {
387
+ audioHelper?.resumeRecording()
388
+ }
386
389
yield ()
387
390
} else {
388
391
/* *
389
392
* We pause the recording while the model is speaking to avoid interrupting it because of
390
393
* no echo cancellation
391
394
*/
392
395
// TODO(b/408223520): Conditionally pause when param is added
393
- audioHelper?.pauseRecording()
396
+ if (enableInterruptions != true ) {
397
+ audioHelper?.pauseRecording()
398
+ }
394
399
395
400
audioHelper?.playAudio(playbackData)
396
401
}
0 commit comments