Skip to content

Commit 1df7e48

Browse files
committed
comments
1 parent 3adf3a3 commit 1df7e48

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/LiveGenerativeModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ internal constructor(
8383
* Returns a LiveSession object using which you could send/receive messages from the server
8484
* @return LiveSession object created
8585
* @throws [BidiServerHandshakeFailed] if the handshake with the server failed.
86+
* @throws [ClosedReceiveChannelException] if the channel was closed by the server.
8687
*/
8788
public suspend fun connect(): LiveSession {
8889
val clientMessage =

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveSession.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ internal constructor(
129129

130130
/**
131131
* Receives all function call responses from the server for the audio conversation feature.
132+
* This can be called only after calling [startAudioConversation] function.
132133
*
133134
* @return A [Flow] which will emit list of [FunctionCallPart] as they are returned by the model.
134135
*/
@@ -196,10 +197,11 @@ internal constructor(
196197

197198
/**
198199
* Starts an audio conversation with the Gemini server, which can only be stopped using
199-
* stopAudioConversation.
200+
* [stopAudioConversation].
200201
*/
201202
public suspend fun startAudioConversation() {
202203
if (isRecording) {
204+
Log.w(TAG, "startAudioConversation called after the recording has already started.")
203205
return
204206
}
205207
functionCallChannel = Channel()
@@ -210,10 +212,13 @@ internal constructor(
210212
CoroutineScope(backgroundDispatcher).launch { sendAudioDataToServer() }
211213
fillServerResponseAudioQueue()
212214
playServerResponseAudio()
215+
// This delay is necessary to ensure that all threads have started.
213216
delay(1000)
214217
}
215218

216-
/** Stops the audio conversation with the Gemini Server. */
219+
/** Stops the audio conversation with the Gemini Server. This needs to be called only after
220+
* calling [startAudioConversation]
221+
* */
217222
public fun stopAudioConversation() {
218223
stopReceiving()
219224
isRecording = false
@@ -239,7 +244,8 @@ internal constructor(
239244
}
240245

241246
/**
242-
* Receives responses from the server for both streaming and standard requests.
247+
* Receives responses from the server for both streaming and standard requests. Call
248+
* [stopReceiving] to stop receiving responses from the server.
243249
*
244250
* @param outputModalities The list of output formats to receive from the server.
245251
*
@@ -281,7 +287,7 @@ internal constructor(
281287
)
282288
continue
283289
} catch (e: Exception) {
284-
Log.i(TAG, "Failed to decode function calling: ${e.message}")
290+
Log.w(TAG, "Failed to decode function calling: ${e.message}")
285291
}
286292
try {
287293

@@ -298,7 +304,7 @@ internal constructor(
298304
}
299305
}
300306
} catch (e: Exception) {
301-
Log.i(TAG, "Failed to decode server content: ${e.message}")
307+
Log.w(TAG, "Failed to decode server content: ${e.message}")
302308
}
303309
}
304310
}
@@ -319,7 +325,8 @@ internal constructor(
319325
}
320326

321327
/**
322-
* Streams client data to the server.
328+
* Streams client data to the server. Calling this after [startAudioConversation] will play the
329+
* response audio immediately.
323330
*
324331
* @param mediaChunks The list of [MediaData] instances representing the media data to be sent.
325332
*/
@@ -332,7 +339,8 @@ internal constructor(
332339
}
333340

334341
/**
335-
* Sends data to the server
342+
* Sends data to the server. Calling this after [startAudioConversation] will play the response
343+
* audio immediately.
336344
*
337345
* @param content Client [Content] to be sent to the server.
338346
*/
@@ -343,7 +351,8 @@ internal constructor(
343351
}
344352

345353
/**
346-
* Sends text to the server
354+
* Sends text to the server. Calling this after [startAudioConversation] will play the response
355+
* audio immediately.
347356
*
348357
* @param text Text to be sent to the server.
349358
*/

0 commit comments

Comments
 (0)