@@ -37,6 +37,7 @@ import java.util.concurrent.ConcurrentLinkedQueue
3737import  java.util.concurrent.atomic.AtomicBoolean 
3838import  kotlin.coroutines.CoroutineContext 
3939import  kotlinx.coroutines.CoroutineScope 
40+ import  kotlinx.coroutines.Dispatchers 
4041import  kotlinx.coroutines.cancel 
4142import  kotlinx.coroutines.channels.Channel.Factory.UNLIMITED 
4243import  kotlinx.coroutines.flow.Flow 
@@ -270,6 +271,7 @@ internal constructor(
270271        Json .encodeToString(
271272          BidiGenerateContentRealtimeInputSetup (mediaChunks.map { (it.toInternal()) }).toInternal()
272273        )
274+       println (" Sending $jsonString "  )
273275      session.send(Frame .Text (jsonString))
274276    }
275277  }
@@ -372,6 +374,7 @@ internal constructor(
372374            if  (it.interrupted) {
373375              playBackQueue.clear()
374376            } else  {
377+               println (" Sending audio parts"  )
375378              val  audioParts =  it.content?.parts?.filterIsInstance<InlineDataPart >().orEmpty()
376379              for  (part in  audioParts) {
377380                playBackQueue.add(part.inlineData)
@@ -387,7 +390,7 @@ internal constructor(
387390          }
388391        }
389392      }
390-       .launchIn(scope )
393+       .launchIn(CoroutineScope ( Dispatchers . IO ) )
391394  }
392395
393396  /* *
@@ -398,7 +401,7 @@ internal constructor(
398401   * Launched asynchronously on [scope]. 
399402   */  
400403  private  fun  listenForModelPlayback (enableInterruptions :  Boolean  = false) {
401-     scope .launch {
404+     CoroutineScope ( Dispatchers . IO ) .launch {
402405      while  (isActive) {
403406        val  playbackData =  playBackQueue.poll()
404407        if  (playbackData ==  null ) {
@@ -414,9 +417,10 @@ internal constructor(
414417           * no echo cancellation 
415418           */  
416419          //  TODO(b/408223520): Conditionally pause when param is added
417-           if  (enableInterruptions  !=   true ) {
420+           if  (! enableInterruptions ) {
418421            audioHelper?.pauseRecording()
419422          }
423+           println (" Playing audio"  )
420424          audioHelper?.playAudio(playbackData)
421425        }
422426      }
0 commit comments