diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/AudioHelper.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/AudioHelper.kt index 016bb88d938..25c70db3e29 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/AudioHelper.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/AudioHelper.kt @@ -100,8 +100,8 @@ internal class AudioHelper { audioRecord.startRecording() return flow { + val buffer = ByteArray(bufferSize) while (!stopRecording) { - val buffer = ByteArray(bufferSize) val bytesRead = audioRecord.read(buffer, 0, buffer.size) if (bytesRead > 0) { emit(buffer.copyOf(bytesRead)) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveSession.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveSession.kt index d687c9bd9fd..02ddd54d0cf 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveSession.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveSession.kt @@ -276,22 +276,6 @@ internal constructor( continue } try { - val functionContent = Json.decodeFromString(receivedJson) - emit( - LiveContentResponse( - null, - LiveContentResponse.Status.NORMAL, - functionContent.toolCall.functionCalls.map { - FunctionCallPart(it.name, it.args.orEmpty().mapValues { x -> x.value ?: JsonNull }) - } - ) - ) - continue - } catch (e: Exception) { - Log.w(TAG, "Failed to decode function calling: ${e.message}") - } - try { - val serverContent = Json.decodeFromString(receivedJson) val data = serverContent.serverContent.modelTurn.toPublic() if (outputModalities.contains(ContentModality.AUDIO)) { @@ -304,8 +288,24 @@ internal constructor( emit(LiveContentResponse(data, LiveContentResponse.Status.NORMAL, null)) } } + continue + } catch (e: Exception) { + Log.i(TAG, "Failed to decode server content: ${e.message}") + } + try { + val functionContent = Json.decodeFromString(receivedJson) + emit( + LiveContentResponse( + null, + LiveContentResponse.Status.NORMAL, + functionContent.toolCall.functionCalls.map { + FunctionCallPart(it.name, it.args.orEmpty().mapValues { x -> x.value ?: JsonNull }) + } + ) + ) + continue } catch (e: Exception) { - Log.w(TAG, "Failed to decode server content: ${e.message}") + Log.w(TAG, "Failed to decode function calling: ${e.message}") } } }